Skip to content

Commit

Permalink
Refactor test user setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cmonty-paypal committed Apr 10, 2024
1 parent 68544d4 commit a0d8595
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 0 additions & 8 deletions pkg/acceptance/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const (
TestSchemaName = "terraform_test_schema"
TestWarehouseName = "terraform_test_warehouse"
TestWarehouseName2 = "terraform_test_warehouse_2"
TestUserName = "terraform_test_user"
)

var (
Expand Down Expand Up @@ -121,13 +120,6 @@ func TestAccPreCheck(t *testing.T) {
}); err != nil {
t.Fatal(err)
}

userId := sdk.NewAccountObjectIdentifier(TestUserName)
if err := atc.client.Users.Create(ctx, userId, &sdk.CreateUserOptions{
IfNotExists: sdk.Bool(true),
}); err != nil {
t.Fatal(err)
}
})
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/resources/object_parameter_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package resources_test

import (
"fmt"
"strings"
"testing"

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)
Expand Down Expand Up @@ -53,6 +55,7 @@ func TestAcc_ObjectParameterAccount(t *testing.T) {
}

func TestAcc_UserParameter(t *testing.T) {
userName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
Expand All @@ -62,7 +65,7 @@ func TestAcc_UserParameter(t *testing.T) {
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: userParameterConfigBasic("ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR", "true", acc.TestUserName),
Config: userParameterConfigBasic(userName, "ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR", "true"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_object_parameter.p", "key", "ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR"),
resource.TestCheckResourceAttr("snowflake_object_parameter.p", "value", "true"),
Expand Down Expand Up @@ -98,16 +101,19 @@ resource "snowflake_object_parameter" "p" {
return fmt.Sprintf(s, key, value, databaseName)
}

func userParameterConfigBasic(key, value, username string) string {
func userParameterConfigBasic(userName string, key string, value string) string {
s := `
resource "snowflake_user" "user" {
name = "%s"
}
resource "snowflake_object_parameter" "p" {
key = "%s"
value = "%s"
object_type = "USER"
object_identifier {
name = "%s"
name = snowflake_user.user.name
}
}
`
return fmt.Sprintf(s, key, value, username)
return fmt.Sprintf(s, userName, key, value)
}

0 comments on commit a0d8595

Please sign in to comment.