From 2409124a2d48753e8030597f8ae85b6dbb275838 Mon Sep 17 00:00:00 2001 From: Spencer Schrock Date: Thu, 12 Dec 2024 11:59:58 -0700 Subject: [PATCH] Fix sorting contributors before comparing in test (#4455) 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 --- clients/azuredevopsrepo/contributors_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clients/azuredevopsrepo/contributors_test.go b/clients/azuredevopsrepo/contributors_test.go index 1f71c504648..2fc1f65e72f 100644 --- a/clients/azuredevopsrepo/contributors_test.go +++ b/clients/azuredevopsrepo/contributors_test.go @@ -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) } })