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 Jan 29, 2024
1 parent 427b935 commit 621ef16
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/datasources/row_access_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package datasources
import (
"context"
"database/sql"
"fmt"
"log"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/helpers"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -85,6 +85,6 @@ func ReadRowAccessPolicies(d *schema.ResourceData, meta interface{}) error {
}
}

d.SetId(fmt.Sprintf(`%v|%v`, databaseName, schemaName))
d.SetId(helpers.EncodeSnowflakeID(databaseName, schemaName))
return d.Set("row_access_policies", rowAccessPolicies)
}
5 changes: 1 addition & 4 deletions pkg/resources/row_access_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ func CreateRowAccessPolicy(d *schema.ResourceData, meta interface{}) error {

args := make([]sdk.CreateRowAccessPolicyArgsRequest, 0)
for k, v := range signature {
dataType, err := sdk.ToDataType(v.(string))
if err != nil {
return err
}
dataType := sdk.DataType(v.(string))
args = append(args, *sdk.NewCreateRowAccessPolicyArgsRequest(k, dataType))
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/sdk/testint/row_access_policies_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ func TestInt_RowAccessPolicies(t *testing.T) {
assertRowAccessPolicyDescription(t, returnedRowAccessPolicyDescription, rowAccessPolicy.ID(), fmt.Sprintf("(%s %s)", strings.ToUpper(argName), sdk.DataTypeTimestampNTZ), body)
})

t.Run("describe row access policy: with data type normalization", func(t *testing.T) {
argName := random.AlphaN(5)
argType := sdk.DataType("VARCHAR(200)")
args := sdk.NewCreateRowAccessPolicyArgsRequest(argName, argType)
body := "true"

request := createRowAccessPolicyRequest(t, []sdk.CreateRowAccessPolicyArgsRequest{*args}, body)
rowAccessPolicy := createRowAccessPolicyWithRequest(t, request)

returnedRowAccessPolicyDescription, err := client.RowAccessPolicies.Describe(ctx, rowAccessPolicy.ID())
require.NoError(t, err)

assertRowAccessPolicyDescription(t, returnedRowAccessPolicyDescription, rowAccessPolicy.ID(), fmt.Sprintf("(%s %s)", strings.ToUpper(argName), sdk.DataTypeVARCHAR), body)
})

t.Run("describe row access policy: non-existing", func(t *testing.T) {
id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist")

Expand Down

0 comments on commit 621ef16

Please sign in to comment.