Skip to content

Commit

Permalink
fix: cleanup acc tests (#2135)
Browse files Browse the repository at this point in the history
* update acc tests

* fix acc test

* fix fmt

* fix comments

* template database and schema names

* update acc

* fix error

* fix error

* fix error

* fix acc tests
  • Loading branch information
sfc-gh-swinkler authored Oct 24, 2023
1 parent 5c633be commit 5db751d
Show file tree
Hide file tree
Showing 54 changed files with 1,173 additions and 2,094 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAcc_AccountPasswordPolicyAttachment(t *testing.T) {
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: accountPasswordPolicyAttachmentConfig(prefix),
Config: accountPasswordPolicyAttachmentConfig(acc.TestDatabaseName, acc.TestSchemaName, prefix),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("snowflake_account_password_policy_attachment.att", "id"),
),
Expand All @@ -41,28 +41,17 @@ func TestAcc_AccountPasswordPolicyAttachment(t *testing.T) {
})
}

func accountPasswordPolicyAttachmentConfig(prefix string) string {
func accountPasswordPolicyAttachmentConfig(databaseName, schemaName, prefix string) string {
s := `
resource "snowflake_database" "test" {
name = "%v"
comment = "Terraform acceptance test"
}
resource "snowflake_schema" "test" {
name = "%v"
database = snowflake_database.test.name
comment = "Terraform acceptance test"
}
resource "snowflake_password_policy" "pa" {
database = snowflake_database.test.name
schema = snowflake_schema.test.name
database = "%s"
schema = "%s"
name = "%v"
}
resource "snowflake_account_password_policy_attachment" "att" {
password_policy = snowflake_password_policy.pa.qualified_name
}
`
return fmt.Sprintf(s, prefix, prefix, prefix)
return fmt.Sprintf(s, databaseName, schemaName, prefix)
}
47 changes: 19 additions & 28 deletions pkg/resources/alert_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,16 @@ type (

var (
warehouseName = "wh_" + strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
databaseName = "db_" + strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
schemaName = "PUBLIC"
alertName = "a_" + strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

alertInitialState = &AccAlertTestSettings{ //nolint
WarehouseName: warehouseName,
DatabaseName: databaseName,

DatabaseName: acc.TestDatabaseName,
Alert: &AlertSettings{
Name: alertName,
Schema: schemaName,
Condition: "select 0 as c",
Action: "select 0 as c",
Schema: acc.TestSchemaName,
Enabled: true,
Schedule: 5,
Comment: "dummy",
Expand All @@ -55,13 +52,12 @@ var (
// Changes: condition, action, comment, schedule.
alertStepOne = &AccAlertTestSettings{ //nolint
WarehouseName: warehouseName,
DatabaseName: databaseName,

DatabaseName: acc.TestDatabaseName,
Alert: &AlertSettings{
Name: alertName,
Schema: schemaName,
Condition: "select 1 as c",
Action: "select 1 as c",
Schema: acc.TestSchemaName,
Enabled: true,
Schedule: 15,
Comment: "test",
Expand All @@ -71,13 +67,12 @@ var (
// Changes: condition, action, comment, schedule.
alertStepTwo = &AccAlertTestSettings{ //nolint
WarehouseName: warehouseName,
DatabaseName: databaseName,

DatabaseName: acc.TestDatabaseName,
Alert: &AlertSettings{
Name: alertName,
Schema: schemaName,
Condition: "select 2 as c",
Action: "select 2 as c",
Schema: acc.TestSchemaName,
Enabled: true,
Schedule: 25,
Comment: "text",
Expand All @@ -87,13 +82,12 @@ var (
// Changes: condition, action, comment, schedule.
alertStepThree = &AccAlertTestSettings{ //nolint
WarehouseName: warehouseName,
DatabaseName: databaseName,

DatabaseName: acc.TestDatabaseName,
Alert: &AlertSettings{
Name: alertName,
Schema: schemaName,
Condition: "select 2 as c",
Action: "select 2 as c",
Schema: acc.TestSchemaName,
Enabled: false,
Schedule: 5,
},
Expand All @@ -111,8 +105,8 @@ func TestAcc_Alert(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
checkBool("snowflake_alert.test_alert", "enabled", alertInitialState.Alert.Enabled),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", alertName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", databaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", schemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", acc.TestSchemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "condition", alertInitialState.Alert.Condition),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "action", alertInitialState.Alert.Action),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "comment", alertInitialState.Alert.Comment),
Expand All @@ -124,8 +118,8 @@ func TestAcc_Alert(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
checkBool("snowflake_alert.test_alert", "enabled", alertStepOne.Alert.Enabled),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", alertName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", databaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", schemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", acc.TestSchemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "condition", alertStepOne.Alert.Condition),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "action", alertStepOne.Alert.Action),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "comment", alertStepOne.Alert.Comment),
Expand All @@ -137,8 +131,8 @@ func TestAcc_Alert(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
checkBool("snowflake_alert.test_alert", "enabled", alertStepTwo.Alert.Enabled),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", alertName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", databaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", schemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", acc.TestSchemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "condition", alertStepTwo.Alert.Condition),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "action", alertStepTwo.Alert.Action),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "comment", alertStepTwo.Alert.Comment),
Expand All @@ -150,8 +144,8 @@ func TestAcc_Alert(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
checkBool("snowflake_alert.test_alert", "enabled", alertStepThree.Alert.Enabled),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", alertName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", databaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", schemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", acc.TestSchemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "condition", alertStepThree.Alert.Condition),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "action", alertStepThree.Alert.Action),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "comment", alertStepThree.Alert.Comment),
Expand All @@ -163,8 +157,8 @@ func TestAcc_Alert(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
checkBool("snowflake_alert.test_alert", "enabled", alertInitialState.Alert.Enabled),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", alertName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", databaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", schemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "schema", acc.TestSchemaName),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "condition", alertInitialState.Alert.Condition),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "action", alertInitialState.Alert.Action),
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "comment", alertInitialState.Alert.Comment),
Expand All @@ -180,12 +174,9 @@ func alertConfig(settings *AccAlertTestSettings) string { //nolint
resource "snowflake_warehouse" "test_wh" {
name = "{{ .WarehouseName }}"
}
resource "snowflake_database" "test_db" {
name = "{{ .DatabaseName }}"
}
resource "snowflake_alert" "test_alert" {
name = "{{ .Alert.Name }}"
database = snowflake_database.test_db.name
database = "{{ .DatabaseName }}"
schema = "{{ .Alert.Schema }}"
warehouse = snowflake_warehouse.test_wh.name
alert_schedule {
Expand Down
14 changes: 5 additions & 9 deletions pkg/resources/database_grant_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func testRolesAndShares(t *testing.T, path string, roles []string) func(*terrafo
}

func TestAcc_DatabaseGrant(t *testing.T) {
dbName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
roleName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
shareName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

Expand All @@ -44,9 +43,9 @@ func TestAcc_DatabaseGrant(t *testing.T) {
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: databaseGrantConfig(dbName, roleName, shareName),
Config: databaseGrantConfig(roleName, shareName, acc.TestDatabaseName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_database_grant.test", "database_name", dbName),
resource.TestCheckResourceAttr("snowflake_database_grant.test", "database_name", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_database_grant.test", "privilege", "USAGE"),
resource.TestCheckResourceAttr("snowflake_database_grant.test", "roles.#", "1"),
resource.TestCheckResourceAttr("snowflake_database_grant.test", "shares.#", "1"),
Expand Down Expand Up @@ -100,11 +99,8 @@ func TestAcc_DatabaseGrant(t *testing.T) {
// })
// }

func databaseGrantConfig(db, role, share string) string {
func databaseGrantConfig(role, share, databaseName string) string {
return fmt.Sprintf(`
resource "snowflake_database" "test" {
name = "%v"
}
resource "snowflake_role" "test" {
name = "%v"
}
Expand All @@ -114,9 +110,9 @@ resource "snowflake_share" "test" {
}
resource "snowflake_database_grant" "test" {
database_name = snowflake_database.test.name
database_name = "%s"
roles = [snowflake_role.test.name]
shares = [snowflake_share.test.name]
}
`, db, role, share)
`, role, share, databaseName)
}
19 changes: 7 additions & 12 deletions pkg/resources/database_role_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

var (
resourceName = "snowflake_database_role.test_db_role"
dbName = "db_" + strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
dbRoleName = "db_role_" + strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
comment = "dummy"
comment2 = "test comment"
Expand All @@ -25,36 +24,32 @@ func TestAcc_DatabaseRole(t *testing.T) {
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: databaseRoleConfig(dbName, dbRoleName, comment),
Config: databaseRoleConfig(dbRoleName, acc.TestDatabaseName, comment),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", dbRoleName),
resource.TestCheckResourceAttr(resourceName, "database", dbName),
resource.TestCheckResourceAttr(resourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(resourceName, "comment", comment),
),
},
{
Config: databaseRoleConfig(dbName, dbRoleName, comment2),
Config: databaseRoleConfig(dbRoleName, acc.TestDatabaseName, comment2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", dbRoleName),
resource.TestCheckResourceAttr(resourceName, "database", dbName),
resource.TestCheckResourceAttr(resourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(resourceName, "comment", comment2),
),
},
},
})
}

func databaseRoleConfig(dbName string, dbRoleName string, comment string) string {
func databaseRoleConfig(dbRoleName string, databaseName string, comment string) string {
s := `
resource "snowflake_database" "test_db" {
name = "%s"
}
resource "snowflake_database_role" "test_db_role" {
name = "%s"
database = snowflake_database.test_db.name
database = "%s"
comment = "%s"
}
`
return fmt.Sprintf(s, dbName, dbRoleName, comment)
return fmt.Sprintf(s, dbRoleName, databaseName, comment)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
)

func TestAcc_EmailNotificationIntegration(t *testing.T) {
emailIntegrationName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
if _, ok := os.LookupEnv("SKIP_EMAIL_INTEGRATION_TESTS"); ok {
env := os.Getenv("SKIP_EMAIL_INTEGRATION_TESTS")
if env != "" {
t.Skip("Skipping TestAcc_EmailNotificationIntegration")
}

emailIntegrationName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
resource.Test(t, resource.TestCase{
Providers: acc.TestAccProviders(),
PreCheck: func() { acc.TestAccPreCheck(t) },
Expand Down
25 changes: 7 additions & 18 deletions pkg/resources/external_stage_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,26 @@ func TestAcc_ExternalStage(t *testing.T) {
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: externalStageConfig(accName),
Config: externalStageConfig(accName, acc.TestDatabaseName, acc.TestSchemaName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_stage.test", "name", accName),
resource.TestCheckResourceAttr("snowflake_stage.test", "database", accName),
resource.TestCheckResourceAttr("snowflake_stage.test", "schema", accName),
resource.TestCheckResourceAttr("snowflake_stage.test", "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr("snowflake_stage.test", "schema", acc.TestSchemaName),
resource.TestCheckResourceAttr("snowflake_stage.test", "comment", "Terraform acceptance test"),
),
},
},
})
}

func externalStageConfig(n string) string {
func externalStageConfig(n, databaseName, schemaName string) string {
return fmt.Sprintf(`
resource "snowflake_database" "test" {
name = "%v"
comment = "Terraform acceptance test"
}
resource "snowflake_schema" "test" {
name = "%v"
database = snowflake_database.test.name
comment = "Terraform acceptance test"
}
resource "snowflake_stage" "test" {
name = "%v"
url = "s3://com.example.bucket/prefix"
database = snowflake_database.test.name
schema = snowflake_schema.test.name
database = "%s"
schema = "%s"
comment = "Terraform acceptance test"
}
`, n, n, n)
`, n, databaseName, schemaName)
}
Loading

0 comments on commit 5db751d

Please sign in to comment.