Skip to content

Commit

Permalink
fix vpc link arn match test, add regex test function that doesnt use …
Browse files Browse the repository at this point in the history
…account id
  • Loading branch information
DrFaust92 committed Oct 19, 2019
1 parent 00c5de0 commit b7de74f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions aws/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ func testAccMatchResourceAttrRegionalARN(resourceName, attributeName, arnService
}
}

// testAccMatchResourceAttrRegionalARN ensures the Terraform state regexp matches a formatted ARN with region and no account id
func testAccMatchResourceAttrRegionalARNNoAccount(resourceName, attributeName, arnService string, arnResourceRegexp *regexp.Regexp) resource.TestCheckFunc {
return func(s *terraform.State) error {
arnRegexp := arn.ARN{
Partition: testAccGetPartition(),
Region: testAccGetRegion(),
Resource: arnResourceRegexp.String(),
Service: arnService,
}.String()

attributeMatch, err := regexp.Compile(arnRegexp)

if err != nil {
return fmt.Errorf("Unable to compile ARN regexp (%s): %s", arnRegexp, err)
}

return resource.TestMatchResourceAttr(resourceName, attributeName, attributeMatch)(s)
}
}

// testAccCheckResourceAttrGlobalARN ensures the Terraform state exactly matches a formatted ARN without region
func testAccCheckResourceAttrGlobalARN(resourceName, attributeName, arnService, arnResource string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_api_gateway_vpc_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestAccAWSAPIGatewayVpcLink_basic(t *testing.T) {
Config: testAccAPIGatewayVpcLinkConfig(rName, "test"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsAPIGatewayVpcLinkExists(resourceName),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "apigateway", regexp.MustCompile(`/vpclinks/.+`)),
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/vpclinks/.+`)),
resource.TestCheckResourceAttr(resourceName, "name", vpcLinkName),
resource.TestCheckResourceAttr(resourceName, "description", "test"),
resource.TestCheckResourceAttr(resourceName, "target_arns.#", "1"),
Expand All @@ -84,7 +84,7 @@ func TestAccAWSAPIGatewayVpcLink_basic(t *testing.T) {
Config: testAccAPIGatewayVpcLinkConfig_Update(rName, "test update"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsAPIGatewayVpcLinkExists(resourceName),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "apigateway", regexp.MustCompile(`/vpclinks/.+`)),
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/vpclinks/.+`)),
resource.TestCheckResourceAttr(resourceName, "name", vpcLinkNameUpdated),
resource.TestCheckResourceAttr(resourceName, "description", "test update"),
resource.TestCheckResourceAttr(resourceName, "target_arns.#", "1"),
Expand Down

0 comments on commit b7de74f

Please sign in to comment.