Skip to content

Commit

Permalink
feat: Procedures sdk update (#3255)
Browse files Browse the repository at this point in the history
Update and test procedures SDK as part of ongoing functions&procedures
rework:
- Regenerate SDK after adjusting defs
- Wrap procedure definitions in `$$`
- Wrap arguments in double quotes
- Extract ProcedureDetails out of DESCRIBE output rows
- Add AutoEventLogging to the SDK
- Adjust alter's structure (add set/unset)
- Add missing fields to SHOW output
- Use extended in for SHOW
- Add/Generate assertions for procedure, procedure details, and
procedure parameters
- Add missing unit tests and adjust existing ones
- Add missing integration tests and temporarily skip most of the
existing ones, adjust them, or remove them
- Adjust existing resource
  • Loading branch information
sfc-gh-asawicki authored Dec 10, 2024
1 parent fc1eace commit 682606a
Show file tree
Hide file tree
Showing 34 changed files with 3,958 additions and 850 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package objectassert

import (
"fmt"
"strings"
"testing"

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

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

Expand Down Expand Up @@ -368,3 +370,38 @@ func (f *FunctionDetailsAssert) HasInstalledPackagesNotEmpty() *FunctionDetailsA
})
return f
}

func (f *FunctionDetailsAssert) HasExactlyExternalAccessIntegrations(integrations ...sdk.AccountObjectIdentifier) *FunctionDetailsAssert {
f.AddAssertion(func(t *testing.T, o *sdk.FunctionDetails) error {
t.Helper()
if o.ExternalAccessIntegrations == nil {
return fmt.Errorf("expected external access integrations to have value; got: nil")
}
joined := strings.Join(collections.Map(integrations, func(ex sdk.AccountObjectIdentifier) string { return ex.FullyQualifiedName() }), ",")
expected := fmt.Sprintf(`[%s]`, joined)
if *o.ExternalAccessIntegrations != expected {
return fmt.Errorf("expected external access integrations: %v; got: %v", expected, *o.ExternalAccessIntegrations)
}
return nil
})
return f
}

func (f *FunctionDetailsAssert) HasExactlySecrets(expectedSecrets map[string]sdk.SchemaObjectIdentifier) *FunctionDetailsAssert {
f.AddAssertion(func(t *testing.T, o *sdk.FunctionDetails) error {
t.Helper()
if o.Secrets == nil {
return fmt.Errorf("expected secrets to have value; got: nil")
}
var parts []string
for k, v := range expectedSecrets {
parts = append(parts, fmt.Sprintf(`"%s":"\"%s\".\"%s\".%s"`, k, v.DatabaseName(), v.SchemaName(), v.Name()))
}
expected := fmt.Sprintf(`{%s}`, strings.Join(parts, ","))
if *o.Secrets != expected {
return fmt.Errorf("expected secrets: %v; got: %v", expected, *o.Secrets)
}
return nil
})
return f
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package objectassert

import (
"fmt"
"strings"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

Expand All @@ -28,3 +30,38 @@ func (a *FunctionAssert) HasExternalAccessIntegrationsNil() *FunctionAssert {
})
return a
}

func (f *FunctionAssert) HasExactlyExternalAccessIntegrations(integrations ...sdk.AccountObjectIdentifier) *FunctionAssert {
f.AddAssertion(func(t *testing.T, o *sdk.Function) error {
t.Helper()
if o.ExternalAccessIntegrations == nil {
return fmt.Errorf("expected external access integrations to have value; got: nil")
}
joined := strings.Join(collections.Map(integrations, func(ex sdk.AccountObjectIdentifier) string { return ex.FullyQualifiedName() }), ",")
expected := fmt.Sprintf(`[%s]`, joined)
if *o.ExternalAccessIntegrations != expected {
return fmt.Errorf("expected external access integrations: %v; got: %v", expected, *o.ExternalAccessIntegrations)
}
return nil
})
return f
}

func (f *FunctionAssert) HasExactlySecrets(expectedSecrets map[string]sdk.SchemaObjectIdentifier) *FunctionAssert {
f.AddAssertion(func(t *testing.T, o *sdk.Function) error {
t.Helper()
if o.Secrets == nil {
return fmt.Errorf("expected secrets to have value; got: nil")
}
var parts []string
for k, v := range expectedSecrets {
parts = append(parts, fmt.Sprintf(`"%s":"\"%s\".\"%s\".%s"`, k, v.DatabaseName(), v.SchemaName(), v.Name()))
}
expected := fmt.Sprintf(`{%s}`, strings.Join(parts, ","))
if *o.Secrets != expected {
return fmt.Errorf("expected secrets: %v; got: %v", expected, *o.Secrets)
}
return nil
})
return f
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ var allStructs = []SdkObjectDef{
ObjectType: sdk.ObjectTypeFunction,
ObjectStruct: sdk.Function{},
},
{
IdType: "sdk.SchemaObjectIdentifierWithArguments",
ObjectType: sdk.ObjectTypeProcedure,
ObjectStruct: sdk.Procedure{},
},
}

func GetSdkObjectDetails() []genhelpers.SdkObjectDetails {
Expand Down
Loading

0 comments on commit 682606a

Please sign in to comment.