2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-28 14:49:30 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
2022-05-17 13:59:46 +00:00
|
|
|
checksumtest "github.com/nspcc-dev/neofs-sdk-go/checksum/test"
|
2021-11-10 07:08:33 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2022-05-12 16:37:46 +00:00
|
|
|
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
2022-05-17 13:59:46 +00:00
|
|
|
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
2020-12-08 07:51:34 +00:00
|
|
|
"github.com/nspcc-dev/tzhash/tz"
|
2020-10-28 14:49:30 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
// saves "big" object in DB.
|
|
|
|
func putBig(db *meta.DB, obj *object.Object) error {
|
|
|
|
return meta.Put(db, obj, nil)
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func testSelect(t *testing.T, db *meta.DB, cnr cid.ID, fs object.SearchFilters, exp ...oid.Address) {
|
|
|
|
res, err := meta.Select(db, cnr, fs)
|
2020-10-28 14:49:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, res, len(exp))
|
|
|
|
|
|
|
|
for i := range exp {
|
|
|
|
require.Contains(t, res, exp[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 13:34:31 +00:00
|
|
|
func newDB(t testing.TB, opts ...meta.Option) *meta.DB {
|
2020-12-08 07:51:34 +00:00
|
|
|
path := t.Name()
|
2020-10-29 12:03:55 +00:00
|
|
|
|
2022-03-21 13:34:31 +00:00
|
|
|
bdb := meta.New(append([]meta.Option{meta.WithPath(path), meta.WithPermissions(0600)},
|
|
|
|
opts...)...)
|
2020-10-29 12:03:55 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, bdb.Open())
|
2022-04-26 19:49:59 +00:00
|
|
|
require.NoError(t, bdb.Init())
|
2020-10-29 12:03:55 +00:00
|
|
|
|
2021-10-27 10:56:30 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
bdb.Close()
|
|
|
|
os.Remove(bdb.DumpInfo().Path)
|
|
|
|
})
|
2020-10-29 16:12:38 +00:00
|
|
|
|
2021-10-27 10:56:30 +00:00
|
|
|
return bdb
|
2020-10-29 16:12:38 +00:00
|
|
|
}
|
2020-11-02 07:37:16 +00:00
|
|
|
|
2022-03-21 13:34:31 +00:00
|
|
|
func generateObject(t testing.TB) *object.Object {
|
2022-03-03 14:19:05 +00:00
|
|
|
return generateObjectWithCID(t, cidtest.ID())
|
2020-11-02 07:37:16 +00:00
|
|
|
}
|
2020-11-02 07:55:35 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
func generateObjectWithCID(t testing.TB, cnr cid.ID) *object.Object {
|
2022-05-11 14:58:52 +00:00
|
|
|
var ver version.Version
|
|
|
|
ver.SetMajor(2)
|
|
|
|
ver.SetMinor(1)
|
2020-11-02 07:55:35 +00:00
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
csum := checksumtest.Checksum()
|
2020-11-02 08:01:55 +00:00
|
|
|
|
2022-05-11 16:35:01 +00:00
|
|
|
var csumTZ checksum.Checksum
|
|
|
|
csumTZ.SetTillichZemor(tz.Sum(csum.Value()))
|
2020-11-02 08:01:55 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := object.New()
|
2022-05-12 16:37:46 +00:00
|
|
|
obj.SetID(oidtest.ID())
|
2022-05-17 13:59:46 +00:00
|
|
|
obj.SetOwnerID(usertest.ID())
|
2022-05-12 16:37:46 +00:00
|
|
|
obj.SetContainerID(cnr)
|
2022-05-11 14:58:52 +00:00
|
|
|
obj.SetVersion(&ver)
|
2020-12-08 07:51:34 +00:00
|
|
|
obj.SetPayloadChecksum(csum)
|
|
|
|
obj.SetPayloadHomomorphicHash(csumTZ)
|
2021-03-22 16:44:57 +00:00
|
|
|
obj.SetPayload([]byte{1, 2, 3, 4, 5})
|
2020-11-02 08:01:55 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
return obj
|
2020-11-02 08:01:55 +00:00
|
|
|
}
|
2020-11-06 09:41:59 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
func addAttribute(obj *object.Object, key, val string) {
|
2022-03-15 12:11:35 +00:00
|
|
|
var attr object.Attribute
|
2020-12-08 07:51:34 +00:00
|
|
|
attr.SetKey(key)
|
|
|
|
attr.SetValue(val)
|
2020-11-06 09:41:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
attrs := obj.Attributes()
|
|
|
|
attrs = append(attrs, attr)
|
|
|
|
obj.SetAttributes(attrs...)
|
2020-11-06 09:41:59 +00:00
|
|
|
}
|