fix(testing): sort label names to prevent random test failure (#1699)

* fix(testing): sort label names to prevent random test failure

* actually use the correct comparison function :(
pull/10616/head
Jade McGough 2018-12-04 13:22:11 -08:00 committed by GitHub
parent efc21bfddf
commit c6955634fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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
}),
@ -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)
}
})