github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/modules/aws/account_test.go (about) 1 package aws 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestGetAccountId(t *testing.T) { 10 accountID := GetAccountId(t) 11 assert.Regexp(t, "^[0-9]{12}$", accountID) 12 } 13 14 func TestExtractAccountIdFromValidArn(t *testing.T) { 15 t.Parallel() 16 17 expectedAccountID := "123456789012" 18 arn := "arn:aws:iam::" + expectedAccountID + ":user/test" 19 20 actualAccountID, err := extractAccountIDFromARN(arn) 21 if err != nil { 22 t.Fatalf("Unexpected error while extracting account id from arn %s: %s", arn, err) 23 } 24 25 if actualAccountID != expectedAccountID { 26 t.Fatalf("Did not get expected account id. Expected: %s. Actual: %s.", expectedAccountID, actualAccountID) 27 } 28 } 29 30 func TestExtractAccountIdFromInvalidArn(t *testing.T) { 31 t.Parallel() 32 33 _, err := extractAccountIDFromARN("invalidArn") 34 if err == nil { 35 t.Fatalf("Expected an error when extracting an account id from an invalid ARN, but got nil") 36 } 37 }