[#128] metabase: Implement Delete method
Implement Delete method on DB structure that adds deleted addresses to tombstone index. Do not attach addresses from tombstone index to Select result. Return error from Get method if address is presented in tombstone index. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
2d319aa29c
commit
20ed7c0d61
4 changed files with 105 additions and 9 deletions
|
@ -26,16 +26,32 @@ func testSelect(t *testing.T, db *DB, fs objectSDK.SearchFilters, exp ...*object
|
|||
}
|
||||
}
|
||||
|
||||
func testCID() *container.ID {
|
||||
cs := [sha256.Size]byte{}
|
||||
rand.Read(cs[:])
|
||||
|
||||
id := container.NewID()
|
||||
id.SetSHA256(cs)
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
func testOID() *objectSDK.ID {
|
||||
cs := [sha256.Size]byte{}
|
||||
rand.Read(cs[:])
|
||||
|
||||
id := objectSDK.NewID()
|
||||
id.SetSHA256(cs)
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
func TestDB(t *testing.T) {
|
||||
version := pkg.NewVersion()
|
||||
version.SetMajor(2)
|
||||
version.SetMinor(1)
|
||||
|
||||
cs := [sha256.Size]byte{}
|
||||
rand.Read(cs[:])
|
||||
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(cs)
|
||||
cid := testCID()
|
||||
|
||||
w, err := owner.NEO3WalletFromPublicKey(&test.DecodeKey(-1).PublicKey)
|
||||
require.NoError(t, err)
|
||||
|
@ -43,9 +59,7 @@ func TestDB(t *testing.T) {
|
|||
ownerID := owner.NewID()
|
||||
ownerID.SetNeo3Wallet(w)
|
||||
|
||||
rand.Read(cs[:])
|
||||
oid := objectSDK.NewID()
|
||||
oid.SetSHA256(cs)
|
||||
oid := testOID()
|
||||
|
||||
obj := object.NewRaw()
|
||||
obj.SetID(oid)
|
||||
|
@ -100,3 +114,42 @@ func TestDB(t *testing.T) {
|
|||
fs.AddFilter(k, v+"1", objectSDK.MatchStringEqual)
|
||||
testSelect(t, db, fs)
|
||||
}
|
||||
|
||||
func TestDB_Delete(t *testing.T) {
|
||||
path := "test.db"
|
||||
|
||||
bdb, err := bbolt.Open(path, 0600, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer func() {
|
||||
bdb.Close()
|
||||
os.Remove(path)
|
||||
}()
|
||||
|
||||
db := NewDB(bdb)
|
||||
|
||||
obj := object.NewRaw()
|
||||
obj.SetContainerID(testCID())
|
||||
obj.SetID(testOID())
|
||||
|
||||
o := obj.Object()
|
||||
|
||||
require.NoError(t, db.Put(o))
|
||||
|
||||
addr := o.Address()
|
||||
|
||||
_, err = db.Get(addr)
|
||||
require.NoError(t, err)
|
||||
|
||||
fs := objectSDK.SearchFilters{}
|
||||
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, o.GetContainerID())
|
||||
|
||||
testSelect(t, db, fs, o.Address())
|
||||
|
||||
require.NoError(t, db.Delete(addr))
|
||||
|
||||
_, err = db.Get(addr)
|
||||
require.Error(t, err)
|
||||
|
||||
testSelect(t, db, fs)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue