From d639e9dd15017316c3afc2f26ff3e79ee15bcc83 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Mon, 11 May 2020 15:28:31 -0700 Subject: [PATCH 1/2] Updates IOT acceptance tests to use ARN testing check functions Addresses: aws/resource_aws_iot_role_alias_test.go:65:6: AWSAT001: prefer resource.TestCheckResourceAttrPair() or ARN check functions (e.g. testAccMatchResourceAttrRegionalARN) --- aws/resource_aws_iot_role_alias_test.go | 35 ++++++++++++------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/aws/resource_aws_iot_role_alias_test.go b/aws/resource_aws_iot_role_alias_test.go index 087574c660f..ea321d97fa9 100644 --- a/aws/resource_aws_iot_role_alias_test.go +++ b/aws/resource_aws_iot_role_alias_test.go @@ -15,6 +15,9 @@ func TestAccAWSIotRoleAlias_basic(t *testing.T) { alias := acctest.RandomWithPrefix("RoleAlias-") alias2 := acctest.RandomWithPrefix("RoleAlias2-") + resourceName := "aws_iot_role_alias.ra" + resourceName2 := "aws_iot_role_alias.ra2" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -23,51 +26,47 @@ func TestAccAWSIotRoleAlias_basic(t *testing.T) { { Config: testAccAWSIotRoleAliasConfig(alias), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSIotRoleAliasExists("aws_iot_role_alias.ra"), - testAccCheckResourceAttrRegionalARN("aws_iot_role_alias.ra", "arn", "iot", fmt.Sprintf("rolealias/%s", alias)), - resource.TestCheckResourceAttr( - "aws_iot_role_alias.ra", "credential_duration", "3600"), + testAccCheckAWSIotRoleAliasExists(resourceName), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "iot", fmt.Sprintf("rolealias/%s", alias)), + resource.TestCheckResourceAttr(resourceName, "credential_duration", "3600"), ), }, { Config: testAccAWSIotRoleAliasConfigUpdate1(alias, alias2), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSIotRoleAliasExists("aws_iot_role_alias.ra"), - testAccCheckAWSIotRoleAliasExists("aws_iot_role_alias.ra2"), - testAccCheckResourceAttrRegionalARN("aws_iot_role_alias.ra", "arn", "iot", fmt.Sprintf("rolealias/%s", alias)), - resource.TestCheckResourceAttr( - "aws_iot_role_alias.ra", "credential_duration", "1800"), + testAccCheckAWSIotRoleAliasExists(resourceName), + testAccCheckAWSIotRoleAliasExists(resourceName2), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "iot", fmt.Sprintf("rolealias/%s", alias)), + resource.TestCheckResourceAttr(resourceName, "credential_duration", "1800"), ), }, { Config: testAccAWSIotRoleAliasConfigUpdate2(alias2), - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSIotRoleAliasExists("aws_iot_role_alias.ra2"), - ), + Check: resource.ComposeTestCheckFunc(testAccCheckAWSIotRoleAliasExists(resourceName2)), }, { Config: testAccAWSIotRoleAliasConfigUpdate3(alias2), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSIotRoleAliasExists("aws_iot_role_alias.ra2"), + testAccCheckAWSIotRoleAliasExists(resourceName2), ), ExpectError: regexp.MustCompile("Role alias .+? already exists for this account"), }, { Config: testAccAWSIotRoleAliasConfigUpdate4(alias2), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSIotRoleAliasExists("aws_iot_role_alias.ra2"), + testAccCheckAWSIotRoleAliasExists(resourceName2), ), }, { Config: testAccAWSIotRoleAliasConfigUpdate5(alias2), Check: resource.ComposeTestCheckFunc( - testAccCheckAWSIotRoleAliasExists("aws_iot_role_alias.ra2"), - resource.TestMatchResourceAttr( - "aws_iot_role_alias.ra2", "role_arn", regexp.MustCompile(".+?bogus")), + testAccCheckAWSIotRoleAliasExists(resourceName2), + resource.TestMatchResourceAttr(resourceName2, "role_arn", regexp.MustCompile(".+?bogus")), + testAccMatchResourceAttrGlobalARN(resourceName2, "role_arn", "iam", regexp.MustCompile("role/rolebogus")), ), }, { - ResourceName: "aws_iot_role_alias.ra2", + ResourceName: resourceName2, ImportState: true, ImportStateVerify: true, }, From 1fcf2305ce7ae512cce9998b8e1c369f19524651 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Tue, 26 May 2020 15:55:55 -0700 Subject: [PATCH 2/2] Removes missed test --- aws/resource_aws_iot_role_alias_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/aws/resource_aws_iot_role_alias_test.go b/aws/resource_aws_iot_role_alias_test.go index ea321d97fa9..ff5b70c6b6f 100644 --- a/aws/resource_aws_iot_role_alias_test.go +++ b/aws/resource_aws_iot_role_alias_test.go @@ -61,7 +61,6 @@ func TestAccAWSIotRoleAlias_basic(t *testing.T) { Config: testAccAWSIotRoleAliasConfigUpdate5(alias2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSIotRoleAliasExists(resourceName2), - resource.TestMatchResourceAttr(resourceName2, "role_arn", regexp.MustCompile(".+?bogus")), testAccMatchResourceAttrGlobalARN(resourceName2, "role_arn", "iam", regexp.MustCompile("role/rolebogus")), ), },