[#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:
Aleksey Savchuk 2024-12-12 15:40:32 +03:00
parent d70e1d29da
commit 428cfed8af
Signed by: a-savchuk
GPG key ID: 70C0A7FF6F9C4639

View file

@ -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)
})
}