Skip to content

Commit

Permalink
Fix sorting contributors before comparing in test (#4455)
Browse files Browse the repository at this point in the history
The intention was always to sort, but the wrong sort function was used.
This led to an unsorted list, which was dependent on map iteration
order, leading to flaky unit tests. This was reproducible with go test
when passing a large --count option.

Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock authored Dec 12, 2024
1 parent 52b3bad commit 2409124
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clients/azuredevopsrepo/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func Test_listContributors(t *testing.T) {
t.Errorf("contributorsHandler.setup() error = %v, wantErr %v", err, tt.wantErr)
return
}
if diff := cmp.Diff(tt.wantContribs, c.contributors, cmpopts.SortSlices(func(a, b string) bool { return a < b })); diff != "" {
sortUsers := func(a, b clients.User) bool { return a.Login < b.Login }
if diff := cmp.Diff(tt.wantContribs, c.contributors, cmpopts.SortSlices(sortUsers)); diff != "" {
t.Errorf("contributorsHandler.setup() mismatch (-want +got):\n%s", diff)
}
})
Expand Down

0 comments on commit 2409124

Please sign in to comment.