Skip to content

Commit

Permalink
Tidy up acceptance tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Aug 31, 2023
1 parent 3c70e2d commit 0266706
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 41 deletions.
39 changes: 0 additions & 39 deletions internal/service/efs/file_system_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/efs"
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"
)

Expand All @@ -28,7 +27,6 @@ func TestAccEFSFileSystemDataSource_id(t *testing.T) {
{
Config: testAccFileSystemDataSourceConfig_id,
Check: resource.ComposeTestCheckFunc(
testAccFileSystemCheckDataSource(dataSourceName, resourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "performance_mode", resourceName, "performance_mode"),
resource.TestCheckResourceAttrPair(dataSourceName, "creation_token", resourceName, "creation_token"),
Expand Down Expand Up @@ -60,7 +58,6 @@ func TestAccEFSFileSystemDataSource_tags(t *testing.T) {
{
Config: testAccFileSystemDataSourceConfig_tags,
Check: resource.ComposeTestCheckFunc(
testAccFileSystemCheckDataSource(dataSourceName, resourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "performance_mode", resourceName, "performance_mode"),
resource.TestCheckResourceAttrPair(dataSourceName, "creation_token", resourceName, "creation_token"),
Expand Down Expand Up @@ -92,7 +89,6 @@ func TestAccEFSFileSystemDataSource_name(t *testing.T) {
{
Config: testAccFileSystemDataSourceConfig_name,
Check: resource.ComposeTestCheckFunc(
testAccFileSystemCheckDataSource(dataSourceName, resourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "performance_mode", resourceName, "performance_mode"),
resource.TestCheckResourceAttrPair(dataSourceName, "creation_token", resourceName, "creation_token"),
Expand Down Expand Up @@ -123,7 +119,6 @@ func TestAccEFSFileSystemDataSource_availabilityZone(t *testing.T) {
{
Config: testAccFileSystemDataSourceConfig_availabilityZone,
Check: resource.ComposeTestCheckFunc(
testAccFileSystemCheckDataSource(dataSourceName, resourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone_id", resourceName, "availability_zone_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone_name", resourceName, "availability_zone_name"),
),
Expand Down Expand Up @@ -157,40 +152,6 @@ func TestAccEFSFileSystemDataSource_nonExistent_tags(t *testing.T) {
})
}

func testAccFileSystemCheckDataSource(dName, rName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[dName]
if !ok {
return fmt.Errorf("root module has no resource called %s", dName)
}

efsRs, ok := s.RootModule().Resources[rName]
if !ok {
return fmt.Errorf("can't find aws_efs_file_system.test in state")
}

attr := rs.Primary.Attributes

if attr["creation_token"] != efsRs.Primary.Attributes["creation_token"] {
return fmt.Errorf(
"creation_token is %s; want %s",
attr["creation_token"],
efsRs.Primary.Attributes["creation_token"],
)
}

if attr["id"] != efsRs.Primary.Attributes["id"] {
return fmt.Errorf(
"file_system_id is %s; want %s",
attr["id"],
efsRs.Primary.Attributes["id"],
)
}

return nil
}
}

func testAccFileSystemConfig_dataSourceBasic(rName string) string {
return fmt.Sprintf(`
resource "aws_efs_file_system" "test" {
Expand Down
11 changes: 9 additions & 2 deletions internal/service/efs/file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccEFSFileSystem_basic(t *testing.T) {
acctest.MatchResourceAttrRegionalHostname(resourceName, "dns_name", "efs", regexache.MustCompile(`fs-[^.]+`)),
resource.TestCheckResourceAttr(resourceName, "encrypted", "false"),
resource.TestCheckResourceAttr(resourceName, "lifecycle_policy.#", "0"),
acctest.MatchResourceAttrAccountID(resourceName, "name"),
resource.TestCheckResourceAttr(resourceName, "name", ""),
resource.TestCheckResourceAttr(resourceName, "number_of_mount_targets", "0"),
acctest.MatchResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "performance_mode", "generalPurpose"),
Expand Down Expand Up @@ -219,8 +219,11 @@ func TestAccEFSFileSystem_kmsKey(t *testing.T) {
Config: testAccFileSystemConfig_kmsKey(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckFileSystem(ctx, resourceName, &desc),
resource.TestCheckResourceAttrPair(resourceName, "kms_key_id", kmsKeyResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "encrypted", "true"),
resource.TestCheckResourceAttrPair(resourceName, "kms_key_id", kmsKeyResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.Name", rName),
),
},
{
Expand Down Expand Up @@ -572,6 +575,10 @@ resource "aws_kms_key" "test" {
resource "aws_efs_file_system" "test" {
encrypted = %[2]t
kms_key_id = aws_kms_key.test.arn
tags = {
Name = %[1]q
}
}
`, rName, enable)
}
Expand Down

0 comments on commit 0266706

Please sign in to comment.