Skip to content

Commit

Permalink
r/aws_backup_plan: Tidy up acceptance tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Jan 30, 2024
1 parent 06d7d0e commit 21b39f9
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions internal/service/backup/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"testing"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/backup"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfbackup "github.com/hashicorp/terraform-provider-aws/internal/service/backup"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func TestAccBackupPlan_basic(t *testing.T) {
Expand Down Expand Up @@ -682,43 +682,39 @@ func testAccCheckPlanDestroy(ctx context.Context) resource.TestCheckFunc {
continue
}

input := &backup.GetBackupPlanInput{
BackupPlanId: aws.String(rs.Primary.ID),
}
_, err := tfbackup.FindPlanByID(ctx, conn, rs.Primary.ID)

resp, err := conn.GetBackupPlanWithContext(ctx, input)
if tfresource.NotFound(err) {
continue
}

if err == nil {
if *resp.BackupPlanId == rs.Primary.ID {
return fmt.Errorf("Plane '%s' was not deleted properly", rs.Primary.ID)
}
if err != nil {
return err
}

return fmt.Errorf("Backup Plan %s still exists", rs.Primary.ID)
}

return nil
}
}

func testAccCheckPlanExists(ctx context.Context, name string, plan *backup.GetBackupPlanOutput) resource.TestCheckFunc {
func testAccCheckPlanExists(ctx context.Context, n string, v *backup.GetBackupPlanOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).BackupConn(ctx)

rs, ok := s.RootModule().Resources[name]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", name)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
return fmt.Errorf("Not found: %s", n)
}

output, err := conn.GetBackupPlanWithContext(ctx, &backup.GetBackupPlanInput{
BackupPlanId: aws.String(rs.Primary.ID),
})
output, err := tfbackup.FindPlanByID(ctx, conn, rs.Primary.ID)

if err != nil {
return err
}

*plan = *output
*v = *output

return nil
}
Expand Down

0 comments on commit 21b39f9

Please sign in to comment.