Skip to content

Commit

Permalink
Fix acceptance test for ForceNew.
Browse files Browse the repository at this point in the history
  • Loading branch information
korenyoni committed Oct 3, 2023
1 parent e06690b commit c212137
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions codefresh/resource_account_user_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func TestAccCodefreshAccountUserAssociation_Activation(t *testing.T) {
func TestAccCodefreshAccountUserAssociation_StatusPending_Email_ForceNew(t *testing.T) {
resourceName := "codefresh_account_user_association.test_user"

testUserEmail := testAccCodefreshAccountUserAssociationGenerateUserEmail()
testUserEmailBefore := testAccCodefreshAccountUserAssociationGenerateUserEmail()
testUserEmailAfter := testAccCodefreshAccountUserAssociationGenerateUserEmail()
var resourceId string
var err error

Expand All @@ -83,9 +84,9 @@ func TestAccCodefreshAccountUserAssociation_StatusPending_Email_ForceNew(t *test
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCodefreshAccountUserAssociationConfig(testUserEmail, true),
Config: testAccCodefreshAccountUserAssociationConfig(testUserEmailBefore, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "email", testUserEmail),
resource.TestCheckResourceAttr(resourceName, "email", testUserEmailBefore),
resource.TestCheckResourceAttr(resourceName, "admin", "true"),
resource.TestCheckResourceAttr(resourceName, "status", "pending"),
),
Expand All @@ -98,12 +99,9 @@ func TestAccCodefreshAccountUserAssociation_StatusPending_Email_ForceNew(t *test
},
},
{
PreConfig: func() {
testUserEmail = testAccCodefreshAccountUserAssociationGenerateUserEmail()
},
Config: testAccCodefreshAccountUserAssociationConfig(testUserEmail, true),
Config: testAccCodefreshAccountUserAssociationConfig(testUserEmailAfter, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "email", testUserEmail),
resource.TestCheckResourceAttr(resourceName, "email", testUserEmailAfter),
resource.TestCheckResourceAttr(resourceName, "admin", "true"),
resource.TestCheckResourceAttr(resourceName, "status", "pending"),
),
Expand All @@ -129,7 +127,8 @@ func TestAccCodefreshAccountUserAssociation_StatusPending_Email_ForceNew(t *test
func TestAccCodefreshAccountUserAssociation_StatusNew_Email_ForceNew(t *testing.T) {
resourceName := "codefresh_account_user_association.test_user"

testUserEmail := testAccCodefreshAccountUserAssociationGenerateUserEmail()
testUserEmailBefore := testAccCodefreshAccountUserAssociationGenerateUserEmail()
testUserEmailAfter := testAccCodefreshAccountUserAssociationGenerateUserEmail()
var resourceId string
var err error

Expand All @@ -138,9 +137,9 @@ func TestAccCodefreshAccountUserAssociation_StatusNew_Email_ForceNew(t *testing.
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCodefreshAccountUserAssociationConfig(testUserEmail, true),
Config: testAccCodefreshAccountUserAssociationConfig(testUserEmailBefore, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "email", testUserEmail),
resource.TestCheckResourceAttr(resourceName, "email", testUserEmailBefore),
resource.TestCheckResourceAttr(resourceName, "admin", "true"),
resource.TestCheckResourceAttr(resourceName, "status", "pending"),
),
Expand All @@ -155,19 +154,16 @@ func TestAccCodefreshAccountUserAssociation_StatusNew_Email_ForceNew(t *testing.
{
RefreshState: true,
Check: func(s *terraform.State) error {
return testAccCodefreshActivateUser(s, testUserEmail)
return testAccCodefreshActivateUser(s, testUserEmailBefore)
},
},
{
// Test that an email change on an activated user DOES force a new resource
PreConfig: func() {
testUserEmail = testAccCodefreshAccountUserAssociationGenerateUserEmail()
},
Config: testAccCodefreshAccountUserAssociationConfig(testUserEmail, true),
Config: testAccCodefreshAccountUserAssociationConfig(testUserEmailAfter, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "email", testUserEmail),
resource.TestCheckResourceAttr(resourceName, "email", testUserEmailAfter),
resource.TestCheckResourceAttr(resourceName, "admin", "true"),
resource.TestCheckResourceAttr(resourceName, "status", "new"),
resource.TestCheckResourceAttr(resourceName, "status", "pending"), // status should be pending because a new resource was forced
),
},
{
Expand Down

0 comments on commit c212137

Please sign in to comment.