2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_Movable(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
defer releaseDB(db)
|
|
|
|
|
|
|
|
raw1 := generateRawObject(t)
|
|
|
|
raw2 := generateRawObject(t)
|
|
|
|
|
|
|
|
// put two objects in metabase
|
2020-11-27 09:03:35 +00:00
|
|
|
err := db.Put(raw1.Object(), nil)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-11-27 09:03:35 +00:00
|
|
|
err = db.Put(raw2.Object(), nil)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index empty
|
|
|
|
toMoveList, err := db.Movable()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 0)
|
|
|
|
|
|
|
|
// mark to move object2
|
2020-11-27 09:03:35 +00:00
|
|
|
err = db.ToMoveIt(raw2.Object().Address())
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index contains address of object 2
|
|
|
|
toMoveList, err = db.Movable()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 1)
|
2020-11-27 09:03:35 +00:00
|
|
|
require.Contains(t, toMoveList, raw2.Object().Address())
|
2020-11-23 13:30:56 +00:00
|
|
|
|
|
|
|
// remove from toMoveIt index non existing address
|
2020-11-27 09:03:35 +00:00
|
|
|
err = db.DoNotMove(raw1.Object().Address())
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index hasn't changed
|
|
|
|
toMoveList, err = db.Movable()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 1)
|
|
|
|
|
|
|
|
// remove from toMoveIt index existing address
|
2020-11-27 09:03:35 +00:00
|
|
|
err = db.DoNotMove(raw2.Object().Address())
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index is empty now
|
|
|
|
toMoveList, err = db.Movable()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 0)
|
|
|
|
}
|