2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_Exists(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
defer releaseDB(db)
|
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("no object", func(t *testing.T) {
|
|
|
|
nonExist := generateRawObject(t)
|
|
|
|
exists, err := db.Exists(nonExist.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, exists)
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("regular object", func(t *testing.T) {
|
|
|
|
regular := generateRawObject(t)
|
|
|
|
err := db.Put(regular.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
exists, err := db.Exists(regular.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("tombstone object", func(t *testing.T) {
|
|
|
|
ts := generateRawObject(t)
|
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
err := db.Put(ts.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
exists, err := db.Exists(ts.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("storage group object", func(t *testing.T) {
|
|
|
|
sg := generateRawObject(t)
|
|
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
|
|
|
|
|
|
|
err := db.Put(sg.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
exists, err := db.Exists(sg.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("virtual object", func(t *testing.T) {
|
|
|
|
cid := testCID()
|
|
|
|
parent := generateRawObjectWithCID(t, cid)
|
|
|
|
|
|
|
|
child := generateRawObjectWithCID(t, cid)
|
|
|
|
child.SetParent(parent.Object().SDK())
|
|
|
|
child.SetParentID(parent.Object().Address().ObjectID())
|
|
|
|
|
|
|
|
err := db.Put(child.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
exists, err := db.Exists(parent.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|