-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Identifier with arguments for procedure and external function (#…
…2987) ## Changes - New identifier with arguments used in procedures and external functions. - Added state upgrader for all 3 resources (the previous identifier wasn't outputting empty parentheses for no args). - Added tests to ensure smooth migration. - Minor fixes (not much since they'll be refactored later on to prepare them for v1); most of the changes come from re-generation of `_def.go` definitions. - Added case for argument parsing arguments with default values.
- Loading branch information
1 parent
6fb76b7
commit f13cc5c
Showing
32 changed files
with
1,510 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type ExternalFunctionClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewExternalFunctionClient(context *TestClientContext, idsGenerator *IdsGenerator) *ExternalFunctionClient { | ||
return &ExternalFunctionClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *ExternalFunctionClient) client() sdk.ExternalFunctions { | ||
return c.context.client.ExternalFunctions | ||
} | ||
|
||
func (c *ExternalFunctionClient) Create(t *testing.T, apiIntegrationId sdk.AccountObjectIdentifier, arguments ...sdk.DataType) *sdk.ExternalFunction { | ||
t.Helper() | ||
return c.CreateWithIdentifier(t, apiIntegrationId, c.ids.RandomSchemaObjectIdentifierWithArguments(arguments...)) | ||
} | ||
|
||
func (c *ExternalFunctionClient) CreateWithIdentifier(t *testing.T, apiIntegrationId sdk.AccountObjectIdentifier, id sdk.SchemaObjectIdentifierWithArguments) *sdk.ExternalFunction { | ||
t.Helper() | ||
ctx := context.Background() | ||
argumentRequests := make([]sdk.ExternalFunctionArgumentRequest, len(id.ArgumentDataTypes())) | ||
for i, argumentDataType := range id.ArgumentDataTypes() { | ||
argumentRequests[i] = *sdk.NewExternalFunctionArgumentRequest(c.ids.Alpha(), argumentDataType) | ||
} | ||
err := c.client().Create(ctx, | ||
sdk.NewCreateExternalFunctionRequest( | ||
id.SchemaObjectId(), | ||
sdk.DataTypeVariant, | ||
&apiIntegrationId, | ||
"https://xyz.execute-api.us-west-2.amazonaws.com/production/remote_echo", | ||
).WithArguments(argumentRequests), | ||
) | ||
require.NoError(t, err) | ||
|
||
t.Cleanup(func() { | ||
require.NoError(t, c.context.client.Functions.Drop(ctx, sdk.NewDropFunctionRequest(id).WithIfExists(true))) | ||
}) | ||
|
||
externalFunction, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return externalFunction | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type FunctionClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewFunctionClient(context *TestClientContext, idsGenerator *IdsGenerator) *FunctionClient { | ||
return &FunctionClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *FunctionClient) client() sdk.Functions { | ||
return c.context.client.Functions | ||
} | ||
|
||
func (c *FunctionClient) Create(t *testing.T, arguments ...sdk.DataType) *sdk.Function { | ||
t.Helper() | ||
return c.CreateWithIdentifier(t, c.ids.RandomSchemaObjectIdentifierWithArguments(arguments...)) | ||
} | ||
|
||
func (c *FunctionClient) CreateWithIdentifier(t *testing.T, id sdk.SchemaObjectIdentifierWithArguments) *sdk.Function { | ||
t.Helper() | ||
ctx := context.Background() | ||
argumentRequests := make([]sdk.FunctionArgumentRequest, len(id.ArgumentDataTypes())) | ||
for i, argumentDataType := range id.ArgumentDataTypes() { | ||
argumentRequests[i] = *sdk.NewFunctionArgumentRequest(c.ids.Alpha(), argumentDataType) | ||
} | ||
err := c.client().CreateForSQL(ctx, | ||
sdk.NewCreateForSQLFunctionRequest( | ||
id.SchemaObjectId(), | ||
*sdk.NewFunctionReturnsRequest().WithResultDataType(*sdk.NewFunctionReturnsResultDataTypeRequest(sdk.DataTypeInt)), | ||
"SELECT 1", | ||
).WithArguments(argumentRequests), | ||
) | ||
require.NoError(t, err) | ||
|
||
t.Cleanup(func() { | ||
require.NoError(t, c.context.client.Functions.Drop(ctx, sdk.NewDropFunctionRequest(id).WithIfExists(true))) | ||
}) | ||
|
||
function, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return function | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type ProcedureClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewProcedureClient(context *TestClientContext, idsGenerator *IdsGenerator) *ProcedureClient { | ||
return &ProcedureClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *ProcedureClient) client() sdk.Procedures { | ||
return c.context.client.Procedures | ||
} | ||
|
||
func (c *ProcedureClient) Create(t *testing.T, arguments ...sdk.DataType) *sdk.Procedure { | ||
t.Helper() | ||
return c.CreateWithIdentifier(t, c.ids.RandomSchemaObjectIdentifierWithArguments(arguments...)) | ||
} | ||
|
||
func (c *ProcedureClient) CreateWithIdentifier(t *testing.T, id sdk.SchemaObjectIdentifierWithArguments) *sdk.Procedure { | ||
t.Helper() | ||
ctx := context.Background() | ||
argumentRequests := make([]sdk.ProcedureArgumentRequest, len(id.ArgumentDataTypes())) | ||
for i, argumentDataType := range id.ArgumentDataTypes() { | ||
argumentRequests[i] = *sdk.NewProcedureArgumentRequest(c.ids.Alpha(), argumentDataType) | ||
} | ||
err := c.client().CreateForSQL(ctx, | ||
sdk.NewCreateForSQLProcedureRequest( | ||
id.SchemaObjectId(), | ||
*sdk.NewProcedureSQLReturnsRequest().WithResultDataType(*sdk.NewProcedureReturnsResultDataTypeRequest(sdk.DataTypeInt)), | ||
`BEGIN RETURN 1; END`).WithArguments(argumentRequests), | ||
) | ||
require.NoError(t, err) | ||
|
||
t.Cleanup(func() { | ||
require.NoError(t, c.context.client.Procedures.Drop(ctx, sdk.NewDropProcedureRequest(id).WithIfExists(true))) | ||
}) | ||
|
||
procedure, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return procedure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.