Skip to content

Commit

Permalink
chore: Add tests to 3117 and bump build time (#3133)
Browse files Browse the repository at this point in the history
- Document two tests for #3117
- Bump acceptance tests build time
  • Loading branch information
sfc-gh-asawicki authored Oct 15, 2024
1 parent 561f78e commit ca90fde
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test: test-client ## run unit and integration tests
go test -v -cover -timeout=45m ./...

test-acceptance: ## run acceptance tests
TF_ACC=1 SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE=true TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestAcc_" -v -cover -timeout=90m ./...
TF_ACC=1 SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE=true TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestAcc_" -v -cover -timeout=120m ./...

test-integration: ## run SDK integration tests
TEST_SF_TF_REQUIRE_TEST_OBJECT_SUFFIX=1 go test -run "^TestInt_" -v -cover -timeout=45m ./...
Expand Down
8 changes: 8 additions & 0 deletions pkg/acceptance/helpers/database_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,11 @@ func (c *DatabaseClient) ShowAllReplicationDatabases(t *testing.T) ([]sdk.Replic

return c.context.client.ReplicationFunctions.ShowReplicationDatabases(ctx, nil)
}

func (c *DatabaseClient) Alter(t *testing.T, id sdk.AccountObjectIdentifier, opts *sdk.AlterDatabaseOptions) {
t.Helper()
ctx := context.Background()

err := c.client().Alter(ctx, id, opts)
require.NoError(t, err)
}
8 changes: 8 additions & 0 deletions pkg/acceptance/helpers/schema_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,11 @@ func (c *SchemaClient) ShowWithOptions(t *testing.T, opts *sdk.ShowSchemaOptions
require.NoError(t, err)
return schemas
}

func (c *SchemaClient) Alter(t *testing.T, id sdk.DatabaseObjectIdentifier, opts *sdk.AlterSchemaOptions) {
t.Helper()
ctx := context.Background()

err := c.client().Alter(ctx, id, opts)
require.NoError(t, err)
}
80 changes: 75 additions & 5 deletions pkg/resources/alert_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

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

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testenvs"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -222,14 +223,14 @@ func TestAcc_Alert_Issue3117(t *testing.T) {
Source: "Snowflake-Labs/snowflake",
},
},
Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId()),
Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId(), "test_alert"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", id.Name()),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId()),
Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId(), "test_alert"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", id.Name()),
),
Expand All @@ -238,9 +239,78 @@ func TestAcc_Alert_Issue3117(t *testing.T) {
})
}

func alertIssue3117Config(alertId sdk.SchemaObjectIdentifier, warehouseId sdk.AccountObjectIdentifier) string {
// Can't reproduce the issue, leaving the test for now.
func TestAcc_Alert_Issue3117_PatternMatching(t *testing.T) {
suffix := acc.TestClient().Ids.Alpha()
id1 := acc.TestClient().Ids.NewSchemaObjectIdentifier("prefix1" + suffix)
id2 := acc.TestClient().Ids.NewSchemaObjectIdentifier("prefix_" + suffix)

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: acc.CheckDestroy(t, resources.Alert),
Steps: []resource.TestStep{
{
Config: alertIssue3117Config(id1, acc.TestClient().Ids.WarehouseId(), "test_alert_1"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_alert.test_alert_1", "name", id1.Name()),
),
},
{
Config: alertIssue3117Config(id1, acc.TestClient().Ids.WarehouseId(), "test_alert_1") + alertIssue3117Config(id2, acc.TestClient().Ids.WarehouseId(), "test_alert_2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_alert.test_alert_1", "name", id1.Name()),
resource.TestCheckResourceAttr("snowflake_alert.test_alert_2", "name", id2.Name()),
),
},
},
})
}

// Can't reproduce the issue, leaving the test for now.
func TestAcc_Alert_Issue3117_IgnoreQuotedIdentifierCase(t *testing.T) {
_ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance)
acc.TestAccPreCheck(t)

database, databaseCleanup := acc.TestClient().Database.CreateDatabase(t)
t.Cleanup(databaseCleanup)

schema, schemaCleanup := acc.TestClient().Schema.CreateSchemaInDatabase(t, database.ID())
t.Cleanup(schemaCleanup)

id := acc.TestClient().Ids.NewSchemaObjectIdentifierInSchema("small_"+acc.TestClient().Ids.Alpha(), schema.ID())

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: acc.CheckDestroy(t, resources.Alert),
Steps: []resource.TestStep{
{
PreConfig: func() {
acc.TestClient().Database.Alter(t, database.ID(), &sdk.AlterDatabaseOptions{
Set: &sdk.DatabaseSet{
QuotedIdentifiersIgnoreCase: sdk.Bool(true),
},
})
},
Config: alertIssue3117Config(id, acc.TestClient().Ids.WarehouseId(), "test_alert"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_alert.test_alert", "name", id.Name()),
),
},
},
})
}

func alertIssue3117Config(alertId sdk.SchemaObjectIdentifier, warehouseId sdk.AccountObjectIdentifier, resourceName string) string {
return fmt.Sprintf(`
resource "snowflake_alert" "test_alert" {
resource "snowflake_alert" "%[5]s" {
database = "%[1]s"
schema = "%[2]s"
name = "%[3]s"
Expand All @@ -256,5 +326,5 @@ resource "snowflake_alert" "test_alert" {
enabled = true
comment = "Alert config for GH issue 3117"
}
`, alertId.DatabaseName(), alertId.SchemaName(), alertId.Name(), warehouseId.Name())
`, alertId.DatabaseName(), alertId.SchemaName(), alertId.Name(), warehouseId.Name(), resourceName)
}

0 comments on commit ca90fde

Please sign in to comment.