Skip to content

Commit

Permalink
Add opt-in feature for acmpca tests 🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzjdevk committed Jul 14, 2021
1 parent d178419 commit 50b4e35
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions aws/acmpca_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"os"
"testing"
"time"

Expand All @@ -13,8 +14,27 @@ import (
"github.com/stretchr/testify/assert"
)

// enableACMPCAExpensiveEnv is used to control whether to run
// the following test or not. The idea is that the test are disabled
// per default and one has to opt-in to enable the test as creating
// and destroying a ACM PCA is expensive.
// Upper bound, worst case: $400 / month per single CA create/delete.
const enableACMPCAExpensiveEnv = "TEST_ACMPCA_EXPENSIVE_ENABLE"

// runOrSkip decides whether to run or skip the test depending
// whether the env-var `TEST_ACMPCA_EXPENSIVE_ENABLE` is set or not.
func runOrSkip(t *testing.T) {
if _, isSet := os.LookupEnv(enableACMPCAExpensiveEnv); !isSet {
t.Skipf("Skipping the integration test for acmpca. Set the env-var '%s' to enable this expensive test.", enableACMPCAExpensiveEnv)
}
}

// createTestACMPCA will create am ACMPCA and return its ARN.
func createTestACMPCA(t *testing.T, session *session.Session, name string) *string {
// As an additional safety guard, we are adding another check here
// to decide whether to run the test or not.
runOrSkip(t)

svc := acmpca.New(session)
ca, err := svc.CreateCertificateAuthority(&acmpca.CreateCertificateAuthorityInput{
CertificateAuthorityConfiguration: &acmpca.CertificateAuthorityConfiguration{
Expand All @@ -39,6 +59,7 @@ func createTestACMPCA(t *testing.T, session *session.Session, name string) *stri
}

func TestListACMPCA(t *testing.T) {
runOrSkip(t)
t.Parallel()

region, err := getRandomRegion()
Expand Down Expand Up @@ -73,6 +94,7 @@ func TestListACMPCA(t *testing.T) {
}

func TestNukeACMPCA(t *testing.T) {
runOrSkip(t)
t.Parallel()

region, err := getRandomRegion()
Expand Down

0 comments on commit 50b4e35

Please sign in to comment.