Skip to content

Commit

Permalink
fix(testing): sort label names to prevent random test failure (#1699)
Browse files Browse the repository at this point in the history
* fix(testing): sort label names to prevent random test failure

* actually use the correct comparison function :(
  • Loading branch information
imogenkinsman authored Dec 4, 2018
1 parent efc21bf commit c695563
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions testing/label_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ var labelCmpOptions = cmp.Options{
cmp.Transformer("Sort", func(in []*platform.Label) []*platform.Label {
out := append([]*platform.Label(nil), in...) // Copy input to avoid mutating it
sort.Slice(out, func(i, j int) bool {
return out[i].ResourceID.String() > out[j].ResourceID.String()
if out[i].Name != out[j].Name {
return out[i].Name < out[j].Name
}
return out[i].ResourceID.String() < out[j].ResourceID.String()
})
return out
}),
Expand Down Expand Up @@ -158,7 +161,7 @@ func CreateLabel(
if err != nil {
t.Fatalf("failed to retrieve labels: %v", err)
}
if diff := cmp.Diff(labels, tt.wants.labels, mappingCmpOptions...); diff != "" {
if diff := cmp.Diff(labels, tt.wants.labels, labelCmpOptions...); diff != "" {
t.Errorf("labels are different -got/+want\ndiff %s", diff)
}
})
Expand Down

0 comments on commit c695563

Please sign in to comment.