Skip to content

Commit 8342c4e

Browse files
authored
add dynamodb lock e2e test (#1387)
1 parent 3da5850 commit 8342c4e

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

cli_e2e/aws_dynamodb_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cli_e2e
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/diggerhq/digger/cli/pkg/locking"
8+
)
9+
10+
func TestAWSDynamoDBLockE2E(t *testing.T) {
11+
// Requires AWS login
12+
os.Setenv("AWS_REGION", "us-east-1")
13+
os.Setenv("LOCK_PROVIDER", "aws")
14+
15+
lock, err := locking.GetLock()
16+
if err != nil {
17+
t.Errorf("failed to get locking provider: %v\n", err)
18+
}
19+
if lock != nil {
20+
lock.Unlock("test")
21+
}
22+
23+
lockID, err := lock.GetLock("test")
24+
if err != nil {
25+
t.Errorf("failed to get lock: %v\n", err)
26+
}
27+
t.Logf("lockID: %v\n", lockID)
28+
29+
locked, err := lock.Lock(1, "test")
30+
if err != nil || locked != true {
31+
t.Errorf("failed to lock: %v, locked: %v\n", err, locked)
32+
}
33+
34+
lockID2, err := lock.GetLock("test")
35+
if err != nil {
36+
t.Errorf("failed to get lock: %v\n", err)
37+
}
38+
if lockID2 == nil {
39+
t.Errorf("lock is nil while it should be set\n")
40+
}
41+
locked, err = lock.Lock(1, "test")
42+
if err != nil {
43+
t.Errorf("failed to lock a second time, but not due to condition: %v\n", err)
44+
}
45+
if locked != false {
46+
t.Errorf("locked: %v should have been locked\n", locked)
47+
}
48+
49+
unlocked, err := lock.Unlock("test")
50+
if err != nil || unlocked != true {
51+
t.Errorf("failed to unlock: %v, unlocked: %v\n", err, unlocked)
52+
}
53+
if !unlocked {
54+
t.Logf("lock has not been unlocked\n")
55+
}
56+
}

0 commit comments

Comments
 (0)