[#1445] metabase/test: Add test for GetLocks
method
Since it'll be working with locks of the new format, i. e. locks with expiration epoch, it's better to have a test for this method to ensure it can handle locks of both old and new formats. Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
d70e1d29da
commit
428cfed8af
1 changed files with 38 additions and 0 deletions
|
@ -288,3 +288,41 @@ func putAndLockObj(t *testing.T, db *meta.DB, numOfLockedObjs int) ([]*objectSDK
|
|||
|
||||
return lockedObjs, lockObj
|
||||
}
|
||||
|
||||
func TestGetLocks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := newDB(t)
|
||||
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
||||
|
||||
object := oidtest.Address()
|
||||
|
||||
t.Run("no locks for object", func(t *testing.T) {
|
||||
gotLocks, err := db.GetLocks(context.Background(), object)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, gotLocks)
|
||||
})
|
||||
|
||||
locks := []meta.Lock{
|
||||
{oidtest.ID(), 1},
|
||||
{oidtest.ID(), 2},
|
||||
}
|
||||
|
||||
for _, lock := range locks {
|
||||
require.NoError(t,
|
||||
db.Lock(context.Background(), object.Container(), lock.ID, []oid.ID{object.Object()}, lock.ExpEpoch),
|
||||
)
|
||||
|
||||
// try to lock with the same lock object to ensure
|
||||
// that all locks are unique and set only once.
|
||||
require.NoError(t,
|
||||
db.Lock(context.Background(), object.Container(), lock.ID, []oid.ID{object.Object()}, lock.ExpEpoch+100),
|
||||
)
|
||||
}
|
||||
|
||||
t.Run("object is locked", func(t *testing.T) {
|
||||
gotLocks, err := db.GetLocks(context.Background(), object)
|
||||
require.NoError(t, err)
|
||||
require.ElementsMatch(t, locks, gotLocks)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue