2021-09-13 08:23:58 +00:00
|
|
|
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"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2022-05-12 16:37:46 +00:00
|
|
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
|
2021-09-13 08:23:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReset(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
|
|
|
err := db.Reset()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := generateObject(t)
|
|
|
|
addr := object.AddressOf(obj)
|
2021-09-13 08:23:58 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
addrToInhume := objecttest.Address()
|
2021-09-13 08:23:58 +00:00
|
|
|
|
2022-03-17 08:03:58 +00:00
|
|
|
assertExists := func(addr *addressSDK.Address, expExists bool, assertErr func(error) bool) {
|
2021-09-13 08:23:58 +00:00
|
|
|
exists, err := meta.Exists(db, addr)
|
2022-03-17 08:03:58 +00:00
|
|
|
if assertErr != nil {
|
|
|
|
require.True(t, assertErr(err))
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2021-09-13 08:23:58 +00:00
|
|
|
require.Equal(t, expExists, exists)
|
|
|
|
}
|
|
|
|
|
|
|
|
assertExists(addr, false, nil)
|
|
|
|
assertExists(addrToInhume, false, nil)
|
|
|
|
|
|
|
|
err = putBig(db, obj)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
err = meta.Inhume(db, addrToInhume, objecttest.Address())
|
2021-09-13 08:23:58 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assertExists(addr, true, nil)
|
2022-03-17 08:03:58 +00:00
|
|
|
assertExists(addrToInhume, false, meta.IsErrRemoved)
|
2021-09-13 08:23:58 +00:00
|
|
|
|
|
|
|
err = db.Reset()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assertExists(addr, false, nil)
|
|
|
|
assertExists(addr, false, nil)
|
|
|
|
}
|