Skip to content

Commit

Permalink
Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Aug 28, 2024
1 parent b702a21 commit f22630f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
6 changes: 3 additions & 3 deletions pkg/resources/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ func DataTypeIssue3007DiffSuppressFunc(_, old, new string, _ *schema.ResourceDat
}
switch v := oldDataType; v {
case sdk.DataTypeNumber:
logging.DebugLogger.Printf("[DEBUG] Handling number data type diff suppression")
logging.DebugLogger.Printf("[DEBUG] DataTypeIssue3007DiffSuppressFunc: Handling number data type diff suppression")
oldPrecision, oldScale := sdk.ParseNumberDataTypeRaw(old)
newPrecision, newScale := sdk.ParseNumberDataTypeRaw(new)
return oldPrecision == newPrecision && oldScale == newScale
case sdk.DataTypeVARCHAR:
logging.DebugLogger.Printf("[DEBUG] Handling text data type diff suppression")
logging.DebugLogger.Printf("[DEBUG] DataTypeIssue3007DiffSuppressFunc: Handling text data type diff suppression")
oldLength := sdk.ParseVarcharDataTypeRaw(old)
newLength := sdk.ParseVarcharDataTypeRaw(new)
return oldLength == newLength
default:
logging.DebugLogger.Printf("[DEBUG] Diff suppression for %s can't be currently handled", v)
logging.DebugLogger.Printf("[DEBUG] DataTypeIssue3007DiffSuppressFunc: Diff suppression for %s can't be currently handled", v)
}
return true
}
Expand Down
43 changes: 14 additions & 29 deletions pkg/resources/table_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2094,9 +2094,7 @@ resource "snowflake_table" "test_table" {
}

func TestAcc_Table_issue3007_textColumn(t *testing.T) {
databaseName := acc.TestClient().Ids.Alpha()
schemaName := acc.TestClient().Ids.Alpha()
name := acc.TestClient().Ids.Alpha()
tableId := acc.TestClient().Ids.RandomSchemaObjectIdentifier()
resourceName := "snowflake_table.test_table"

defaultVarchar := fmt.Sprintf("VARCHAR(%d)", sdk.DefaultVarcharLength)
Expand All @@ -2109,15 +2107,15 @@ func TestAcc_Table_issue3007_textColumn(t *testing.T) {
Steps: []resource.TestStep{
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, "VARCHAR(3)"),
Config: tableConfigIssue3007(tableId, "VARCHAR(3)"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "column.0.type", "NUMBER(11,2)"),
resource.TestCheckResourceAttr(resourceName, "column.1.type", "VARCHAR(3)"),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, "VARCHAR(256)"),
Config: tableConfigIssue3007(tableId, "VARCHAR(256)"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
planchecks.ExpectChange(resourceName, "column.1.type", tfjson.ActionUpdate, sdk.String("VARCHAR(3)"), sdk.String("VARCHAR(256)")),
Expand All @@ -2129,7 +2127,7 @@ func TestAcc_Table_issue3007_textColumn(t *testing.T) {
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, "VARCHAR"),
Config: tableConfigIssue3007(tableId, "VARCHAR"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
planchecks.ExpectChange(resourceName, "column.1.type", tfjson.ActionUpdate, sdk.String("VARCHAR(256)"), sdk.String("VARCHAR")),
Expand All @@ -2141,7 +2139,7 @@ func TestAcc_Table_issue3007_textColumn(t *testing.T) {
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, defaultVarchar),
Config: tableConfigIssue3007(tableId, defaultVarchar),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
Expand All @@ -2153,7 +2151,7 @@ func TestAcc_Table_issue3007_textColumn(t *testing.T) {
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, "text"),
Config: tableConfigIssue3007(tableId, "text"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
Expand All @@ -2169,9 +2167,7 @@ func TestAcc_Table_issue3007_textColumn(t *testing.T) {

// TODO [SNOW-1348114]: visit with table rework (e.g. changing scale is not supported: err 040052 (22000): SQL compilation error: cannot change column SOME_COLUMN from type NUMBER(38,0) to NUMBER(11,2) because changing the scale of a number is not supported.)
func TestAcc_Table_issue3007_numberColumn(t *testing.T) {
databaseName := acc.TestClient().Ids.Alpha()
schemaName := acc.TestClient().Ids.Alpha()
name := acc.TestClient().Ids.Alpha()
tableId := acc.TestClient().Ids.RandomSchemaObjectIdentifier()
resourceName := "snowflake_table.test_table"

defaultNumber := fmt.Sprintf("NUMBER(%d,%d)", sdk.DefaultNumberPrecision, sdk.DefaultNumberScale)
Expand All @@ -2184,15 +2180,15 @@ func TestAcc_Table_issue3007_numberColumn(t *testing.T) {
Steps: []resource.TestStep{
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, "NUMBER"),
Config: tableConfigIssue3007(tableId, "NUMBER"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "column.0.type", "NUMBER(11,2)"),
resource.TestCheckResourceAttr(resourceName, "column.1.type", "NUMBER(38,0)"),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, "NUMBER(11)"),
Config: tableConfigIssue3007(tableId, "NUMBER(11)"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
planchecks.ExpectChange(resourceName, "column.1.type", tfjson.ActionUpdate, sdk.String("NUMBER(38,0)"), sdk.String("NUMBER(11)")),
Expand All @@ -2205,7 +2201,7 @@ func TestAcc_Table_issue3007_numberColumn(t *testing.T) {
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, "NUMBER"),
Config: tableConfigIssue3007(tableId, "NUMBER"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
planchecks.ExpectChange(resourceName, "column.1.type", tfjson.ActionUpdate, sdk.String("NUMBER(11,0)"), sdk.String("NUMBER")),
Expand All @@ -2217,7 +2213,7 @@ func TestAcc_Table_issue3007_numberColumn(t *testing.T) {
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, defaultNumber),
Config: tableConfigIssue3007(tableId, defaultNumber),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
Expand All @@ -2229,7 +2225,7 @@ func TestAcc_Table_issue3007_numberColumn(t *testing.T) {
},
{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: tableConfigIssue3007(name, databaseName, schemaName, "decimal"),
Config: tableConfigIssue3007(tableId, "decimal"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
Expand All @@ -2243,20 +2239,9 @@ func TestAcc_Table_issue3007_numberColumn(t *testing.T) {
})
}

func tableConfigIssue3007(name string, databaseName string, schemaName string, dataType string) string {
func tableConfigIssue3007(tableId sdk.SchemaObjectIdentifier, dataType string) string {
return fmt.Sprintf(`
resource "snowflake_database" "test_database" {
name = "%[2]s"
}
resource "snowflake_schema" "test_schema" {
depends_on = [snowflake_database.test_database]
name = "%[3]s"
database = "%[2]s"
}
resource "snowflake_table" "test_table" {
depends_on = [snowflake_schema.test_schema]
name = "%[1]s"
database = "%[2]s"
schema = "%[3]s"
Expand All @@ -2272,5 +2257,5 @@ resource "snowflake_table" "test_table" {
type = "%[4]s"
}
}
`, name, databaseName, schemaName, dataType)
`, tableId.Name(), tableId.DatabaseName(), tableId.SchemaName(), dataType)
}

0 comments on commit f22630f

Please sign in to comment.