Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix few tests #2515

Merged
merged 6 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ provider "snowflake" {
account = "..." # required if not using profile. Can also be set via SNOWFLAKE_ACCOUNT env var
username = "..." # required if not using profile or token. Can also be set via SNOWFLAKE_USER env var
password = "..."
authenticator = "..." # required if not using password as auth method
oauth_access_token = "..."
private_key_path = "..."
private_key = "..."
Expand Down
1 change: 1 addition & 0 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ provider "snowflake" {
account = "..." # required if not using profile. Can also be set via SNOWFLAKE_ACCOUNT env var
username = "..." # required if not using profile or token. Can also be set via SNOWFLAKE_USER env var
password = "..."
authenticator = "..." # required if not using password as auth method
oauth_access_token = "..."
private_key_path = "..."
private_key = "..."
Expand Down
7 changes: 4 additions & 3 deletions pkg/resources/grant_database_role_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func TestAcc_GrantDatabaseRole_databaseRole(t *testing.T) {
}

func TestAcc_GrantDatabaseRole_issue2402(t *testing.T) {
databaseName := "DB_TEST_DB_DEV"
databaseRoleName := "TEST_DATABASE_ROLE_02"
parentDatabaseRoleName := "TEST_DATABASE_ROLE_01"
databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
databaseRoleName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
parentDatabaseRoleName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
resourceName := "snowflake_grant_database_role.g"
m := func() map[string]config.Variable {
return map[string]config.Variable{
Expand All @@ -69,6 +69,7 @@ func TestAcc_GrantDatabaseRole_issue2402(t *testing.T) {
"parent_database_role_name": config.StringVariable(parentDatabaseRoleName),
}
}

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
Expand Down
65 changes: 35 additions & 30 deletions pkg/resources/resource_monitor_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ import (
"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"
"github.com/stretchr/testify/require"
)

func TestAcc_ResourceMonitor(t *testing.T) {
// TODO test more attributes
name := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

resource.ParallelTest(t, resource.TestCase{
Providers: acc.TestAccProviders(),
PreCheck: func() { acc.TestAccPreCheck(t) },
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: resourceMonitorConfig(name),
Config: resourceMonitorConfig(name, acc.TestWarehouseName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_resource_monitor.test", "name", name),
resource.TestCheckResourceAttr("snowflake_resource_monitor.test", "credit_quota", "100"),
Expand Down Expand Up @@ -71,9 +76,12 @@ func TestAcc_ResourceMonitor(t *testing.T) {
func TestAcc_ResourceMonitorChangeStartEndTimestamp(t *testing.T) {
name := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

resource.ParallelTest(t, resource.TestCase{
Providers: acc.TestAccProviders(),
PreCheck: func() { acc.TestAccPreCheck(t) },
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -165,9 +173,12 @@ func TestAcc_ResourceMonitorUpdateNotifyUsers(t *testing.T) {
if err != nil {
t.Error(err)
}
resource.ParallelTest(t, resource.TestCase{
Providers: acc.TestAccProviders(),
PreCheck: func() { acc.TestAccPreCheck(t) },
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Expand All @@ -190,34 +201,22 @@ func TestAcc_ResourceMonitorUpdateNotifyUsers(t *testing.T) {
})
}

func resourceMonitorConfig(accName string) string {
func resourceMonitorConfig(accName string, warehouse string) string {
return fmt.Sprintf(`
resource "snowflake_warehouse" "warehouse" {
name = "test"
comment = "foo"
warehouse_size = "SMALL"
}

resource "snowflake_resource_monitor" "test" {
name = "%v"
credit_quota = 100
set_for_account = false
notify_triggers = [40]
suspend_trigger = 80
suspend_immediate_trigger = 90
warehouses = [snowflake_warehouse.warehouse.id]
warehouses = ["%s"]
}
`, accName)
`, accName, warehouse)
}

func resourceMonitorConfig2(accName string, suspendTrigger int) string {
return fmt.Sprintf(`
resource "snowflake_warehouse" "warehouse" {
name = "test"
comment = "foo"
warehouse_size = "SMALL"
}

resource "snowflake_resource_monitor" "test" {
name = "%v"
credit_quota = 150
Expand All @@ -241,8 +240,11 @@ func TestAcc_ResourceMonitor_issue2167(t *testing.T) {
require.NoError(t, err)

resource.Test(t, resource.TestCase{
Providers: acc.TestAccProviders(),
PreCheck: func() { acc.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -277,9 +279,12 @@ func TestAcc_ResourceMonitorNotifyUsers(t *testing.T) {
for _, s := range users {
checks = append(checks, resource.TestCheckTypeSetElemAttr("snowflake_resource_monitor.test", "notify_users.*", s))
}
resource.ParallelTest(t, resource.TestCase{
Providers: acc.TestAccProviders(),
PreCheck: func() { acc.TestAccPreCheck(t) },
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func CreateStage(ctx context.Context, d *schema.ResourceData, meta any) diag.Dia
q := builder.Create()

if err := snowflake.Exec(db, q); err != nil {
return diag.Errorf("error creating stage %v", name)
return diag.Errorf("error creating stage %v, err: %v", name, err)
}

d.SetId(helpers.EncodeSnowflakeID(database, schema, name))
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func UpdateTask(d *schema.ResourceData, meta interface{}) error {
if d.HasChange("after") {
// making changes to after require suspending the current task
if err := suspendTask(ctx, client, taskId); err != nil {
return fmt.Errorf("error suspending task %s", taskId.FullyQualifiedName())
return fmt.Errorf("error suspending task %s, err: %w", taskId.FullyQualifiedName(), err)
}

o, n := d.GetChange("after")
Expand Down
34 changes: 16 additions & 18 deletions pkg/resources/task_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,51 +600,49 @@ func TestAcc_Task_SwitchScheduled(t *testing.T) {
}

func taskConfigManagedScheduled(name string, taskRootName string, databaseName string, schemaName string) string {
s := `
return fmt.Sprintf(`
resource "snowflake_task" "test_task_root" {
name = "%s"
database = "%s"
schema = "%s"
name = "%[1]s"
database = "%[2]s"
schema = "%[3]s"
sql_statement = "SELECT 1"
enabled = true
schedule = "5 MINUTE"
suspend_task_after_num_failures = 1
}

resource "snowflake_task" "test_task" {
name = "%s"
database = "%s"
schema = "%s"
name = "%[4]s"
database = "%[2]s"
schema = "%[3]s"
sql_statement = "SELECT 1"
enabled = true
schedule = "5 MINUTE"
}
`
return fmt.Sprintf(s, taskRootName, databaseName, schemaName, name, databaseName, schemaName)
`, taskRootName, databaseName, schemaName, name)
}

func taskConfigManagedScheduled2(name string, taskRootName string, databaseName string, schemaName string) string {
s := `
return fmt.Sprintf(`
resource "snowflake_task" "test_task_root" {
name = "%s"
database = "%s"
schema = "%s"
name = "%[1]s"
database = "%[2]s"
schema = "%[3]s"
sql_statement = "SELECT 1"
enabled = true
schedule = "5 MINUTE"
suspend_task_after_num_failures = 2
}

resource "snowflake_task" "test_task" {
name = "%s"
database = "%s"
schema = "%s"
name = "%[4]s"
database = "%[2]s"
schema = "%[3]s"
sql_statement = "SELECT 1"
enabled = true
after = [snowflake_task.test_task_root.name]
}
`
return fmt.Sprintf(s, taskRootName, databaseName, schemaName, name, databaseName, schemaName)
`, taskRootName, databaseName, schemaName, name)
}

func taskConfigManagedScheduled3(name string, taskRootName string, databaseName string, schemaName string) string {
Expand Down
Loading