Skip to content

add dynamodb lock e2e test #1387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions cli_e2e/aws_dynamodb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cli_e2e

import (
"os"
"testing"

"github.com/diggerhq/digger/cli/pkg/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")
}
}