From 18e5c446e05902649b5589f98809018fdd4d802e Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 15 Jun 2026 21:53:33 +0200 Subject: [PATCH] data/fs: faster comparison in tests --- internal/data/snapshot_policy_test.go | 6 ++++-- internal/fs/fs_reader_test.go | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/data/snapshot_policy_test.go b/internal/data/snapshot_policy_test.go index 7cb943361..b74bfd667 100644 --- a/internal/data/snapshot_policy_test.go +++ b/internal/data/snapshot_policy_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "reflect" "testing" "time" @@ -275,11 +276,12 @@ func TestApplyPolicy(t *testing.T) { cmpOpts := cmpopts.IgnoreUnexported(data.Snapshot{}) - if !cmp.Equal(want.Keep, keep, cmpOpts) { + // reflect.DeepEqual is faster than cmp.Equal + if !reflect.DeepEqual(want.Keep, keep) { t.Error(cmp.Diff(want.Keep, keep, cmpOpts)) } - if !cmp.Equal(want.Reasons, reasons, cmpOpts) { + if !reflect.DeepEqual(want.Reasons, reasons) { t.Error(cmp.Diff(want.Reasons, reasons, cmpOpts)) } }) diff --git a/internal/fs/fs_reader_test.go b/internal/fs/fs_reader_test.go index d56583646..a467a522f 100644 --- a/internal/fs/fs_reader_test.go +++ b/internal/fs/fs_reader_test.go @@ -6,6 +6,7 @@ import ( "io" "os" "path" + "slices" "sort" "strings" "testing" @@ -23,7 +24,8 @@ func verifyFileContentOpenFile(t testing.TB, fs FS, filename string, want []byte test.OK(t, err) test.OK(t, f.Close()) - if !cmp.Equal(want, buf) { + // slices.Equal is much faster than cmp.Equal + if !slices.Equal(want, buf) { t.Error(cmp.Diff(want, buf)) } }