frostfs-node/pkg/local_object_storage/metabase/control_test.go

52 lines
1.2 KiB
Go
Raw Normal View History

package meta_test
import (
"testing"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
"github.com/stretchr/testify/require"
)
func TestReset(t *testing.T) {
db := newDB(t)
err := db.Reset()
require.NoError(t, err)
obj := generateObject(t)
addr := object.AddressOf(obj)
addrToInhume := objecttest.Address()
assertExists := func(addr *addressSDK.Address, expExists bool, assertErr func(error) bool) {
exists, err := meta.Exists(db, addr)
if assertErr != nil {
require.True(t, assertErr(err))
} else {
require.NoError(t, err)
}
require.Equal(t, expExists, exists)
}
assertExists(addr, false, nil)
assertExists(addrToInhume, false, nil)
err = putBig(db, obj)
require.NoError(t, err)
err = meta.Inhume(db, addrToInhume, objecttest.Address())
require.NoError(t, err)
assertExists(addr, true, nil)
assertExists(addrToInhume, false, meta.IsErrRemoved)
err = db.Reset()
require.NoError(t, err)
assertExists(addr, false, nil)
assertExists(addr, false, nil)
}