Skip to content

Commit

Permalink
Add TestAccAWSCodeStarConnectionsConnection_disappears
Browse files Browse the repository at this point in the history
  • Loading branch information
shuheiktgw committed Dec 15, 2020
1 parent 91c5f2d commit 8a963ff
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aws/resource_aws_codestarconnections_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func resourceAwsCodeStarConnectionsConnection() *schema.Resource {
},

"provider_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(codestarconnections.ProviderType_Values(), false),
},
},
Expand Down
44 changes: 44 additions & 0 deletions aws/resource_aws_codestarconnections_connection_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"errors"
"fmt"
"regexp"
"testing"
Expand All @@ -24,6 +25,7 @@ func TestAccAWSCodeStarConnectionsConnection_Basic(t *testing.T) {
{
Config: testAccAWSCodeStarConnectionsConnectionConfigBasic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSCodeStarConnectionsConnectionExists(resourceName),
testAccMatchResourceAttrRegionalARN(resourceName, "id", "codestar-connections", regexp.MustCompile("connection/.+")),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "codestar-connections", regexp.MustCompile("connection/.+")),
resource.TestCheckResourceAttr(resourceName, "provider_type", codestarconnections.ProviderTypeBitbucket),
Expand All @@ -40,6 +42,48 @@ func TestAccAWSCodeStarConnectionsConnection_Basic(t *testing.T) {
})
}

func TestAccAWSCodeStarConnectionsConnection_disappears(t *testing.T) {
resourceName := "aws_codestarconnections_connection.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCodeStarConnectionsConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCodeStarConnectionsConnectionConfigBasic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSCodeStarConnectionsConnectionExists(resourceName),
testAccCheckResourceDisappears(testAccProvider, resourceAwsCodeStarConnectionsConnection(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckAWSCodeStarConnectionsConnectionExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return errors.New("No CodeStar connection ID is set")
}

conn := testAccProvider.Meta().(*AWSClient).codestarconnectionsconn

_, err := conn.GetConnection(&codestarconnections.GetConnectionInput{
ConnectionArn: aws.String(rs.Primary.ID),
})

return err
}
}

func testAccCheckAWSCodeStarConnectionsConnectionDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).codestarconnectionsconn

Expand Down

0 comments on commit 8a963ff

Please sign in to comment.