Skip to content

Commit

Permalink
Fix flaky test by sorting slices
Browse files Browse the repository at this point in the history
TestGetVarSubstitutionExpressionsForPipelineResult was flaky since the expected
test output was in a fixed order while the function under test was iterating
through a map where order is not guaranteed. This commit fixes it by sorting
the inputs to cmp.Diff

Signed-off-by: Dibyo Mukherjee <[email protected]>
  • Loading branch information
dibyom authored and tekton-robot committed Jul 20, 2022
1 parent 94055d9 commit a4f9216
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/apis/pipeline/v1beta1/resultref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,10 +754,13 @@ func TestGetVarSubstitutionExpressionsForPipelineResult(t *testing.T) {
want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2", "tasks.task3.results.result3"},
},
}
var sortStrings = func(x, y string) bool {
return x < y
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
get, _ := v1beta1.GetVarSubstitutionExpressionsForPipelineResult(tt.result)
if d := cmp.Diff(tt.want, get); d != "" {
if d := cmp.Diff(tt.want, get, cmpopts.SortSlices(sortStrings)); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down

0 comments on commit a4f9216

Please sign in to comment.