frostfs-node/pkg/local_object_storage/shard/delete_test.go
Leonard Lyubich f15e6e888f [#1377] oid, cid: Upgrade SDK package
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2022-05-16 15:33:22 +03:00

80 lines
1.8 KiB
Go

package shard_test
import (
"testing"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
"github.com/stretchr/testify/require"
)
func TestShard_Delete(t *testing.T) {
t.Run("without write cache", func(t *testing.T) {
testShardDelete(t, false)
})
t.Run("with write cache", func(t *testing.T) {
testShardDelete(t, true)
})
}
func testShardDelete(t *testing.T, hasWriteCache bool) {
sh := newShard(t, hasWriteCache)
defer releaseShard(sh, t)
cnr := cidtest.ID()
obj := generateObjectWithCID(t, cnr)
addAttribute(obj, "foo", "bar")
putPrm := new(shard.PutPrm)
getPrm := new(shard.GetPrm)
t.Run("big object", func(t *testing.T) {
addPayload(obj, 1<<20)
putPrm.WithObject(obj)
getPrm.WithAddress(object.AddressOf(obj))
delPrm := new(shard.DeletePrm)
delPrm.WithAddresses(object.AddressOf(obj))
_, err := sh.Put(putPrm)
require.NoError(t, err)
_, err = testGet(t, sh, getPrm, hasWriteCache)
require.NoError(t, err)
_, err = sh.Delete(delPrm)
require.NoError(t, err)
_, err = sh.Get(getPrm)
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
})
t.Run("small object", func(t *testing.T) {
obj.SetID(oidtest.ID())
addPayload(obj, 1<<5)
putPrm.WithObject(obj)
getPrm.WithAddress(object.AddressOf(obj))
delPrm := new(shard.DeletePrm)
delPrm.WithAddresses(object.AddressOf(obj))
_, err := sh.Put(putPrm)
require.NoError(t, err)
_, err = sh.Get(getPrm)
require.NoError(t, err)
_, err = sh.Delete(delPrm)
require.NoError(t, err)
_, err = sh.Get(getPrm)
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
})
}