forked from TrueCloudLab/frostfs-node
9508633a7e
After introduction of LOCK objects (of type `TypeLock`) complicated extended its behavior: * create `lockers` container bucket (LCB) during PUT; * remove object from LCB during DELETE; * look up object in LCB during EXISTS; * get object from LCB during GET; * list objects from LCB during LIST with cursor; * select objects from LCB during SELECT with '*'. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package meta_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDB_Lock(t *testing.T) {
|
|
cnr := *cidtest.ID()
|
|
db := newDB(t)
|
|
|
|
t.Run("empty locked list", func(t *testing.T) {
|
|
require.Panics(t, func() { _ = db.Lock(cnr, oid.ID{}, nil) })
|
|
require.Panics(t, func() { _ = db.Lock(cnr, oid.ID{}, []oid.ID{}) })
|
|
})
|
|
|
|
t.Run("(ir)regular", func(t *testing.T) {
|
|
for _, typ := range [...]object.Type{
|
|
object.TypeTombstone,
|
|
object.TypeStorageGroup,
|
|
object.TypeLock,
|
|
object.TypeRegular,
|
|
} {
|
|
obj := objecttest.Raw()
|
|
obj.SetType(typ)
|
|
obj.SetContainerID(&cnr)
|
|
|
|
// save irregular object
|
|
err := meta.Put(db, obj, nil)
|
|
require.NoError(t, err, typ)
|
|
|
|
// try to lock it
|
|
err = db.Lock(cnr, *oidtest.ID(), []oid.ID{*obj.ID()})
|
|
if typ == object.TypeRegular {
|
|
require.NoError(t, err, typ)
|
|
} else {
|
|
require.ErrorIs(t, err, meta.ErrLockIrregularObject, typ)
|
|
}
|
|
}
|
|
})
|
|
}
|