Skip to content

Commit

Permalink
fix: app-pkg unset (#2399)
Browse files Browse the repository at this point in the history
Follow up PR from discussion in original PR 


#2323 (comment)

Fixing Unset to use commas, allowing multiple unsets
  • Loading branch information
sfc-gh-swinkler authored Jan 23, 2024
1 parent f19d319 commit fedb1df
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 40 deletions.
4 changes: 2 additions & 2 deletions pkg/sdk/application_packages_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var applicationPackageUnset = g.NewQueryStruct("ApplicationPackageUnset").
OptionalSQL("DEFAULT_DDL_COLLATION").
OptionalSQL("COMMENT").
OptionalSQL("DISTRIBUTION").
WithValidation(g.ExactlyOneValueSet, "DataRetentionTimeInDays", "MaxDataExtensionTimeInDays", "DefaultDdlCollation", "Comment", "Distribution")
WithValidation(g.AtLeastOneValueSet, "DataRetentionTimeInDays", "MaxDataExtensionTimeInDays", "DefaultDdlCollation", "Comment", "Distribution")

var ApplicationPackagesDef = g.NewInterface(
"ApplicationPackages",
Expand Down Expand Up @@ -83,7 +83,7 @@ var ApplicationPackagesDef = g.NewInterface(
OptionalQueryStructField(
"Unset",
applicationPackageUnset,
g.KeywordOptions().SQL("UNSET"),
g.ListOptions().NoParentheses().SQL("UNSET"),
).
OptionalQueryStructField(
"ModifyReleaseDirective",
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/application_packages_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type AlterApplicationPackageOptions struct {
IfExists *bool `ddl:"keyword" sql:"IF EXISTS"`
name AccountObjectIdentifier `ddl:"identifier"`
Set *ApplicationPackageSet `ddl:"keyword" sql:"SET"`
Unset *ApplicationPackageUnset `ddl:"keyword" sql:"UNSET"`
Unset *ApplicationPackageUnset `ddl:"list,no_parentheses" sql:"UNSET"`
ModifyReleaseDirective *ModifyReleaseDirective `ddl:"keyword" sql:"MODIFY RELEASE DIRECTIVE"`
SetDefaultReleaseDirective *SetDefaultReleaseDirective `ddl:"keyword" sql:"SET DEFAULT RELEASE DIRECTIVE"`
SetReleaseDirective *SetReleaseDirective `ddl:"keyword" sql:"SET RELEASE DIRECTIVE"`
Expand Down
36 changes: 11 additions & 25 deletions pkg/sdk/application_packages_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func TestApplicationPackages_Alter(t *testing.T) {
assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterApplicationPackageOptions", "Set", "Unset", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"))
})

t.Run("validation: set options at least one field should be present", func(t *testing.T) {
opts := defaultOpts()
opts.Unset = &ApplicationPackageUnset{}
assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApplicationPackageOptions.Unset", "DataRetentionTimeInDays", "MaxDataExtensionTimeInDays", "DefaultDdlCollation", "Comment", "Distribution"))
})

t.Run("alter: set options", func(t *testing.T) {
opts := defaultOpts()
opts.Set = &ApplicationPackageSet{
Expand All @@ -94,33 +100,13 @@ func TestApplicationPackages_Alter(t *testing.T) {
t.Run("alter: unset options", func(t *testing.T) {
opts := defaultOpts()
opts.Unset = &ApplicationPackageUnset{
Comment: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET COMMENT`, id.FullyQualifiedName())

opts = defaultOpts()
opts.Unset = &ApplicationPackageUnset{
DataRetentionTimeInDays: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET DATA_RETENTION_TIME_IN_DAYS`, id.FullyQualifiedName())

opts = defaultOpts()
opts.Unset = &ApplicationPackageUnset{
DataRetentionTimeInDays: Bool(true),
MaxDataExtensionTimeInDays: Bool(true),
DefaultDdlCollation: Bool(true),
Comment: Bool(true),
Distribution: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET MAX_DATA_EXTENSION_TIME_IN_DAYS`, id.FullyQualifiedName())

opts = defaultOpts()
opts.Unset = &ApplicationPackageUnset{
DefaultDdlCollation: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET DEFAULT_DDL_COLLATION`, id.FullyQualifiedName())

opts = defaultOpts()
opts.Unset = &ApplicationPackageUnset{
Distribution: Bool(true),
}
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET DISTRIBUTION`, id.FullyQualifiedName())
assertOptsValidAndSQLEquals(t, opts, `ALTER APPLICATION PACKAGE IF EXISTS %s UNSET DATA_RETENTION_TIME_IN_DAYS, MAX_DATA_EXTENSION_TIME_IN_DAYS, DEFAULT_DDL_COLLATION, COMMENT, DISTRIBUTION`, id.FullyQualifiedName())
})

t.Run("alter: set tags", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/application_packages_validations_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func (opts *AlterApplicationPackageOptions) validate() error {
errs = append(errs, errExactlyOneOf("AlterApplicationPackageOptions", "Set", "Unset", "ModifyReleaseDirective", "SetDefaultReleaseDirective", "SetReleaseDirective", "UnsetReleaseDirective", "AddVersion", "DropVersion", "AddPatchForVersion", "SetTags", "UnsetTags"))
}
if valueSet(opts.Unset) {
if !exactlyOneValueSet(opts.Unset.DataRetentionTimeInDays, opts.Unset.MaxDataExtensionTimeInDays, opts.Unset.DefaultDdlCollation, opts.Unset.Comment, opts.Unset.Distribution) {
errs = append(errs, errExactlyOneOf("AlterApplicationPackageOptions.Unset", "DataRetentionTimeInDays", "MaxDataExtensionTimeInDays", "DefaultDdlCollation", "Comment", "Distribution"))
if !anyValueSet(opts.Unset.DataRetentionTimeInDays, opts.Unset.MaxDataExtensionTimeInDays, opts.Unset.DefaultDdlCollation, opts.Unset.Comment, opts.Unset.Distribution) {
errs = append(errs, errAtLeastOneOf("AlterApplicationPackageOptions.Unset", "DataRetentionTimeInDays", "MaxDataExtensionTimeInDays", "DefaultDdlCollation", "Comment", "Distribution"))
}
}
return JoinErrors(errs...)
Expand Down
13 changes: 3 additions & 10 deletions pkg/sdk/testint/application_packages_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,13 @@ func TestInt_ApplicationPackages(t *testing.T) {
e := createApplicationPackageHandle(t)
id := sdk.NewAccountObjectIdentifier(e.Name)

// unset comment
unset := sdk.NewApplicationPackageUnsetRequest().WithComment(sdk.Bool(true))
// unset comment and distribution
unset := sdk.NewApplicationPackageUnsetRequest().WithComment(sdk.Bool(true)).WithDistribution(sdk.Bool(true))
err := client.ApplicationPackages.Alter(ctx, sdk.NewAlterApplicationPackageRequest(id).WithUnset(unset))
require.NoError(t, err)
o, err := client.ApplicationPackages.ShowByID(ctx, id)
require.NoError(t, err)
require.Empty(t, o.Comment)

// unset distribution
unset = sdk.NewApplicationPackageUnsetRequest().WithDistribution(sdk.Bool(true))
err = client.ApplicationPackages.Alter(ctx, sdk.NewAlterApplicationPackageRequest(id).WithUnset(unset))
require.NoError(t, err)
o, err = client.ApplicationPackages.ShowByID(ctx, id)
require.NoError(t, err)
require.Equal(t, sdk.DistributionInternal, sdk.Distribution(o.Distribution))
})

Expand Down Expand Up @@ -201,7 +194,7 @@ func TestInt_ApplicationPackagesVersionAndReleaseDirective(t *testing.T) {
createApplicationPackageHandle := func(t *testing.T) *sdk.ApplicationPackage {
t.Helper()

id := sdk.RandomAccountObjectIdentifier()
id := sdk.NewAccountObjectIdentifier("snowflake_package_test")
request := sdk.NewCreateApplicationPackageRequest(id).WithDistribution(sdk.DistributionPointer(sdk.DistributionInternal))
err := client.ApplicationPackages.Create(ctx, request)
require.NoError(t, err)
Expand Down

0 comments on commit fedb1df

Please sign in to comment.