database: add test for lock expiration

This commit is contained in:
Jimmy Zelinskie 2019-02-28 15:54:57 -05:00
parent a4e7873d14
commit 961c7d4680

View File

@ -1,4 +1,4 @@
// Copyright 2016 clair authors // Copyright 2019 clair authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -19,8 +19,23 @@ import (
"time" "time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestAcquireLockReturnsExistingLockDuration(t *testing.T) {
datastore, tx := openSessionForTest(t, "Lock", true)
defer datastore.Close()
acquired, originalExpiration, err := tx.AcquireLock("test1", "owner1", time.Minute)
require.Nil(t, err)
require.True(t, acquired)
acquired2, expiration, err := tx.AcquireLock("test1", "owner2", time.Hour)
require.Nil(t, err)
require.False(t, acquired2)
require.Equal(t, expiration, originalExpiration)
}
func TestLock(t *testing.T) { func TestLock(t *testing.T) {
datastore, tx := openSessionForTest(t, "Lock", true) datastore, tx := openSessionForTest(t, "Lock", true)
defer datastore.Close() defer datastore.Close()