Skip to content

Commit

Permalink
aws_lightsail_key_pair: add disappears test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonaj committed Jul 20, 2023
1 parent 643408f commit ed72227
Showing 1 changed file with 53 additions and 5 deletions.
58 changes: 53 additions & 5 deletions internal/service/lightsail/key_pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func TestAccLightsailKeyPair_basic(t *testing.T) {
resourceName := "aws_lightsail_key_pair.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, strings.ToLower(lightsail.ServiceID))
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(lightsail.ServiceID)),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckKeyPairDestroy(ctx),
Expand Down Expand Up @@ -58,7 +62,11 @@ func TestAccLightsailKeyPair_publicKey(t *testing.T) {
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, strings.ToLower(lightsail.ServiceID))
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(lightsail.ServiceID)),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckKeyPairDestroy(ctx),
Expand Down Expand Up @@ -86,7 +94,11 @@ func TestAccLightsailKeyPair_encrypted(t *testing.T) {
resourceName := "aws_lightsail_key_pair.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, strings.ToLower(lightsail.ServiceID))
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(lightsail.ServiceID)),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckKeyPairDestroy(ctx),
Expand All @@ -110,7 +122,11 @@ func TestAccLightsailKeyPair_encrypted(t *testing.T) {
func TestAccLightsailKeyPair_namePrefix(t *testing.T) {
ctx := acctest.Context(t)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, strings.ToLower(lightsail.ServiceID))
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(lightsail.ServiceID)),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckKeyPairDestroy(ctx),
Expand All @@ -135,7 +151,11 @@ func TestAccLightsailKeyPair_tags(t *testing.T) {
resourceName := "aws_lightsail_key_pair.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, strings.ToLower(lightsail.ServiceID))
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(lightsail.ServiceID)),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckKeyPairDestroy(ctx),
Expand Down Expand Up @@ -169,6 +189,34 @@ func TestAccLightsailKeyPair_tags(t *testing.T) {
})
}

func TestAccLightsailKeyPair_disappears(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resourceName := "aws_lightsail_key_pair.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, strings.ToLower(lightsail.ServiceID))
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(lightsail.ServiceID)),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckKeyPairDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccKeyPairConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKeyPairExists(ctx, resourceName),
acctest.CheckResourceDisappears(ctx, acctest.Provider, tflightsail.ResourceKeyPair(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckKeyPairExists(ctx context.Context, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down

0 comments on commit ed72227

Please sign in to comment.