2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"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
|
|
|
|
err := db.Put(child.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// fill ToMoveIt index
|
|
|
|
err = db.ToMoveIt(child.Object().Address())
|
|
|
|
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
|
|
|
|
l, err := db.Movable()
|
|
|
|
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 07:51:34 +00:00
|
|
|
err = db.Inhume(child.Object().Address(), ts.Object().Address())
|
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
err = db.Inhume(child.Object().Address(), ts.Object().Address())
|
|
|
|
require.NoError(t, err)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// delete object
|
|
|
|
err = db.Delete(child.Object().Address())
|
|
|
|
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
|
|
|
|
l, err = db.Movable()
|
|
|
|
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
|
|
|
|
ok, err := db.Exists(child.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, ok)
|
2020-11-09 10:09:09 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
ok, err = db.Exists(parent.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, ok)
|
2020-11-09 10:09:09 +00:00
|
|
|
}
|