Skip to content

Commit

Permalink
Confirm problem with computed disabled attribute
Browse files Browse the repository at this point in the history
References #1572
  • Loading branch information
sfc-gh-asawicki committed Aug 23, 2024
1 parent 73902f9 commit 1780916
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package resourceassert

import (
"strconv"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
)

func (u *UserResourceAssert) HasDisabled(expected bool) *UserResourceAssert {
u.AddAssertion(assert.ValueSet("disabled", strconv.FormatBool(expected)))
return u
}
8 changes: 8 additions & 0 deletions pkg/acceptance/helpers/user_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ func (c *UserClient) Show(t *testing.T, id sdk.AccountObjectIdentifier) (*sdk.Us

return c.client().ShowByID(ctx, id)
}

func (c *UserClient) Disable(t *testing.T, id sdk.AccountObjectIdentifier) {
t.Helper()
ctx := context.Background()

err := c.client().Alter(ctx, id, &sdk.AlterUserOptions{Set: &sdk.UserSet{ObjectProperties: &sdk.UserObjectProperties{Disable: sdk.Bool(true)}}})
require.NoError(t, err)
}
42 changes: 42 additions & 0 deletions pkg/resources/user_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,45 @@ func TestAcc_User_issue2970(t *testing.T) {
},
})
}

// TODO: will be fixed with addition of show_output, its logic, and changing disabled to non-computed attribute
func TestAcc_User_issue1572(t *testing.T) {
userId := acc.TestClient().Ids.RandomAccountObjectIdentifier()

userModel := model.UserWithDefaultMeta(userId.Name())

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
PreCheck: func() { acc.TestAccPreCheck(t) },
CheckDestroy: acc.CheckDestroy(t, resources.User),
Steps: []resource.TestStep{
{
Config: config.FromModel(t, userModel),
Check: assert.AssertThat(t,
resourceassert.UserResource(t, userModel.ResourceReference()).
HasDisabled(false),
),
},
{
PreConfig: func() {
acc.TestClient().User.Disable(t, userId)
objectassert.User(t, userId).HasDisabled(true)
},
Config: config.FromModel(t, userModel),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
planchecks.ExpectDrift(userModel.ResourceReference(), "disabled", sdk.String("false"), sdk.String("true")),
planchecks.ExpectChange(userModel.ResourceReference(), "disabled", tfjson.ActionUpdate, sdk.String("false"), sdk.String("true")),
},
},
Check: assert.AssertThat(t,
resourceassert.UserResource(t, userModel.ResourceReference()).
HasDisabled(false),
),
},
},
})
}

0 comments on commit 1780916

Please sign in to comment.