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 Feb 15, 2024
1 parent 9afabb0 commit 95c2a83
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
3 changes: 3 additions & 0 deletions pkg/resources/external_function_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -256,6 +257,7 @@ func TestAcc_ExternalFunction_migrateFromVersion085(t *testing.T) {
},
Config: externalFunctionConfig(acc.TestDatabaseName, acc.TestSchemaName, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf("%s|%s|%s|VARCHAR-VARCHAR", acc.TestDatabaseName, acc.TestSchemaName, name)),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "database", "\""+acc.TestDatabaseName+"\""),
resource.TestCheckResourceAttr(resourceName, "schema", "\""+acc.TestSchemaName+"\""),
Expand All @@ -270,6 +272,7 @@ func TestAcc_ExternalFunction_migrateFromVersion085(t *testing.T) {
PreApply: []plancheck.PlanCheck{plancheck.ExpectEmptyPlan()},
},
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", sdk.NewSchemaObjectIdentifierWithArguments(acc.TestDatabaseName, acc.TestSchemaName, name, []sdk.DataType{sdk.DataTypeVARCHAR, sdk.DataTypeVARCHAR}).FullyQualifiedName()),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(resourceName, "schema", acc.TestSchemaName),
Expand Down
7 changes: 3 additions & 4 deletions pkg/resources/external_function_state_upgraders.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package resources
import (
"context"
"encoding/csv"
"fmt"
"strings"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
Expand All @@ -21,14 +20,14 @@ func parseV085ExternalFunctionId(stringID string) (*v085ExternalFunctionId, erro
reader.Comma = '|'
lines, err := reader.ReadAll()
if err != nil {
return nil, fmt.Errorf("not CSV compatible")
return nil, sdk.NewError("not CSV compatible")
}

if len(lines) != 1 {
return nil, fmt.Errorf("1 line at a time")
return nil, sdk.NewError("1 line at a time")
}
if len(lines[0]) != 4 {
return nil, fmt.Errorf("4 fields allowed")
return nil, sdk.NewError("4 fields allowed")
}

return &v085ExternalFunctionId{
Expand Down
2 changes: 2 additions & 0 deletions pkg/resources/function_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func TestAcc_Function_migrateFromVersion085(t *testing.T) {
},
Config: functionConfig(acc.TestDatabaseName, acc.TestSchemaName, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf("%s|%s|%s|VARCHAR", acc.TestDatabaseName, acc.TestSchemaName, name)),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(resourceName, "schema", acc.TestSchemaName),
Expand All @@ -218,6 +219,7 @@ func TestAcc_Function_migrateFromVersion085(t *testing.T) {
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Config: functionConfig(acc.TestDatabaseName, acc.TestSchemaName, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", sdk.NewSchemaObjectIdentifierWithArguments(acc.TestDatabaseName, acc.TestSchemaName, name, []sdk.DataType{sdk.DataTypeVARCHAR}).FullyQualifiedName()),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(resourceName, "schema", acc.TestSchemaName),
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/function_state_upgraders.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type v085FunctionId struct {
func parseV085FunctionId(v string) (*v085FunctionId, error) {
arr := strings.Split(v, "|")
if len(arr) != 4 {
return nil, fmt.Errorf("ID %v is invalid", v)
return nil, sdk.NewError(fmt.Sprintf("ID %v is invalid", v))
}

// this is a bit different from V085 state, but it was buggy
Expand Down
3 changes: 3 additions & 0 deletions pkg/resources/procedure_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -202,6 +203,7 @@ func TestAcc_Procedure_migrateFromVersion085(t *testing.T) {
},
Config: procedureConfig(acc.TestDatabaseName, acc.TestSchemaName, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf("%s|%s|%s|", acc.TestDatabaseName, acc.TestSchemaName, name)),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(resourceName, "schema", acc.TestSchemaName),
Expand All @@ -214,6 +216,7 @@ func TestAcc_Procedure_migrateFromVersion085(t *testing.T) {
PreApply: []plancheck.PlanCheck{plancheck.ExpectEmptyPlan()},
},
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", sdk.NewSchemaObjectIdentifier(acc.TestDatabaseName, acc.TestSchemaName, name).FullyQualifiedName()),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "database", acc.TestDatabaseName),
resource.TestCheckResourceAttr(resourceName, "schema", acc.TestSchemaName),
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/procedure_state_upgraders.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type v085ProcedureId struct {
func parseV085ProcedureId(v string) (*v085ProcedureId, error) {
arr := strings.Split(v, "|")
if len(arr) != 4 {
return nil, fmt.Errorf("ID %v is invalid", v)
return nil, sdk.NewError(fmt.Sprintf("ID %v is invalid", v))
}

// this is a bit different from V085 state, but it was buggy
Expand Down
22 changes: 11 additions & 11 deletions pkg/sdk/testint/views_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ func TestInt_Views(t *testing.T) {

// proves issue https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2506
t.Run("show view by id: same name in different schemas", func(t *testing.T) {
schema, schemaCleanup := createSchema(t, client, testDb(t))
// we assume that SF returns views alphabetically
schemaName := "aaaa" + random.StringRange(8, 28)
schema, schemaCleanup := createSchemaWithIdentifier(t, client, testDb(t), schemaName)
t.Cleanup(schemaCleanup)

name := random.String()
Expand All @@ -500,17 +502,15 @@ func TestInt_Views(t *testing.T) {
request1 := sdk.NewCreateViewRequest(id1, sql)
request2 := sdk.NewCreateViewRequest(id2, sql)

view1 := createViewWithRequest(t, request1)
view2 := createViewWithRequest(t, request2)
createViewWithRequest(t, request1)
createViewWithRequest(t, request2)

assert.Equal(t, id1, view1.ID())
assert.Equal(t, id2, view2.ID())

for i := 0; i < 10; i++ {
returnedView, err := client.Views.ShowByID(ctx, id1)
require.NoError(t, err)
require.Equal(t, id1, returnedView.ID())
}
returnedView1, err := client.Views.ShowByID(ctx, id1)
require.NoError(t, err)
returnedView2, err := client.Views.ShowByID(ctx, id2)
require.NoError(t, err)
require.Equal(t, id1, returnedView1.ID())
require.Equal(t, id2, returnedView2.ID())
})

t.Run("describe view", func(t *testing.T) {
Expand Down

0 comments on commit 95c2a83

Please sign in to comment.