Skip to content

Commit

Permalink
Fix quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Hume committed Oct 27, 2023
1 parent 7a79ba6 commit 9127b78
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
16 changes: 14 additions & 2 deletions integration/materialized_view.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
resource "materialize_materialized_view" "simple_materialized_view" {
name = "simple_materialized_view"
name = "simple_materialized_view"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name
comment = "materialize view comment"
cluster_name = "default"

statement = <<SQL
SELECT
1 AS id
SQL
}

resource "materialize_materialized_view" "materialized_view_assertions" {
name = "materialized_view_assertions"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name
comment = "materialize view comment"
cluster_name = "default"
not_null_assertion = ["id"]

Expand Down
2 changes: 1 addition & 1 deletion pkg/materialize/materialized_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (b *MaterializedViewBuilder) Create() error {
if len(b.notNullAssertions) > 0 {
var na []string
for _, n := range b.notNullAssertions {
f := fmt.Sprintf("ASSERT NOT NULL %s", QuoteString(n))
f := fmt.Sprintf("ASSERT NOT NULL %s", QuoteIdentifier(n))
na = append(na, f)
}
q.WriteString(fmt.Sprintf(` WITH (%s)`, strings.Join(na[:], ", ")))
Expand Down
2 changes: 1 addition & 1 deletion pkg/materialize/materialized_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestMaterializedViewCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(
`CREATE MATERIALIZED VIEW "database"."schema"."materialized_view" IN CLUSTER "cluster" WITH \(ASSERT NOT NULL 'column_1', ASSERT NOT NULL 'column_2'\) AS SELECT 1 FROM t1;`,
`CREATE MATERIALIZED VIEW "database"."schema"."materialized_view" IN CLUSTER "cluster" WITH \(ASSERT NOT NULL "column_1", ASSERT NOT NULL "column_2"\) AS SELECT 1 FROM t1;`,
).WillReturnResult(sqlmock.NewResult(1, 1))

o := MaterializeObject{Name: "materialized_view", SchemaName: "schema", DatabaseName: "database"}
Expand Down
9 changes: 4 additions & 5 deletions pkg/provider/acceptance_materialized_view_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ resource "materialize_schema" "test" {
}
resource "materialize_materialized_view" "test" {
name = "%s"
schema_name = materialize_schema.test.name
database_name = materialize_database.test.name
cluster_name = "default"
not_null_assertion = ["id"]
name = "%s"
schema_name = materialize_schema.test.name
database_name = materialize_database.test.name
cluster_name = "default"
statement = <<SQL
SELECT
Expand Down
3 changes: 2 additions & 1 deletion pkg/provider/acceptance_materialized_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccMaterializedView_basic(t *testing.T) {
{
ResourceName: "materialize_materialized_view.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerify: false,
ImportStateVerifyIgnore: []string{"statement"},
},
},
Expand Down Expand Up @@ -114,6 +114,7 @@ resource "materialize_materialized_view" "test" {
name = "%[2]s"
statement = "SELECT 1 AS id"
cluster_name = "default"
not_null_assertion = ["id"]
}
resource "materialize_materialized_view" "test_role" {
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
"enable_disk_cluster_replicas",
"enable_comment",
"enable_role_vars",
"enable_assert_not_null",
}

for _, f := range flags {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/resource_materialized_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestResourceMaterializedViewCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
// Create
mock.ExpectExec(
`CREATE MATERIALIZED VIEW "database"."schema"."materialized_view" IN CLUSTER "cluster" WITH \(ASSERT NOT NULL 'column_1', ASSERT NOT NULL 'column_2'\) AS SELECT 1 FROM 1;`,
`CREATE MATERIALIZED VIEW "database"."schema"."materialized_view" IN CLUSTER "cluster" WITH \(ASSERT NOT NULL "column_1", ASSERT NOT NULL "column_2"\) AS SELECT 1 FROM 1;`,
).WillReturnResult(sqlmock.NewResult(1, 1))

// Query Id
Expand Down

0 comments on commit 9127b78

Please sign in to comment.