-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test alert datasource (basic) * Add more test cases * Fix bad config params combination * Fix database behavior * Add test for show by schema * Add test for empty in * Fix after review * Fix merge conflicts
- Loading branch information
1 parent
c1700de
commit 774a7db
Showing
16 changed files
with
378 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package datasources_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" | ||
) | ||
|
||
func TestAcc_Alerts(t *testing.T) { | ||
name := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
|
||
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: alertsResourceConfig(name) + alertsDatasourceConfigNoOptionals(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.snowflake_alerts.test_datasource_alert", "alerts.#"), | ||
), | ||
}, | ||
{ | ||
Config: alertsResourceConfig(name) + alertsDatasourceConfigDbOnly(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.snowflake_alerts.test_datasource_alert", "alerts.#"), | ||
), | ||
}, | ||
{ | ||
Config: alertsResourceConfig(name) + alertsDatasourceConfigDbAndSchema(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.snowflake_alerts.test_datasource_alert", "alerts.#"), | ||
resource.TestCheckResourceAttr("data.snowflake_alerts.test_datasource_alert", "alerts.0.name", name), | ||
), | ||
}, | ||
{ | ||
Config: alertsResourceConfig(name) + alertsDatasourceConfigAllOptionals(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.snowflake_alerts.test_datasource_alert", "alerts.#"), | ||
resource.TestCheckResourceAttr("data.snowflake_alerts.test_datasource_alert", "alerts.0.name", name), | ||
), | ||
}, | ||
{ | ||
Config: alertsResourceConfig(name) + alertsDatasourceConfigSchemaOnly(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.snowflake_alerts.test_datasource_alert", "alerts.#"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func alertsResourceConfig(name string) string { | ||
return fmt.Sprintf(` | ||
resource "snowflake_alert" "test_resource_alert" { | ||
name = "%s" | ||
database = "%s" | ||
schema = "%s" | ||
warehouse = "%s" | ||
condition = "select 0 as c" | ||
action = "select 0 as c" | ||
enabled = false | ||
comment = "some comment" | ||
alert_schedule { | ||
interval = "60" | ||
} | ||
} | ||
`, name, acc.TestDatabaseName, acc.TestSchemaName, acc.TestWarehouseName) | ||
} | ||
|
||
func alertsDatasourceConfigNoOptionals() string { | ||
return ` | ||
data "snowflake_alerts" "test_datasource_alert" {} | ||
` | ||
} | ||
|
||
func alertsDatasourceConfigDbOnly() string { | ||
return fmt.Sprintf(` | ||
data "snowflake_alerts" "test_datasource_alert" { | ||
database = "%s" | ||
} | ||
`, acc.TestDatabaseName) | ||
} | ||
|
||
func alertsDatasourceConfigDbAndSchema() string { | ||
return fmt.Sprintf(` | ||
data "snowflake_alerts" "test_datasource_alert" { | ||
database = "%s" | ||
schema = "%s" | ||
} | ||
`, acc.TestDatabaseName, acc.TestSchemaName) | ||
} | ||
|
||
func alertsDatasourceConfigAllOptionals(name string) string { | ||
return fmt.Sprintf(` | ||
data "snowflake_alerts" "test_datasource_alert" { | ||
database = "%s" | ||
schema = "%s" | ||
pattern = "%s" | ||
} | ||
`, acc.TestDatabaseName, acc.TestSchemaName, name) | ||
} | ||
|
||
func alertsDatasourceConfigSchemaOnly() string { | ||
return fmt.Sprintf(` | ||
data "snowflake_alerts" "test_datasource_alert" { | ||
schema = "%s" | ||
} | ||
`, acc.TestSchemaName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
pkg/datasources/testdata/TestAcc_DynamicTables_complete/1/test.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
|
||
|
||
resource "snowflake_table" "t" { | ||
database = var.database | ||
schema = var.schema | ||
|
36 changes: 36 additions & 0 deletions
36
pkg/datasources/testdata/TestAcc_DynamicTables_complete/2/test.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
resource "snowflake_table" "t" { | ||
database = var.database | ||
schema = var.schema | ||
name = var.table_name | ||
change_tracking = true | ||
column { | ||
name = "id" | ||
type = "NUMBER(38,0)" | ||
} | ||
} | ||
|
||
resource "snowflake_dynamic_table" "dt" { | ||
depends_on = [snowflake_table.t] | ||
name = var.name | ||
database = var.database | ||
schema = var.schema | ||
target_lag { | ||
maximum_duration = "2 minutes" | ||
} | ||
warehouse = var.warehouse | ||
query = var.query | ||
comment = var.comment | ||
} | ||
|
||
data "snowflake_dynamic_tables" "dts" { | ||
like { | ||
pattern = snowflake_dynamic_table.dt.name | ||
} | ||
in { | ||
schema = "\"${snowflake_dynamic_table.dt.database}\".\"${snowflake_dynamic_table.dt.schema}\"" | ||
} | ||
starts_with = snowflake_dynamic_table.dt.name | ||
limit { | ||
rows = 1 | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
pkg/datasources/testdata/TestAcc_DynamicTables_complete/2/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
|
||
variable "name" { | ||
type = string | ||
} | ||
|
||
variable "database" { | ||
type = string | ||
} | ||
|
||
variable "schema" { | ||
type = string | ||
} | ||
|
||
variable "warehouse" { | ||
type = string | ||
} | ||
|
||
variable "query" { | ||
type = string | ||
} | ||
|
||
variable "comment" { | ||
type = string | ||
} | ||
|
||
variable "table_name" { | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.