From ed7222791199da7bc11c7d1e105baff14af05669 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 19 Jul 2023 19:36:53 -0500 Subject: [PATCH] aws_lightsail_key_pair: add disappears test --- internal/service/lightsail/key_pair_test.go | 58 +++++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/internal/service/lightsail/key_pair_test.go b/internal/service/lightsail/key_pair_test.go index 4fa0756662c..268bcd66022 100644 --- a/internal/service/lightsail/key_pair_test.go +++ b/internal/service/lightsail/key_pair_test.go @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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]