Skip to content

Commit 1d5b9c1

Browse files
committed
fix: make tests order-insensitive
1 parent f983112 commit 1d5b9c1

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module chromium-policy-vulnfeed
33
go 1.21
44

55
require (
6-
github.com/google/go-github/v66 v66.0.0 // indirect
7-
github.com/google/go-querystring v1.1.0 // indirect
6+
github.com/google/go-cmp v0.6.0
7+
github.com/google/go-github/v66 v66.0.0
88
)
9+
10+
require github.com/google/go-querystring v1.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
3+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
24
github.com/google/go-github/v66 v66.0.0 h1:ADJsaXj9UotwdgK8/iFZtv7MLc8E8WBl62WLd/D/9+M=
35
github.com/google/go-github/v66 v66.0.0/go.mod h1:+4SO9Zkuyf8ytMj0csN1NR/5OTR+MfqPp8P8dVlcvY4=
46
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=

src/main_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"testing"
2222
"time"
2323

24+
"github.com/google/go-cmp/cmp"
25+
"github.com/google/go-cmp/cmp/cmpopts"
2426
"github.com/google/go-github/v66/github"
2527
)
2628

@@ -110,8 +112,8 @@ func TestUpdateCache(t *testing.T) {
110112
if err != nil {
111113
t.Fatalf("updateCache failed: %v", err)
112114
}
113-
if !reflect.DeepEqual(got, tt.want) {
114-
t.Errorf("unexpected AffectedItem: got %v, want %v", got, tt.want)
115+
if diff := cmp.Diff(got, tt.want, cmpopts.SortSlices(func(a, b string) bool { return a < b })); diff != "" {
116+
t.Errorf("unexpected AffectedItem: diff (-want +got):\n%s", diff)
115117
}
116118
})
117119
}
@@ -223,8 +225,8 @@ func TestGetCacheEntry(t *testing.T) {
223225
t.Errorf("getCacheEntry() error = %v", err)
224226
return
225227
}
226-
if !reflect.DeepEqual(got, tt.want) {
227-
t.Errorf("getCacheEntry() = %v, want %v", got, tt.want)
228+
if diff := cmp.Diff(got, tt.want, cmpopts.SortSlices(func(a, b string) bool { return a < b })); diff != "" {
229+
t.Errorf("getCacheEntry() diff (-want +got):\n%s", diff)
228230
}
229231
})
230232
}
@@ -365,8 +367,8 @@ func TestSaveCache(t *testing.T) {
365367
"hash2"
366368
]
367369
}`)
368-
if !reflect.DeepEqual(savedCacheData, expectedCacheData) {
369-
t.Errorf("unexpected cache data: got %v, want %v", savedCacheData, expectedCacheData)
370+
if diff := cmp.Diff(savedCacheData, expectedCacheData, cmpopts.SortSlices(func(a, b string) bool { return a < b })); diff != "" {
371+
t.Errorf("unexpected AffectedItem: diff (-want +got):\n%s", diff)
370372
}
371373
}
372374

0 commit comments

Comments
 (0)