frostfs-node/pkg/local_object_storage/metabase/control_test.go
Ayrat Arifullin 9808dec591 [#86] node: Move testing utils to one package
Move testing utils from tests in local_object_storage package to
unified testutil package

Signed-off-by: Airat Arifullin <aarifullin@yadro.com>
2023-03-23 08:19:15 +00:00

60 lines
1.5 KiB
Go

package meta_test
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
"github.com/stretchr/testify/require"
)
func TestReset(t *testing.T) {
db := newDB(t)
err := db.Reset()
require.NoError(t, err)
obj := testutil.GenerateObject()
addr := object.AddressOf(obj)
addrToInhume := oidtest.Address()
assertExists := func(addr oid.Address, expExists bool, assertErr func(error) bool) {
exists, err := metaExists(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 = metaInhume(db, addrToInhume, oidtest.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)
}
func metaExists(db *meta.DB, addr oid.Address) (bool, error) {
var existsPrm meta.ExistsPrm
existsPrm.SetAddress(addr)
res, err := db.Exists(existsPrm)
return res.Exists(), err
}