data/fs: faster comparison in tests

This commit is contained in:
Michael Eischer
2026-06-15 21:53:33 +02:00
parent f91afb2fa8
commit 18e5c446e0
2 changed files with 7 additions and 3 deletions
+4 -2
View File
@@ -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))
}
})
+3 -1
View File
@@ -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))
}
}