diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index 7b0a0eb0a4..f1b4b10120 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -1,13 +1,13 @@ package meta_test import ( + "crypto/rand" "os" "strconv" "testing" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-sdk-go/checksum" - checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" @@ -16,7 +16,6 @@ import ( oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" "github.com/nspcc-dev/neofs-sdk-go/version" - "github.com/nspcc-dev/tzhash/tz" "github.com/stretchr/testify/require" ) @@ -76,12 +75,14 @@ func generateObjectWithCID(t testing.TB, cnr cid.ID) *object.Object { ver.SetMajor(2) ver.SetMinor(1) - csum := checksumtest.Checksum() - - var csumTZ checksum.Checksum - csumTZ.SetTillichZemor(tz.Sum(csum.Value())) + payload := make([]byte, 10) + _, err := rand.Read(payload) + require.NoError(t, err) - payload := []byte{1, 2, 3, 4, 5} + csum, err := checksum.NewFromData(checksum.SHA256, payload) + require.NoError(t, err) + csumTZ, err := checksum.NewFromData(checksum.TillichZemor, payload) + require.NoError(t, err) obj := object.New() obj.SetID(oidtest.ID()) diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index d8dea30eea..a607d4c99e 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -376,32 +376,40 @@ func TestDB_SelectPayloadHash(t *testing.T) { cs, _ := raw1.PayloadChecksum() payloadHash := [sha256.Size]byte(cs.Value()) - fs := objectSDK.SearchFilters{} - fs.AddPayloadHashFilter(objectSDK.MatchStringEqual, payloadHash) + t.Run("equal filter", func(t *testing.T) { + fs := objectSDK.SearchFilters{} + fs.AddPayloadHashFilter(objectSDK.MatchStringEqual, payloadHash) - testSelect(t, db, cnr, fs, object.AddressOf(raw1)) + testSelect(t, db, cnr, fs, object.AddressOf(raw1)) + }) - fs = objectSDK.SearchFilters{} - fs.AddFilter(objectSDK.FilterPayloadChecksum, - hex.EncodeToString(payloadHash[:len(payloadHash)-1]), - objectSDK.MatchCommonPrefix) + t.Run("common prefix filter", func(t *testing.T) { + fs := objectSDK.SearchFilters{} + fs.AddFilter(objectSDK.FilterPayloadChecksum, + hex.EncodeToString(payloadHash[:len(payloadHash)-1]), + objectSDK.MatchCommonPrefix) - testSelect(t, db, cnr, fs, object.AddressOf(raw1)) + testSelect(t, db, cnr, fs, object.AddressOf(raw1)) + }) - fs = objectSDK.SearchFilters{} - fs.AddPayloadHashFilter(objectSDK.MatchStringNotEqual, payloadHash) + t.Run("not equal filter", func(t *testing.T) { + fs := objectSDK.SearchFilters{} + fs.AddPayloadHashFilter(objectSDK.MatchStringNotEqual, payloadHash) - testSelect(t, db, cnr, fs, object.AddressOf(raw2)) + testSelect(t, db, cnr, fs, object.AddressOf(raw2)) + }) - fs = objectSDK.SearchFilters{} - fs.AddFilter(objectSDK.FilterPayloadChecksum, - "", - objectSDK.MatchNotPresent) + t.Run("not present filter", func(t *testing.T) { + fs := objectSDK.SearchFilters{} + fs.AddFilter(objectSDK.FilterPayloadChecksum, + "", + objectSDK.MatchNotPresent) - testSelect(t, db, cnr, fs) + testSelect(t, db, cnr, fs) + }) t.Run("invalid hashes", func(t *testing.T) { - fs = objectSDK.SearchFilters{} + fs := objectSDK.SearchFilters{} otherHash := payloadHash otherHash[0]++ fs.AddPayloadHashFilter(objectSDK.MatchStringNotEqual, otherHash)