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 May 29, 2024
1 parent f4a1ce6 commit 3fba21f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
19 changes: 8 additions & 11 deletions pkg/resources/grant_database_role_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,17 @@ func TestAcc_GrantDatabaseRole_accountRole(t *testing.T) {
// proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2410 is fixed
func TestAcc_GrantDatabaseRole_share(t *testing.T) {
databaseId := acc.TestClient().Ids.RandomAccountObjectIdentifier()
databaseName := databaseId.Name()
databaseRoleId := acc.TestClient().Ids.RandomDatabaseObjectIdentifierInDatabase(databaseId)
databaseRoleName := databaseRoleId.Name()
databaseRoleFullyQualifiedName := databaseRoleId.FullyQualifiedName()
shareId := acc.TestClient().Ids.RandomAccountObjectIdentifier()
shareName := shareId.Name()
resourceName := "snowflake_grant_database_role.test"

configVariables := func() config.Variables {
return config.Variables{
"database": config.StringVariable(databaseName),
"database_role_name": config.StringVariable(databaseRoleName),
"share_name": config.StringVariable(shareName),
"database": config.StringVariable(databaseId.Name()),
"database_role_name": config.StringVariable(databaseRoleId.Name()),
"share_name": config.StringVariable(shareId.Name()),
}
}
resourceName := "snowflake_grant_database_role.test"
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
Expand All @@ -154,9 +151,9 @@ func TestAcc_GrantDatabaseRole_share(t *testing.T) {
ConfigDirectory: config.StaticDirectory("testdata/TestAcc_GrantDatabaseRole/share"),
ConfigVariables: configVariables(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "database_role_name", databaseRoleFullyQualifiedName),
resource.TestCheckResourceAttr(resourceName, "share_name", shareName),
resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf(`%v|%v|%v`, databaseRoleFullyQualifiedName, "SHARE", shareId.FullyQualifiedName())),
resource.TestCheckResourceAttr(resourceName, "database_role_name", databaseRoleId.FullyQualifiedName()),
resource.TestCheckResourceAttr(resourceName, "share_name", shareId.Name()),
resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf(`%v|%v|%v`, databaseRoleId.FullyQualifiedName(), "SHARE", shareId.FullyQualifiedName())),
),
},
// test import
Expand Down
1 change: 1 addition & 0 deletions pkg/sdk/poc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ find a better solution to solve the issue (add more logic to the templates ?)
- better handling of list of strings/identifiers
- there should be no need to define custom types every time
- more clear definition of lists that can be empty vs cannot be empty
- add empty ids in generated tests (TODO in random_test.go)

##### Known issues
- generating two converts when Show and Desc use the same data structure
Expand Down
11 changes: 8 additions & 3 deletions pkg/sdk/policy_references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestPolicyReferencesGetForEntity(t *testing.T) {
},
},
}
assertOptsValidAndSQLEquals(t, opts, `SELECT * FROM TABLE (SNOWFLAKE.INFORMATION_SCHEMA.POLICY_REFERENCES (REF_ENTITY_NAME => '%s', REF_ENTITY_DOMAIN => 'TABLE'))`, strings.ReplaceAll(id.FullyQualifiedName(), `"`, `\"`))
assertOptsValidAndSQLEquals(t, opts, `SELECT * FROM TABLE (SNOWFLAKE.INFORMATION_SCHEMA.POLICY_REFERENCES (REF_ENTITY_NAME => '%s', REF_ENTITY_DOMAIN => 'TABLE'))`, temporaryReplace(id))
})

t.Run("account domain", func(t *testing.T) {
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestPolicyReferencesGetForEntity(t *testing.T) {
},
},
}
assertOptsValidAndSQLEquals(t, opts, `SELECT * FROM TABLE (SNOWFLAKE.INFORMATION_SCHEMA.POLICY_REFERENCES (REF_ENTITY_NAME => '%s', REF_ENTITY_DOMAIN => 'TAG'))`, strings.ReplaceAll(id.FullyQualifiedName(), `"`, `\"`))
assertOptsValidAndSQLEquals(t, opts, `SELECT * FROM TABLE (SNOWFLAKE.INFORMATION_SCHEMA.POLICY_REFERENCES (REF_ENTITY_NAME => '%s', REF_ENTITY_DOMAIN => 'TAG'))`, temporaryReplace(id))
})

t.Run("view domain", func(t *testing.T) {
Expand All @@ -112,6 +112,11 @@ func TestPolicyReferencesGetForEntity(t *testing.T) {
},
},
}
assertOptsValidAndSQLEquals(t, opts, `SELECT * FROM TABLE (SNOWFLAKE.INFORMATION_SCHEMA.POLICY_REFERENCES (REF_ENTITY_NAME => '%s', REF_ENTITY_DOMAIN => 'VIEW'))`, strings.ReplaceAll(id.FullyQualifiedName(), `"`, `\"`))
assertOptsValidAndSQLEquals(t, opts, `SELECT * FROM TABLE (SNOWFLAKE.INFORMATION_SCHEMA.POLICY_REFERENCES (REF_ENTITY_NAME => '%s', REF_ENTITY_DOMAIN => 'VIEW'))`, temporaryReplace(id))
})
}

// TODO [SNOW-999049]: check during the identifiers rework
func temporaryReplace(id SchemaObjectIdentifier) string {
return strings.ReplaceAll(id.FullyQualifiedName(), `"`, `\"`)
}
1 change: 0 additions & 1 deletion pkg/sdk/test_ids_test.go

This file was deleted.

0 comments on commit 3fba21f

Please sign in to comment.