2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2020-10-30 13:42:24 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_Delete(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2020-11-02 07:55:35 +00:00
|
|
|
defer releaseDB(db)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
cid := testCID()
|
|
|
|
parent := generateRawObjectWithCID(t, cid)
|
|
|
|
addAttribute(parent, "foo", "bar")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
child := generateRawObjectWithCID(t, cid)
|
|
|
|
child.SetParent(parent.Object().SDK())
|
|
|
|
child.SetParentID(parent.ID())
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// put object with parent
|
2020-12-08 09:56:14 +00:00
|
|
|
err := putBig(db, child.Object())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// fill ToMoveIt index
|
2020-12-08 09:56:14 +00:00
|
|
|
err = meta.ToMoveIt(db, child.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// check if Movable list is not empty
|
2020-12-08 09:56:14 +00:00
|
|
|
l, err := meta.Movable(db)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, l, 1)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// inhume parent and child so they will be on graveyard
|
|
|
|
ts := generateRawObjectWithCID(t, cid)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
err = meta.Inhume(db, child.Object().Address(), ts.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
err = meta.Inhume(db, child.Object().Address(), ts.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// delete object
|
2020-12-08 09:56:14 +00:00
|
|
|
err = meta.Delete(db, child.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// check if there is no data in Movable index
|
2020-12-08 09:56:14 +00:00
|
|
|
l, err = meta.Movable(db)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, l, 0)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// check if they removed from graveyard
|
2020-12-08 09:56:14 +00:00
|
|
|
ok, err := meta.Exists(db, child.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, ok)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
ok, err = meta.Exists(db, parent.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, ok)
|
2020-11-09 10:09:09 +00:00
|
|
|
}
|