From bcfe0eafffb5b3af037eaf26ac25595a51d03b5f Mon Sep 17 00:00:00 2001 From: Max Neuvians Date: Mon, 22 Jan 2024 10:15:13 -0500 Subject: [PATCH] fix: optimize tests (#54) --- encryption/aws_kms_test.go | 10 +++++----- storage/dynamodb_test.go | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/encryption/aws_kms_test.go b/encryption/aws_kms_test.go index 1f6972c..e87e614 100644 --- a/encryption/aws_kms_test.go +++ b/encryption/aws_kms_test.go @@ -5,7 +5,7 @@ import ( "testing" ) -func getKmsHost() string { +var getKmsHost string = func() string { host := "http://local-kms:8080" if h := os.Getenv("KMS_HOST"); h != "" { @@ -13,7 +13,7 @@ func getKmsHost() string { } return host -} +}() func TestAwsKmsEncryptionInitMissingKeyId(t *testing.T) { t.Parallel() @@ -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", }) @@ -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", }) @@ -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", }) diff --git a/storage/dynamodb_test.go b/storage/dynamodb_test.go index 4fb2ab7..857ab1d 100644 --- a/storage/dynamodb_test.go +++ b/storage/dynamodb_test.go @@ -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", }) @@ -26,7 +26,7 @@ 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 != "" { @@ -34,7 +34,7 @@ func getDynamoDBHost() string { } return host -} +}() func TestDynamoDBBackendDelete(t *testing.T) { t.Parallel() @@ -42,7 +42,7 @@ func TestDynamoDBBackendDelete(t *testing.T) { backend := DynamoDBBackend{} _ = backend.Init(map[string]string{ - "endpoint": getDynamoDBHost(), + "endpoint": getDynamoDBHost, "region": "ca-central-1", "table_name": "secrets", }) @@ -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 { @@ -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", }) @@ -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", }) @@ -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", })