Skip to content

Commit

Permalink
fix: optimize tests (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxneuvians authored Jan 22, 2024
1 parent b14b920 commit bcfe0ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions encryption/aws_kms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"testing"
)

func getKmsHost() string {
var getKmsHost string = func() string {
host := "http://local-kms:8080"

if h := os.Getenv("KMS_HOST"); h != "" {
host = h
}

return host
}
}()

func TestAwsKmsEncryptionInitMissingKeyId(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestAwsKmsEncryptionInitValid(t *testing.T) {
e := AwsKmsEncryption{}

err := e.Init(map[string]string{
"endpoint": getKmsHost(),
"endpoint": getKmsHost,
"kms_key_id": "test",
"region": "ca-central-1",
})
Expand All @@ -65,7 +65,7 @@ func TestAwsKmsEncryptionEncrypt(t *testing.T) {
e := AwsKmsEncryption{}

_ = e.Init(map[string]string{
"endpoint": getKmsHost(),
"endpoint": getKmsHost,
"kms_key_id": "bc436485-5092-42b8-92a3-0aa8b93536dc", // Set in .devcontainer/docker/kms/init.yml
"region": "ca-central-1",
})
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestAwsKmsEncryptionDecrypt(t *testing.T) {
e := AwsKmsEncryption{}

_ = e.Init(map[string]string{
"endpoint": getKmsHost(),
"endpoint": getKmsHost,
"kms_key_id": "bc436485-5092-42b8-92a3-0aa8b93536dc", // Set in .devcontainer/docker/kms/init.yml
"region": "ca-central-1",
})
Expand Down
16 changes: 8 additions & 8 deletions storage/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestMain(m *testing.M) {
backend := DynamoDBBackend{}

_ = backend.Init(map[string]string{
"endpoint": getDynamoDBHost(),
"endpoint": getDynamoDBHost,
"region": "ca-central-1",
"table_name": "secrets",
})
Expand All @@ -26,23 +26,23 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

func getDynamoDBHost() string {
var getDynamoDBHost string = func() string {
host := "http://dynamodb-local:8000"

if h := os.Getenv("DYNAMODB_HOST"); h != "" {
host = h
}

return host
}
}()

func TestDynamoDBBackendDelete(t *testing.T) {
t.Parallel()

backend := DynamoDBBackend{}

_ = backend.Init(map[string]string{
"endpoint": getDynamoDBHost(),
"endpoint": getDynamoDBHost,
"region": "ca-central-1",
"table_name": "secrets",
})
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestDynamoDBBackendInitWithEndpoint(t *testing.T) {
err := backend.Init(map[string]string{
"region": "ca-central-1",
"table_name": "secrets",
"endpoint": getDynamoDBHost(),
"endpoint": getDynamoDBHost,
})

if err != nil {
Expand All @@ -119,7 +119,7 @@ func TestDynamoDBBackendStore(t *testing.T) {
backend := DynamoDBBackend{}

_ = backend.Init(map[string]string{
"endpoint": getDynamoDBHost(),
"endpoint": getDynamoDBHost,
"region": "ca-central-1",
"table_name": "secrets",
})
Expand All @@ -141,7 +141,7 @@ func TestDynamoDBBackendRetrieveWithTTLInFuture(t *testing.T) {
backend := DynamoDBBackend{}

_ = backend.Init(map[string]string{
"endpoint": getDynamoDBHost(),
"endpoint": getDynamoDBHost,
"region": "ca-central-1",
"table_name": "secrets",
})
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestDynamoDBBackendRetrieveWithTTLInPast(t *testing.T) {
backend := DynamoDBBackend{}

_ = backend.Init(map[string]string{
"endpoint": getDynamoDBHost(),
"endpoint": getDynamoDBHost,
"region": "ca-central-1",
"table_name": "secrets",
})
Expand Down

0 comments on commit bcfe0ea

Please sign in to comment.