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