diff --git a/Makefile b/Makefile index 1593810d0b..1e0504f5bd 100644 --- a/Makefile +++ b/Makefile @@ -123,4 +123,16 @@ generate-show-output-schemas: ## Generate show output schemas with mappers clean-show-output-schemas: ## Clean generated show output schemas rm -f ./pkg/schemas/*_gen.go +generate-snowflake-object-assertions: ## Generate snowflake object assertions + go generate ./pkg/acceptance/bettertestspoc/assert/objectassert/generate.go + +clean-snowflake-object-assertions: ## Clean snowflake object assertions + rm -f ./pkg/acceptance/bettertestspoc/assert/objectassert/*_gen.go + +generate-snowflake-object-parameters-assertions: ## Generate snowflake object parameters assertions + go generate ./pkg/acceptance/bettertestspoc/assert/objectparametersassert/generate.go + +clean-snowflake-object-parameters-assertions: ## Clean snowflake object parameters assertions + rm -f ./pkg/acceptance/bettertestspoc/assert/objectparametersassert/*_gen.go + .PHONY: build-local clean-generator-poc dev-setup dev-cleanup docs docs-check fmt fmt-check fumpt help install lint lint-fix mod mod-check pre-push pre-push-check sweep test test-acceptance uninstall-tf diff --git a/pkg/acceptance/bettertestspoc/README.md b/pkg/acceptance/bettertestspoc/README.md index 68b698ea0c..3ec94ca7f7 100644 --- a/pkg/acceptance/bettertestspoc/README.md +++ b/pkg/acceptance/bettertestspoc/README.md @@ -1,9 +1,13 @@ # Better tests poc This package contains a quick implementation of helpers that should allow us a quicker, more pleasant, and more readable implementation of tests, mainly the acceptance ones. It contains the following packages: -- `assert` - all the assertions reside here. The currently supported assertions are: resource assertions, show output assertions, parameters assertions, and Snowflake object assertions. -The package contains utilities to build assertions for new objects. -All the assertions will be ultimately generated; the ones presented for warehouse were manually created. +- `assert` - all the assertions reside here. Also, the utilities to build assertions for new objects. All the assertions will be ultimately generated; the ones presented in this folder were manually created. The currently supported assertions are: + - resource assertions (currently, created manually) + - show output assertions (currently, created manually) + - resource parameters assertions (currently, created manually) + - Snowflake object assertions (generated in subpackage `objectassert`) + - Snowflake object parameters assertions (generated in subpackage `objectparametersassert`) + - `config` - the new ResourceModel abstraction resides here. It provides models for objects and the builder methods allowing better config preparation in the acceptance tests. It aims to be more readable than using `Config:` with hardcoded string or `ConfigFile:` for file that is not directly reachable from the test body. Also, it should be easier to reuse the models and prepare convenience extension methods. All the models will be ultimately generated; the ones presented for warehouse were manually created. @@ -21,7 +25,7 @@ You can check the current example usage in `TestAcc_Warehouse_BasicFlows` and th assert.WarehouseParameters(t, "snowflake_warehouse.w"). HasMaxConcurrencyLevel(16). HasMaxConcurrencyLevelLevel(sdk.ParameterTypeWarehouse), - assert.Warehouse(t, warehouseId). + objectassert.Warehouse(t, warehouseId). HasName("bad name"). HasState(sdk.WarehouseStateSuspended). HasType(sdk.WarehouseTypeSnowparkOptimized). @@ -89,7 +93,7 @@ it will result in: HasStatementQueuedTimeoutInSecondsLevel(sdk.ParameterTypeWarehouse). HasStatementTimeoutInSeconds(1232). HasStatementTimeoutInSecondsLevel(sdk.ParameterTypeWarehouse), - assert.Warehouse(t, warehouseId). + objectassert.Warehouse(t, warehouseId). HasName("bad name"). HasState(sdk.WarehouseStateSuspended). HasType(sdk.WarehouseTypeSnowparkOptimized). @@ -147,7 +151,7 @@ it will result in: - add the following to the `create: complete` in `TestInt_Warehouses`: ```go // to show errors - warehouseAssertionsBad := objectAssert.Warehouse(t, id). + warehouseAssertionsBad := objectassert.Warehouse(t, id). HasName("bad name"). HasState(sdk.WarehouseStateSuspended). HasType(sdk.WarehouseTypeSnowparkOptimized). @@ -161,7 +165,7 @@ it will result in: HasComment("bad comment"). HasEnableQueryAcceleration(false). HasQueryAccelerationMaxScaleFactor(12) - objectAssert.AssertThatObject(t, warehouseAssertionsBad) + assertions.AssertThatObject(t, warehouseAssertionsBad) ``` it will result in: ``` @@ -345,43 +349,9 @@ func (w *WarehouseParametersAssert) HasDefaultStatementTimeoutInSeconds() *Wareh ``` ## Adding new Snowflake object assertions -For object `abc` create the following files with the described content in the `assert` package: -- `abc_snowflake.go` -```go -type AbcAssert struct { - *SnowflakeObjectAssert[sdk.Abc, sdk.AccountObjectIdentifier] -} - -func Abc(t *testing.T, id sdk.AccountObjectIdentifier) *AbcAssert { - t.Helper() - return &AbcAssert{ - NewSnowflakeObjectAssertWithProvider(sdk.ObjectTypeAbc, id, acc.TestClient().Abc.Show), - } -} - -func AbcFromObject(t *testing.T, abc *sdk.Abc) *AbcAssert { - t.Helper() - return &AbcAssert{ - NewSnowflakeObjectAssertWithObject(sdk.ObjectTypeAbc, abc.ID(), abc), - } -} -``` - -A method for each object parameter (let's say parameter name is xyz): -```go -func (w *AbcAssert) HasXyz(expected string) *AbcAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Abc) error { - t.Helper() - if o.Xyz != expected { - return fmt.Errorf("expected xyz: %v; got: %v", expected, o.Xyz) - } - return nil - }) - return w -} -``` - -- `abc_snowflake_ext.go` - for the easier separation later (when we start generating the common checks for each object). Example would be: +Snowflake object assertions can be generated automatically. For object `abc` do the following: +- add object you want to generate to `allStructs` slice in the `assert/objectassert/gen/main/main.go` +- to add custom (not generated assertions) create file `abc_snowflake_ext.go` in the `objectassert` package. Example would be: ```go func (w *WarehouseAssert) HasStateOneOf(expected ...sdk.WarehouseState) *WarehouseAssert { w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { @@ -395,6 +365,19 @@ func (w *WarehouseAssert) HasStateOneOf(expected ...sdk.WarehouseState) *Warehou } ``` +## Adding new Snowflake object parameters assertions +Snowflake object parameters assertions can be generated automatically. For object `abc` do the following: +- add object you want to generate to `allObjectsParameters` slice in the `assert/objectparametersassert/gen/main/main.go` +- make sure that test helper method `acc.TestClient().Parameter.ShowAbcParameters` exists in `/pkg/acceptance/helpers/parameter_client.go` +- to add custom (not generated assertions) create file `abc_parameters_snowflake_ext.go` in the `objectparametersassert` package. Example would be: +```go +func (w *WarehouseParametersAssert) HasDefaultMaxConcurrencyLevel() *WarehouseParametersAssert { + return w. + HasMaxConcurrencyLevel(8). + HasMaxConcurrencyLevelLevel("") +} +``` + ## Adding new models For object `abc` create the following files with the described content in the `config` package: - `abc_model.go` @@ -447,7 +430,7 @@ func BasicWarehouseModel( ``` ## Known limitations/planned improvements -- Generate all assertions and models. +- Generate all missing assertions and models. - Test all the utilities for assertion/model construction (public interfaces, methods, functions). - Verify if all the config types are supported. - Consider a better implementation for the model conversion to config (TODO left). @@ -468,3 +451,7 @@ func (w *WarehouseDatasourceShowOutputAssert) IsEmpty() { w.assertions = append(w.assertions, valueSet("show_output.#", "0")) } ``` +- support other mappings if needed (TODO left in `assert/objectassert/gen/model.go`) +- consider extracting preamble model to commons (TODOs left in `assert/objectassert/gen/model.go` and in `assert/objectparametersassert/gen/model.go`) +- get a runtime name for the assertion creator (TODOs left in `assert/objectparametersassert/gen/model.go`) +- use a better definition for each objet's snowflake parameters (TODO left in `assert/objectparametersassert/gen/main/main.go`) \ No newline at end of file diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go new file mode 100644 index 0000000000..a9635a1bc7 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go @@ -0,0 +1,55 @@ +//go:build exclude + +package main + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +func main() { + genhelpers.NewGenerator( + getSdkObjectDetails, + gen.ModelFromSdkObjectDetails, + getFilename, + gen.AllTemplates, + ). + RunAndHandleOsReturn() +} + +type SdkObjectDef struct { + idType string + objectType sdk.ObjectType + objectStruct any +} + +func getSdkObjectDetails() []genhelpers.SdkObjectDetails { + allSdkObjectsDetails := make([]genhelpers.SdkObjectDetails, len(allStructs)) + for idx, d := range allStructs { + structDetails := genhelpers.ExtractStructDetails(d.objectStruct) + allSdkObjectsDetails[idx] = genhelpers.SdkObjectDetails{ + IdType: d.idType, + ObjectType: d.objectType, + StructDetails: structDetails, + } + } + return allSdkObjectsDetails +} + +func getFilename(_ genhelpers.SdkObjectDetails, model gen.SnowflakeObjectAssertionsModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_snowflake" + "_gen.go" +} + +var allStructs = []SdkObjectDef{ + { + idType: "sdk.AccountObjectIdentifier", + objectType: sdk.ObjectTypeUser, + objectStruct: sdk.User{}, + }, + { + idType: "sdk.AccountObjectIdentifier", + objectType: sdk.ObjectTypeWarehouse, + objectStruct: sdk.Warehouse{}, + }, +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go new file mode 100644 index 0000000000..a4de0d2846 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go @@ -0,0 +1,81 @@ +package gen + +import ( + "os" + "slices" + "strings" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +// TODO [SNOW-1501905]: extract to commons? +type PreambleModel struct { + PackageName string + AdditionalStandardImports []string +} + +type SnowflakeObjectAssertionsModel struct { + Name string + SdkType string + IdType string + Fields []SnowflakeObjectFieldAssertion + PreambleModel +} + +func (m SnowflakeObjectAssertionsModel) SomeFunc() { +} + +type SnowflakeObjectFieldAssertion struct { + Name string + ConcreteType string + IsOriginalTypePointer bool + Mapper genhelpers.Mapper +} + +func ModelFromSdkObjectDetails(sdkObject genhelpers.SdkObjectDetails) SnowflakeObjectAssertionsModel { + name, _ := strings.CutPrefix(sdkObject.Name, "sdk.") + fields := make([]SnowflakeObjectFieldAssertion, len(sdkObject.Fields)) + imports := make(map[string]struct{}) + for idx, field := range sdkObject.Fields { + fields[idx] = MapToSnowflakeObjectFieldAssertion(field) + additionalImport, isImportedType := field.GetImportedType() + if isImportedType { + imports[additionalImport] = struct{}{} + } + } + additionalImports := make([]string, 0) + for k := range imports { + if !slices.Contains([]string{"sdk"}, k) { + additionalImports = append(additionalImports, k) + } + } + + packageWithGenerateDirective := os.Getenv("GOPACKAGE") + return SnowflakeObjectAssertionsModel{ + Name: name, + SdkType: sdkObject.Name, + IdType: sdkObject.IdType, + Fields: fields, + PreambleModel: PreambleModel{ + PackageName: packageWithGenerateDirective, + AdditionalStandardImports: additionalImports, + }, + } +} + +func MapToSnowflakeObjectFieldAssertion(field genhelpers.Field) SnowflakeObjectFieldAssertion { + concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") + + // TODO [SNOW-1501905]: handle other mappings if needed + mapper := genhelpers.Identity + if concreteTypeWithoutPtr == "sdk.AccountObjectIdentifier" { + mapper = genhelpers.Name + } + + return SnowflakeObjectFieldAssertion{ + Name: field.Name, + ConcreteType: field.ConcreteType, + IsOriginalTypePointer: field.IsPointer(), + Mapper: mapper, + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go new file mode 100644 index 0000000000..3309a84da8 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go @@ -0,0 +1,33 @@ +package gen + +import ( + "text/template" + + _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + + //go:embed templates/definition.tmpl + definitionTemplateContent string + DefinitionTemplate, _ = template.New("definitionTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + )).Parse(definitionTemplateContent) + + //go:embed templates/assertions.tmpl + assertionsTemplateContent string + AssertionsTemplate, _ = template.New("assertionsTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + genhelpers.TypeWithoutPointer, + genhelpers.CamelToWords, + genhelpers.RunMapper, + )).Parse(assertionsTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, DefinitionTemplate, AssertionsTemplate} +) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl new file mode 100644 index 0000000000..d36caddcea --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl @@ -0,0 +1,23 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen.SnowflakeObjectAssertionsModel*/ -}} + +{{ $assertName := .Name | printf "%sAssert" }} +{{ $sdkType := .SdkType }} +{{ $nameLowerCase := FirstLetterLowercase .Name }} +{{ $assertVar := FirstLetter $nameLowerCase }} +{{- range .Fields }} + func ({{ $assertVar }} *{{ $assertName }}) Has{{ .Name }}(expected {{ TypeWithoutPointer .ConcreteType }}) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(func(t *testing.T, o *{{ $sdkType }}) error { + t.Helper() + {{ if .IsOriginalTypePointer -}} + if o.{{ .Name }} == nil { + return fmt.Errorf("expected {{ CamelToWords .Name }} to have value; got: nil") + } + {{ end -}} + if {{ if .IsOriginalTypePointer }}*{{ end }}{{ RunMapper .Mapper "o." .Name }} != {{ RunMapper .Mapper "expected" }} { + return fmt.Errorf("expected {{ CamelToWords .Name }}: %v; got: %v", {{ RunMapper .Mapper "expected" }}, {{ if .IsOriginalTypePointer }}*{{ end }}{{ RunMapper .Mapper "o." .Name }}) + } + return nil + }) + return {{ $assertVar }} + } +{{ end }} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl new file mode 100644 index 0000000000..511a00cb46 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl @@ -0,0 +1,21 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen.SnowflakeObjectAssertionsModel*/ -}} + +{{ $assertName := .Name | printf "%sAssert" }} +{{ $nameLowerCase := FirstLetterLowercase .Name }} +type {{ $assertName }} struct { + *assert.SnowflakeObjectAssert[{{ .SdkType }}, {{ .IdType }}] +} + +func {{ .Name }}(t *testing.T, id {{ .IdType }}) *{{ $assertName }} { + t.Helper() + return &{{ $assertName }}{ + assert.NewSnowflakeObjectAssertWithProvider(sdk.ObjectType{{ .Name }}, id, acc.TestClient().{{ .Name }}.Show), + } +} + +func {{ .Name }}FromObject(t *testing.T, {{ $nameLowerCase }} *{{ .SdkType }}) *{{ $assertName }} { + t.Helper() + return &{{ $assertName }}{ + assert.NewSnowflakeObjectAssertWithObject(sdk.ObjectType{{ .Name }}, {{ $nameLowerCase }}.ID(), {{ $nameLowerCase }}), + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl new file mode 100644 index 0000000000..ac7011d57e --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl @@ -0,0 +1,18 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen.PreambleModel*/ -}} + +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package {{ .PackageName }} + +import ( + "fmt" + "testing" + {{- range .AdditionalStandardImports }} + "{{- . }}" + {{- end }} + + 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/sdk" +) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go b/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go new file mode 100644 index 0000000000..25a8acb1c1 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go @@ -0,0 +1,3 @@ +package objectassert + +//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/acceptance/bettertestspoc/assert/user_snowflake_ext.go b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_ext.go similarity index 81% rename from pkg/acceptance/bettertestspoc/assert/user_snowflake_ext.go rename to pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_ext.go index 51bbd4f46c..910672b3be 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_snowflake_ext.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_ext.go @@ -1,4 +1,4 @@ -package assert +package objectassert import ( "fmt" @@ -39,7 +39,7 @@ func (w *UserAssert) HasDefaults(name string) *UserAssert { } func (w *UserAssert) HasCreatedOnNotEmpty() *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { + w.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.CreatedOn == (time.Time{}) { return fmt.Errorf("expected created on not empty; got: %v", o.CreatedOn) @@ -50,7 +50,7 @@ func (w *UserAssert) HasCreatedOnNotEmpty() *UserAssert { } func (w *UserAssert) HasLastSuccessLoginEmpty() *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { + w.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.LastSuccessLogin != (time.Time{}) { return fmt.Errorf("expected last success login empty; got: %v", o.LastSuccessLogin) @@ -61,7 +61,7 @@ func (w *UserAssert) HasLastSuccessLoginEmpty() *UserAssert { } func (w *UserAssert) HasExpiresAtTimeEmpty() *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { + w.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.ExpiresAtTime != (time.Time{}) { return fmt.Errorf("expected expires at time empty; got: %v", o.ExpiresAtTime) @@ -72,7 +72,7 @@ func (w *UserAssert) HasExpiresAtTimeEmpty() *UserAssert { } func (w *UserAssert) HasLockedUntilTimeEmpty() *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { + w.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.LockedUntilTime != (time.Time{}) { return fmt.Errorf("expected locked until time empty; got: %v", o.LockedUntilTime) @@ -83,7 +83,7 @@ func (w *UserAssert) HasLockedUntilTimeEmpty() *UserAssert { } func (w *UserAssert) HasExpiresAtTimeNotEmpty() *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { + w.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.ExpiresAtTime == (time.Time{}) { return fmt.Errorf("expected expires at time not empty; got: %v", o.ExpiresAtTime) @@ -94,7 +94,7 @@ func (w *UserAssert) HasExpiresAtTimeNotEmpty() *UserAssert { } func (w *UserAssert) HasLockedUntilTimeNotEmpty() *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { + w.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.LockedUntilTime == (time.Time{}) { return fmt.Errorf("expected locked until time not empty; got: %v", o.LockedUntilTime) @@ -105,7 +105,7 @@ func (w *UserAssert) HasLockedUntilTimeNotEmpty() *UserAssert { } func (w *UserAssert) HasDefaultNamespaceId(expected sdk.DatabaseObjectIdentifier) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { + w.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if sdk.NewDatabaseObjectIdentifierFromFullyQualifiedName(o.DefaultNamespace).FullyQualifiedName() != expected.FullyQualifiedName() { return fmt.Errorf("expected default namespace: %v; got: %v", expected, o.DefaultNamespace) @@ -116,7 +116,7 @@ func (w *UserAssert) HasDefaultNamespaceId(expected sdk.DatabaseObjectIdentifier } func (w *UserAssert) HasDaysToExpiryNotEmpty() *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { + w.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.DaysToExpiry == "" { return fmt.Errorf("expected days to expiry not empty; got: %v", o.DaysToExpiry) diff --git a/pkg/acceptance/bettertestspoc/assert/user_snowflake.go b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go similarity index 51% rename from pkg/acceptance/bettertestspoc/assert/user_snowflake.go rename to pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go index 30e30bd5b7..d3875a169b 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go @@ -1,4 +1,6 @@ -package assert +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package objectassert import ( "fmt" @@ -7,309 +9,310 @@ import ( 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/sdk" ) type UserAssert struct { - *SnowflakeObjectAssert[sdk.User, sdk.AccountObjectIdentifier] + *assert.SnowflakeObjectAssert[sdk.User, sdk.AccountObjectIdentifier] } func User(t *testing.T, id sdk.AccountObjectIdentifier) *UserAssert { t.Helper() return &UserAssert{ - NewSnowflakeObjectAssertWithProvider(sdk.ObjectTypeUser, id, acc.TestClient().User.Show), + assert.NewSnowflakeObjectAssertWithProvider(sdk.ObjectTypeUser, id, acc.TestClient().User.Show), } } func UserFromObject(t *testing.T, user *sdk.User) *UserAssert { t.Helper() return &UserAssert{ - NewSnowflakeObjectAssertWithObject(sdk.ObjectTypeUser, user.ID(), user), + assert.NewSnowflakeObjectAssertWithObject(sdk.ObjectTypeUser, user.ID(), user), } } -func (w *UserAssert) HasName(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasName(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.Name != expected { return fmt.Errorf("expected name: %v; got: %v", expected, o.Name) } return nil }) - return w + return u } -func (w *UserAssert) HasCreatedOn(expected time.Time) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasCreatedOn(expected time.Time) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.CreatedOn != expected { return fmt.Errorf("expected created on: %v; got: %v", expected, o.CreatedOn) } return nil }) - return w + return u } -func (w *UserAssert) HasLoginName(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasLoginName(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.LoginName != expected { return fmt.Errorf("expected login name: %v; got: %v", expected, o.LoginName) } return nil }) - return w + return u } -func (w *UserAssert) HasDisplayName(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasDisplayName(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.DisplayName != expected { return fmt.Errorf("expected display name: %v; got: %v", expected, o.DisplayName) } return nil }) - return w + return u } -func (w *UserAssert) HasFirstName(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasFirstName(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.FirstName != expected { return fmt.Errorf("expected first name: %v; got: %v", expected, o.FirstName) } return nil }) - return w + return u } -func (w *UserAssert) HasLastName(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasLastName(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.LastName != expected { return fmt.Errorf("expected last name: %v; got: %v", expected, o.LastName) } return nil }) - return w + return u } -func (w *UserAssert) HasEmail(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasEmail(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.Email != expected { return fmt.Errorf("expected email: %v; got: %v", expected, o.Email) } return nil }) - return w + return u } -func (w *UserAssert) HasMinsToUnlock(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasMinsToUnlock(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.MinsToUnlock != expected { return fmt.Errorf("expected mins to unlock: %v; got: %v", expected, o.MinsToUnlock) } return nil }) - return w + return u } -func (w *UserAssert) HasDaysToExpiry(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasDaysToExpiry(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.DaysToExpiry != expected { return fmt.Errorf("expected days to expiry: %v; got: %v", expected, o.DaysToExpiry) } return nil }) - return w + return u } -func (w *UserAssert) HasComment(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasComment(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.Comment != expected { return fmt.Errorf("expected comment: %v; got: %v", expected, o.Comment) } return nil }) - return w + return u } -func (w *UserAssert) HasDisabled(expected bool) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasDisabled(expected bool) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.Disabled != expected { return fmt.Errorf("expected disabled: %v; got: %v", expected, o.Disabled) } return nil }) - return w + return u } -func (w *UserAssert) HasMustChangePassword(expected bool) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasMustChangePassword(expected bool) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.MustChangePassword != expected { return fmt.Errorf("expected must change password: %v; got: %v", expected, o.MustChangePassword) } return nil }) - return w + return u } -func (w *UserAssert) HasSnowflakeLock(expected bool) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasSnowflakeLock(expected bool) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.SnowflakeLock != expected { return fmt.Errorf("expected snowflake lock: %v; got: %v", expected, o.SnowflakeLock) } return nil }) - return w + return u } -func (w *UserAssert) HasDefaultWarehouse(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasDefaultWarehouse(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.DefaultWarehouse != expected { return fmt.Errorf("expected default warehouse: %v; got: %v", expected, o.DefaultWarehouse) } return nil }) - return w + return u } -func (w *UserAssert) HasDefaultNamespace(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasDefaultNamespace(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.DefaultNamespace != expected { return fmt.Errorf("expected default namespace: %v; got: %v", expected, o.DefaultNamespace) } return nil }) - return w + return u } -func (w *UserAssert) HasDefaultRole(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasDefaultRole(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.DefaultRole != expected { return fmt.Errorf("expected default role: %v; got: %v", expected, o.DefaultRole) } return nil }) - return w + return u } -func (w *UserAssert) HasDefaultSecondaryRoles(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasDefaultSecondaryRoles(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.DefaultSecondaryRoles != expected { return fmt.Errorf("expected default secondary roles: %v; got: %v", expected, o.DefaultSecondaryRoles) } return nil }) - return w + return u } -func (w *UserAssert) HasExtAuthnDuo(expected bool) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasExtAuthnDuo(expected bool) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.ExtAuthnDuo != expected { - return fmt.Errorf("expected ext auth duo: %v; got: %v", expected, o.ExtAuthnDuo) + return fmt.Errorf("expected ext authn duo: %v; got: %v", expected, o.ExtAuthnDuo) } return nil }) - return w + return u } -func (w *UserAssert) HasExtAuthnUid(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasExtAuthnUid(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.ExtAuthnUid != expected { return fmt.Errorf("expected ext authn uid: %v; got: %v", expected, o.ExtAuthnUid) } return nil }) - return w + return u } -func (w *UserAssert) HasMinsToBypassMfa(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasMinsToBypassMfa(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.MinsToBypassMfa != expected { return fmt.Errorf("expected mins to bypass mfa: %v; got: %v", expected, o.MinsToBypassMfa) } return nil }) - return w + return u } -func (w *UserAssert) HasOwner(expected string) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasOwner(expected string) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.Owner != expected { return fmt.Errorf("expected owner: %v; got: %v", expected, o.Owner) } return nil }) - return w + return u } -func (w *UserAssert) HasLastSuccessLogin(expected time.Time) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasLastSuccessLogin(expected time.Time) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.LastSuccessLogin != expected { return fmt.Errorf("expected last success login: %v; got: %v", expected, o.LastSuccessLogin) } return nil }) - return w + return u } -func (w *UserAssert) HasExpiresAtTime(expected time.Time) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasExpiresAtTime(expected time.Time) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.ExpiresAtTime != expected { return fmt.Errorf("expected expires at time: %v; got: %v", expected, o.ExpiresAtTime) } return nil }) - return w + return u } -func (w *UserAssert) HasLockedUntilTime(expected time.Time) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasLockedUntilTime(expected time.Time) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.LockedUntilTime != expected { return fmt.Errorf("expected locked until time: %v; got: %v", expected, o.LockedUntilTime) } return nil }) - return w + return u } -func (w *UserAssert) HasHasPassword(expected bool) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasHasPassword(expected bool) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.HasPassword != expected { return fmt.Errorf("expected has password: %v; got: %v", expected, o.HasPassword) } return nil }) - return w + return u } -func (w *UserAssert) HasHasRsaPublicKey(expected bool) *UserAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.User) error { +func (u *UserAssert) HasHasRsaPublicKey(expected bool) *UserAssert { + u.AddAssertion(func(t *testing.T, o *sdk.User) error { t.Helper() if o.HasRsaPublicKey != expected { return fmt.Errorf("expected has rsa public key: %v; got: %v", expected, o.HasRsaPublicKey) } return nil }) - return w + return u } diff --git a/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake_ext.go b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_ext.go similarity index 79% rename from pkg/acceptance/bettertestspoc/assert/warehouse_snowflake_ext.go rename to pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_ext.go index a9b835dd95..c1d49b5bef 100644 --- a/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake_ext.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_ext.go @@ -1,4 +1,4 @@ -package assert +package objectassert import ( "fmt" @@ -9,7 +9,7 @@ import ( ) func (w *WarehouseAssert) HasStateOneOf(expected ...sdk.WarehouseState) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { t.Helper() if !slices.Contains(expected, o.State) { return fmt.Errorf("expected state one of: %v; got: %v", expected, string(o.State)) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go new file mode 100644 index 0000000000..d90d75bb8b --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go @@ -0,0 +1,329 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package objectassert + +import ( + "fmt" + "testing" + "time" + + 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/sdk" +) + +type WarehouseAssert struct { + *assert.SnowflakeObjectAssert[sdk.Warehouse, sdk.AccountObjectIdentifier] +} + +func Warehouse(t *testing.T, id sdk.AccountObjectIdentifier) *WarehouseAssert { + t.Helper() + return &WarehouseAssert{ + assert.NewSnowflakeObjectAssertWithProvider(sdk.ObjectTypeWarehouse, id, acc.TestClient().Warehouse.Show), + } +} + +func WarehouseFromObject(t *testing.T, warehouse *sdk.Warehouse) *WarehouseAssert { + t.Helper() + return &WarehouseAssert{ + assert.NewSnowflakeObjectAssertWithObject(sdk.ObjectTypeWarehouse, warehouse.ID(), warehouse), + } +} + +func (w *WarehouseAssert) HasName(expected string) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Name != expected { + return fmt.Errorf("expected name: %v; got: %v", expected, o.Name) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasState(expected sdk.WarehouseState) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.State != expected { + return fmt.Errorf("expected state: %v; got: %v", expected, o.State) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasType(expected sdk.WarehouseType) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Type != expected { + return fmt.Errorf("expected type: %v; got: %v", expected, o.Type) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasSize(expected sdk.WarehouseSize) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Size != expected { + return fmt.Errorf("expected size: %v; got: %v", expected, o.Size) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasMinClusterCount(expected int) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.MinClusterCount != expected { + return fmt.Errorf("expected min cluster count: %v; got: %v", expected, o.MinClusterCount) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasMaxClusterCount(expected int) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.MaxClusterCount != expected { + return fmt.Errorf("expected max cluster count: %v; got: %v", expected, o.MaxClusterCount) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasStartedClusters(expected int) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.StartedClusters != expected { + return fmt.Errorf("expected started clusters: %v; got: %v", expected, o.StartedClusters) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasRunning(expected int) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Running != expected { + return fmt.Errorf("expected running: %v; got: %v", expected, o.Running) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasQueued(expected int) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Queued != expected { + return fmt.Errorf("expected queued: %v; got: %v", expected, o.Queued) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasIsDefault(expected bool) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.IsDefault != expected { + return fmt.Errorf("expected is default: %v; got: %v", expected, o.IsDefault) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasIsCurrent(expected bool) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.IsCurrent != expected { + return fmt.Errorf("expected is current: %v; got: %v", expected, o.IsCurrent) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasAutoSuspend(expected int) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.AutoSuspend != expected { + return fmt.Errorf("expected auto suspend: %v; got: %v", expected, o.AutoSuspend) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasAutoResume(expected bool) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.AutoResume != expected { + return fmt.Errorf("expected auto resume: %v; got: %v", expected, o.AutoResume) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasAvailable(expected float64) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Available != expected { + return fmt.Errorf("expected available: %v; got: %v", expected, o.Available) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasProvisioning(expected float64) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Provisioning != expected { + return fmt.Errorf("expected provisioning: %v; got: %v", expected, o.Provisioning) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasQuiescing(expected float64) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Quiescing != expected { + return fmt.Errorf("expected quiescing: %v; got: %v", expected, o.Quiescing) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasOther(expected float64) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Other != expected { + return fmt.Errorf("expected other: %v; got: %v", expected, o.Other) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasCreatedOn(expected time.Time) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.CreatedOn != expected { + return fmt.Errorf("expected created on: %v; got: %v", expected, o.CreatedOn) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasResumedOn(expected time.Time) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.ResumedOn != expected { + return fmt.Errorf("expected resumed on: %v; got: %v", expected, o.ResumedOn) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasUpdatedOn(expected time.Time) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.UpdatedOn != expected { + return fmt.Errorf("expected updated on: %v; got: %v", expected, o.UpdatedOn) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasOwner(expected string) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Owner != expected { + return fmt.Errorf("expected owner: %v; got: %v", expected, o.Owner) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasComment(expected string) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.Comment != expected { + return fmt.Errorf("expected comment: %v; got: %v", expected, o.Comment) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasEnableQueryAcceleration(expected bool) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.EnableQueryAcceleration != expected { + return fmt.Errorf("expected enable query acceleration: %v; got: %v", expected, o.EnableQueryAcceleration) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasQueryAccelerationMaxScaleFactor(expected int) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.QueryAccelerationMaxScaleFactor != expected { + return fmt.Errorf("expected query acceleration max scale factor: %v; got: %v", expected, o.QueryAccelerationMaxScaleFactor) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasResourceMonitor(expected sdk.AccountObjectIdentifier) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.ResourceMonitor.Name() != expected.Name() { + return fmt.Errorf("expected resource monitor: %v; got: %v", expected.Name(), o.ResourceMonitor.Name()) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasScalingPolicy(expected sdk.ScalingPolicy) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.ScalingPolicy != expected { + return fmt.Errorf("expected scaling policy: %v; got: %v", expected, o.ScalingPolicy) + } + return nil + }) + return w +} + +func (w *WarehouseAssert) HasOwnerRoleType(expected string) *WarehouseAssert { + w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { + t.Helper() + if o.OwnerRoleType != expected { + return fmt.Errorf("expected owner role type: %v; got: %v", expected, o.OwnerRoleType) + } + return nil + }) + return w +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go new file mode 100644 index 0000000000..982f6daf90 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go @@ -0,0 +1,22 @@ +package gen + +import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + +type SnowflakeObjectParameters struct { + Name string + IdType string + Level sdk.ParameterType + AdditionalImports []string + Parameters []SnowflakeParameter +} + +func (p SnowflakeObjectParameters) ObjectName() string { + return p.Name +} + +type SnowflakeParameter struct { + ParameterName string + ParameterType string + DefaultValue string + DefaultLevel string +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go new file mode 100644 index 0000000000..b7073aeebb --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -0,0 +1,109 @@ +//go:build exclude + +package main + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +func main() { + genhelpers.NewGenerator( + getAllSnowflakeObjectParameters, + gen.ModelFromSnowflakeObjectParameters, + getFilename, + gen.AllTemplates, + ). + RunAndHandleOsReturn() +} + +func getAllSnowflakeObjectParameters() []gen.SnowflakeObjectParameters { + return allObjectsParameters +} + +func getFilename(_ gen.SnowflakeObjectParameters, model gen.SnowflakeObjectParametersAssertionsModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_parameters_snowflake" + "_gen.go" +} + +// TODO [SNOW-1501905]: use SDK definition after parameters rework (+ preprocessing here) +var allObjectsParameters = []gen.SnowflakeObjectParameters{ + { + Name: "User", + IdType: "sdk.AccountObjectIdentifier", + Level: sdk.ParameterTypeUser, + Parameters: []gen.SnowflakeParameter{ + {ParameterName: string(sdk.UserParameterEnableUnredactedQuerySyntaxError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterNetworkPolicy), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterPreventUnloadToInternalStages), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterAbortDetachedQuery), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterAutocommit), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterBinaryInputFormat), ParameterType: "sdk.BinaryInputFormat", DefaultValue: "sdk.BinaryInputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterBinaryOutputFormat), ParameterType: "sdk.BinaryOutputFormat", DefaultValue: "sdk.BinaryOutputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientMemoryLimit), ParameterType: "int", DefaultValue: "1536", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientMetadataRequestUseConnectionCtx), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientPrefetchThreads), ParameterType: "int", DefaultValue: "4", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientResultChunkSize), ParameterType: "int", DefaultValue: "160", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientResultColumnCaseInsensitive), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientSessionKeepAlive), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency), ParameterType: "int", DefaultValue: "3600", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientTimestampTypeMapping), ParameterType: "sdk.ClientTimestampTypeMapping", DefaultValue: "sdk.ClientTimestampTypeMappingLtz", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterDateInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterDateOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterEnableUnloadPhysicalTypeOptimization), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterErrorOnNondeterministicMerge), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterErrorOnNondeterministicUpdate), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterGeographyOutputFormat), ParameterType: "sdk.GeographyOutputFormat", DefaultValue: "sdk.GeographyOutputFormatGeoJSON", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterGeometryOutputFormat), ParameterType: "sdk.GeometryOutputFormat", DefaultValue: "sdk.GeometryOutputFormatGeoJSON", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterJdbcTreatDecimalAsInt), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterJdbcTreatTimestampNtzAsUtc), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterJdbcUseSessionTimezone), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterJsonIndent), ParameterType: "int", DefaultValue: "2", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterLockTimeout), ParameterType: "int", DefaultValue: "43200", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterLogLevel), ParameterType: "sdk.LogLevel", DefaultValue: "sdk.LogLevelOff", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterMultiStatementCount), ParameterType: "int", DefaultValue: "1", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterNoorderSequenceAsDefault), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterOdbcTreatDecimalAsInt), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterQueryTag), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterRowsPerResultset), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterS3StageVpceDnsName), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterSearchPath), ParameterType: "string", DefaultValue: "$current, $public", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterSimulatedDataSharingConsumer), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterStatementQueuedTimeoutInSeconds), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterStatementTimeoutInSeconds), ParameterType: "int", DefaultValue: "172800", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterStrictJsonOutput), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampDayIsAlways24h), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampLtzOutputFormat), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampNtzOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD HH24:MI:SS.FF3", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampTypeMapping), ParameterType: "sdk.TimestampTypeMapping", DefaultValue: "sdk.TimestampTypeMappingNtz", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampTzOutputFormat), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimezone), ParameterType: "string", DefaultValue: "America/Los_Angeles", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimeInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimeOutputFormat), ParameterType: "string", DefaultValue: "HH24:MI:SS", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTraceLevel), ParameterType: "sdk.TraceLevel", DefaultValue: "sdk.TraceLevelOff", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTransactionAbortOnError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterTransactionDefaultIsolationLevel), ParameterType: "sdk.TransactionDefaultIsolationLevel", DefaultValue: "sdk.TransactionDefaultIsolationLevelReadCommitted", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTwoDigitCenturyStart), ParameterType: "int", DefaultValue: "1970", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + // TODO: quick workaround for now: lowercase for ignore in snowflake by default but uppercase for FAIL + {ParameterName: string(sdk.UserParameterUnsupportedDdlAction), ParameterType: "sdk.UnsupportedDDLAction", DefaultValue: "sdk.UnsupportedDDLAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore)))", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterUseCachedResult), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterWeekOfYearPolicy), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterWeekStart), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + }, + // for the quickfix above + AdditionalImports: []string{"strings"}, + }, + { + Name: "Warehouse", + IdType: "sdk.AccountObjectIdentifier", + Level: sdk.ParameterTypeWarehouse, + Parameters: []gen.SnowflakeParameter{ + {ParameterName: string(sdk.WarehouseParameterMaxConcurrencyLevel), ParameterType: "int", DefaultValue: "8", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.WarehouseParameterStatementTimeoutInSeconds), ParameterType: "int", DefaultValue: "172800", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + }, + }, +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go new file mode 100644 index 0000000000..a6053a4686 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -0,0 +1,77 @@ +package gen + +import ( + "fmt" + "os" + "strings" +) + +// TODO [SNOW-1501905]: extract to commons? +type PreambleModel struct { + PackageName string + AdditionalStandardImports []string +} + +type SnowflakeObjectParametersAssertionsModel struct { + Name string + IdType string + Parameters []ParameterAssertionModel + PreambleModel +} + +type ParameterAssertionModel struct { + Name string + Type string + DefaultValue string + DefaultLevel string + AssertionCreator string +} + +func (m SnowflakeObjectParametersAssertionsModel) SomeFunc() { +} + +func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjectParameters) SnowflakeObjectParametersAssertionsModel { + parameters := make([]ParameterAssertionModel, len(snowflakeObjectParameters.Parameters)) + for idx, p := range snowflakeObjectParameters.Parameters { + // TODO [SNOW-1501905]: get a runtime name for the assertion creator + var assertionCreator string + switch { + case p.ParameterType == "bool": + assertionCreator = "SnowflakeParameterBoolValueSet" + case p.ParameterType == "int": + assertionCreator = "SnowflakeParameterIntValueSet" + case p.ParameterType == "string": + assertionCreator = "SnowflakeParameterValueSet" + case strings.HasPrefix(p.ParameterType, "sdk."): + assertionCreator = "SnowflakeParameterStringUnderlyingValueSet" + // TODO [SNOW-1501905]: handle other types if needed + default: + assertionCreator = "SnowflakeParameterValueSet" + } + + defaultValue := p.DefaultValue + // string has to be wrapped in double quotes; all other values are passed explicitly + if p.ParameterType == "string" { + defaultValue = fmt.Sprintf(`"%s"`, defaultValue) + } + + parameters[idx] = ParameterAssertionModel{ + Name: p.ParameterName, + Type: p.ParameterType, + DefaultValue: defaultValue, + DefaultLevel: p.DefaultLevel, + AssertionCreator: assertionCreator, + } + } + + packageWithGenerateDirective := os.Getenv("GOPACKAGE") + return SnowflakeObjectParametersAssertionsModel{ + Name: snowflakeObjectParameters.ObjectName(), + IdType: snowflakeObjectParameters.IdType, + Parameters: parameters, + PreambleModel: PreambleModel{ + PackageName: packageWithGenerateDirective, + AdditionalStandardImports: snowflakeObjectParameters.AdditionalImports, + }, + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go new file mode 100644 index 0000000000..195ba47362 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -0,0 +1,45 @@ +package gen + +import ( + "text/template" + + _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + + //go:embed templates/definition.tmpl + definitionTemplateContent string + DefinitionTemplate, _ = template.New("definitionTemplate").Parse(definitionTemplateContent) + + //go:embed templates/generic_checks.tmpl + genericChecksTemplateContent string + GenericChecksTemplate, _ = template.New("genericChecksTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + )).Parse(genericChecksTemplateContent) + + //go:embed templates/aggregated_generic_checks.tmpl + aggregatedGenericChecksTemplateContent string + AggregatedGenericChecksTemplate, _ = template.New("aggregatedGenericChecksTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + genhelpers.SnakeCaseToCamel, + genhelpers.IsLastItem, + )).Parse(aggregatedGenericChecksTemplateContent) + + //go:embed templates/specific_checks.tmpl + specificChecksTemplateContent string + SpecificChecksTemplate, _ = template.New("specificChecksTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + genhelpers.SnakeCaseToCamel, + )).Parse(specificChecksTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, DefinitionTemplate, GenericChecksTemplate, AggregatedGenericChecksTemplate, SpecificChecksTemplate} +) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl new file mode 100644 index 0000000000..4dded2f186 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl @@ -0,0 +1,27 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen.SnowflakeObjectParametersAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sParametersAssert" -}} +{{- $sdkParameterName := .Name | printf "sdk.%sParameter" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $assertVar := FirstLetter $nameLowerCase -}} +{{- $parametersCount := len .Parameters }} +/////////////////////////////// +// Aggregated generic checks // +/////////////////////////////// + +// HasAllDefaults checks if all the parameters: +// - have a default value by comparing current value of the sdk.Parameter with its default +// - have an expected level +func ({{ $assertVar }} *{{ $assertName }}) HasAllDefaults() *{{ $assertName }} { + return {{ $assertVar }}. + {{- range $index, $item := .Parameters }} + HasDefaultParameterValueOnLevel({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}, {{ .DefaultLevel }}){{ if not (IsLastItem $index $parametersCount) }}.{{ end }} + {{- end }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasAllDefaultsExplicit() *{{ $assertName }} { + return {{ $assertVar }}. + {{- range $index, $item := .Parameters }} + HasDefault{{ SnakeCaseToCamel .Name }}ValueExplicit(){{ if not (IsLastItem $index $parametersCount) }}.{{ end }} + {{- end }} +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/definition.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/definition.tmpl new file mode 100644 index 0000000000..41f421bc19 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/definition.tmpl @@ -0,0 +1,20 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen.SnowflakeObjectParametersAssertionsModel*/ -}} + +{{ $assertName := .Name | printf "%sParametersAssert" }} +type {{ $assertName }} struct { + *assert.SnowflakeParametersAssert[{{ .IdType }}] +} + +func {{ .Name }}Parameters(t *testing.T, id {{ .IdType }}) *{{ $assertName }} { + t.Helper() + return &{{ $assertName }}{ + assert.NewSnowflakeParametersAssertWithProvider(id, sdk.ObjectType{{ .Name }}, acc.TestClient().Parameter.Show{{ .Name }}Parameters), + } +} + +func {{ .Name }}ParametersPrefetched(t *testing.T, id {{ .IdType }}, parameters []*sdk.Parameter) *{{ $assertName }} { + t.Helper() + return &{{ $assertName }}{ + assert.NewSnowflakeParametersAssertWithParameters(id, sdk.ObjectType{{ .Name }}, parameters), + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl new file mode 100644 index 0000000000..4fd4a771c4 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl @@ -0,0 +1,34 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen.SnowflakeObjectParametersAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sParametersAssert" -}} +{{- $sdkParameterName := .Name | printf "sdk.%sParameter" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $assertVar := FirstLetter $nameLowerCase }} +////////////////////////////// +// Generic parameter checks // +////////////////////////////// + +func ({{ $assertVar }} *{{ $assertName }}) HasBoolParameterValue(parameterName {{ $sdkParameterName }}, expected bool) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterBoolValueSet(parameterName, expected)) + return {{ $assertVar }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasIntParameterValue(parameterName {{ $sdkParameterName }}, expected int) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterIntValueSet(parameterName, expected)) + return {{ $assertVar }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasStringParameterValue(parameterName {{ $sdkParameterName }}, expected string) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterValueSet(parameterName, expected)) + return {{ $assertVar }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasDefaultParameterValue(parameterName {{ $sdkParameterName }}) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterDefaultValueSet(parameterName)) + return {{ $assertVar }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasDefaultParameterValueOnLevel(parameterName {{ $sdkParameterName }}, parameterType sdk.ParameterType) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) + return {{ $assertVar }} +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl new file mode 100644 index 0000000000..4e8c6394a8 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl @@ -0,0 +1,17 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen.PreambleModel*/ -}} + +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package {{ .PackageName }} + +import ( + "testing" + {{- range .AdditionalStandardImports }} + "{{- . }}" + {{- end }} + + 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/sdk" +) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl new file mode 100644 index 0000000000..187c9e147d --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl @@ -0,0 +1,51 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen.SnowflakeObjectParametersAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sParametersAssert" -}} +{{- $sdkParameterName := .Name | printf "sdk.%sParameter" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $assertVar := FirstLetter $nameLowerCase }} +//////////////////////////// +// Parameter value checks // +//////////////////////////// + +{{ range .Parameters -}} + func ({{ $assertVar }} *{{ $assertName }}) Has{{ SnakeCaseToCamel .Name }}(expected {{ .Type }}) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.{{ .AssertionCreator }}({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}, expected)) + return {{ $assertVar }} + } + +{{ end -}} + +//////////////////////////// +// Parameter level checks // +//////////////////////////// + +{{ range .Parameters -}} + func ({{ $assertVar }} *{{ $assertName }}) Has{{ SnakeCaseToCamel .Name }}Level(expected sdk.ParameterType) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterLevelSet({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}, expected)) + return {{ $assertVar }} + } + +{{ end -}} + +//////////////////////////////////// +// Parameter default value checks // +//////////////////////////////////// + +{{ range .Parameters -}} + func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}Value() *{{ $assertName }} { + return {{ $assertVar }}.HasDefaultParameterValue({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}) + } + +{{ end -}} + +///////////////////////////////////////////// +// Parameter explicit default value checks // +///////////////////////////////////////////// + +{{ range .Parameters -}} + func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}ValueExplicit() *{{ $assertName }} { + return {{ $assertVar }}.Has{{ SnakeCaseToCamel .Name }}({{ .DefaultValue }}) + } + +{{ end }} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/generate.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/generate.go new file mode 100644 index 0000000000..cf2893dc6d --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/generate.go @@ -0,0 +1,3 @@ +package objectparametersassert + +//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go new file mode 100644 index 0000000000..a8e1727714 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go @@ -0,0 +1,1251 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package objectparametersassert + +import ( + "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/sdk" +) + +type UserParametersAssert struct { + *assert.SnowflakeParametersAssert[sdk.AccountObjectIdentifier] +} + +func UserParameters(t *testing.T, id sdk.AccountObjectIdentifier) *UserParametersAssert { + t.Helper() + return &UserParametersAssert{ + assert.NewSnowflakeParametersAssertWithProvider(id, sdk.ObjectTypeUser, acc.TestClient().Parameter.ShowUserParameters), + } +} + +func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, parameters []*sdk.Parameter) *UserParametersAssert { + t.Helper() + return &UserParametersAssert{ + assert.NewSnowflakeParametersAssertWithParameters(id, sdk.ObjectTypeUser, parameters), + } +} + +////////////////////////////// +// Generic parameter checks // +////////////////////////////// + +func (u *UserParametersAssert) HasBoolParameterValue(parameterName sdk.UserParameter, expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(parameterName, expected)) + return u +} + +func (u *UserParametersAssert) HasIntParameterValue(parameterName sdk.UserParameter, expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(parameterName, expected)) + return u +} + +func (u *UserParametersAssert) HasStringParameterValue(parameterName sdk.UserParameter, expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(parameterName, expected)) + return u +} + +func (u *UserParametersAssert) HasDefaultParameterValue(parameterName sdk.UserParameter) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterDefaultValueSet(parameterName)) + return u +} + +func (u *UserParametersAssert) HasDefaultParameterValueOnLevel(parameterName sdk.UserParameter, parameterType sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) + return u +} + +/////////////////////////////// +// Aggregated generic checks // +/////////////////////////////// + +// HasAllDefaults checks if all the parameters: +// - have a default value by comparing current value of the sdk.Parameter with its default +// - have an expected level +func (u *UserParametersAssert) HasAllDefaults() *UserParametersAssert { + return u. + HasDefaultParameterValueOnLevel(sdk.UserParameterEnableUnredactedQuerySyntaxError, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterNetworkPolicy, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterPreventUnloadToInternalStages, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterAbortDetachedQuery, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterAutocommit, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.UserParameterBinaryInputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterBinaryOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterClientMemoryLimit, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterClientMetadataRequestUseConnectionCtx, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterClientPrefetchThreads, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterClientResultChunkSize, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterClientResultColumnCaseInsensitive, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterClientSessionKeepAlive, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterClientTimestampTypeMapping, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterDateInputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterDateOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterErrorOnNondeterministicMerge, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterErrorOnNondeterministicUpdate, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterGeographyOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterGeometryOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterJdbcTreatDecimalAsInt, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterJdbcUseSessionTimezone, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterJsonIndent, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterLockTimeout, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterLogLevel, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterMultiStatementCount, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterNoorderSequenceAsDefault, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterOdbcTreatDecimalAsInt, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterQueryTag, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterQuotedIdentifiersIgnoreCase, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.UserParameterRowsPerResultset, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterS3StageVpceDnsName, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterSearchPath, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterSimulatedDataSharingConsumer, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterStatementQueuedTimeoutInSeconds, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterStatementTimeoutInSeconds, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterStrictJsonOutput, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampDayIsAlways24h, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampInputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampLtzOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampNtzOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampTypeMapping, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampTzOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimezone, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimeInputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimeOutputFormat, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTraceLevel, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTransactionAbortOnError, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.UserParameterTransactionDefaultIsolationLevel, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterTwoDigitCenturyStart, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterUnsupportedDdlAction, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterUseCachedResult, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterWeekOfYearPolicy, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.UserParameterWeekStart, sdk.ParameterTypeSnowflakeDefault) +} + +func (u *UserParametersAssert) HasAllDefaultsExplicit() *UserParametersAssert { + return u. + HasDefaultEnableUnredactedQuerySyntaxErrorValueExplicit(). + HasDefaultNetworkPolicyValueExplicit(). + HasDefaultPreventUnloadToInternalStagesValueExplicit(). + HasDefaultAbortDetachedQueryValueExplicit(). + HasDefaultAutocommitValueExplicit(). + HasDefaultBinaryInputFormatValueExplicit(). + HasDefaultBinaryOutputFormatValueExplicit(). + HasDefaultClientMemoryLimitValueExplicit(). + HasDefaultClientMetadataRequestUseConnectionCtxValueExplicit(). + HasDefaultClientPrefetchThreadsValueExplicit(). + HasDefaultClientResultChunkSizeValueExplicit(). + HasDefaultClientResultColumnCaseInsensitiveValueExplicit(). + HasDefaultClientSessionKeepAliveValueExplicit(). + HasDefaultClientSessionKeepAliveHeartbeatFrequencyValueExplicit(). + HasDefaultClientTimestampTypeMappingValueExplicit(). + HasDefaultDateInputFormatValueExplicit(). + HasDefaultDateOutputFormatValueExplicit(). + HasDefaultEnableUnloadPhysicalTypeOptimizationValueExplicit(). + HasDefaultErrorOnNondeterministicMergeValueExplicit(). + HasDefaultErrorOnNondeterministicUpdateValueExplicit(). + HasDefaultGeographyOutputFormatValueExplicit(). + HasDefaultGeometryOutputFormatValueExplicit(). + HasDefaultJdbcTreatDecimalAsIntValueExplicit(). + HasDefaultJdbcTreatTimestampNtzAsUtcValueExplicit(). + HasDefaultJdbcUseSessionTimezoneValueExplicit(). + HasDefaultJsonIndentValueExplicit(). + HasDefaultLockTimeoutValueExplicit(). + HasDefaultLogLevelValueExplicit(). + HasDefaultMultiStatementCountValueExplicit(). + HasDefaultNoorderSequenceAsDefaultValueExplicit(). + HasDefaultOdbcTreatDecimalAsIntValueExplicit(). + HasDefaultQueryTagValueExplicit(). + HasDefaultQuotedIdentifiersIgnoreCaseValueExplicit(). + HasDefaultRowsPerResultsetValueExplicit(). + HasDefaultS3StageVpceDnsNameValueExplicit(). + HasDefaultSearchPathValueExplicit(). + HasDefaultSimulatedDataSharingConsumerValueExplicit(). + HasDefaultStatementQueuedTimeoutInSecondsValueExplicit(). + HasDefaultStatementTimeoutInSecondsValueExplicit(). + HasDefaultStrictJsonOutputValueExplicit(). + HasDefaultTimestampDayIsAlways24hValueExplicit(). + HasDefaultTimestampInputFormatValueExplicit(). + HasDefaultTimestampLtzOutputFormatValueExplicit(). + HasDefaultTimestampNtzOutputFormatValueExplicit(). + HasDefaultTimestampOutputFormatValueExplicit(). + HasDefaultTimestampTypeMappingValueExplicit(). + HasDefaultTimestampTzOutputFormatValueExplicit(). + HasDefaultTimezoneValueExplicit(). + HasDefaultTimeInputFormatValueExplicit(). + HasDefaultTimeOutputFormatValueExplicit(). + HasDefaultTraceLevelValueExplicit(). + HasDefaultTransactionAbortOnErrorValueExplicit(). + HasDefaultTransactionDefaultIsolationLevelValueExplicit(). + HasDefaultTwoDigitCenturyStartValueExplicit(). + HasDefaultUnsupportedDdlActionValueExplicit(). + HasDefaultUseCachedResultValueExplicit(). + HasDefaultWeekOfYearPolicyValueExplicit(). + HasDefaultWeekStartValueExplicit() +} + +//////////////////////////// +// Parameter value checks // +//////////////////////////// + +func (u *UserParametersAssert) HasEnableUnredactedQuerySyntaxError(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) + return u +} + +func (u *UserParametersAssert) HasNetworkPolicy(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterNetworkPolicy, expected)) + return u +} + +func (u *UserParametersAssert) HasPreventUnloadToInternalStages(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) + return u +} + +func (u *UserParametersAssert) HasAbortDetachedQuery(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterAbortDetachedQuery, expected)) + return u +} + +func (u *UserParametersAssert) HasAutocommit(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterAutocommit, expected)) + return u +} + +func (u *UserParametersAssert) HasBinaryInputFormat(expected sdk.BinaryInputFormat) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryInputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasBinaryOutputFormat(expected sdk.BinaryOutputFormat) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasClientMemoryLimit(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterClientMemoryLimit, expected)) + return u +} + +func (u *UserParametersAssert) HasClientMetadataRequestUseConnectionCtx(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) + return u +} + +func (u *UserParametersAssert) HasClientPrefetchThreads(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterClientPrefetchThreads, expected)) + return u +} + +func (u *UserParametersAssert) HasClientResultChunkSize(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterClientResultChunkSize, expected)) + return u +} + +func (u *UserParametersAssert) HasClientResultColumnCaseInsensitive(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) + return u +} + +func (u *UserParametersAssert) HasClientSessionKeepAlive(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterClientSessionKeepAlive, expected)) + return u +} + +func (u *UserParametersAssert) HasClientSessionKeepAliveHeartbeatFrequency(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) + return u +} + +func (u *UserParametersAssert) HasClientTimestampTypeMapping(expected sdk.ClientTimestampTypeMapping) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterClientTimestampTypeMapping, expected)) + return u +} + +func (u *UserParametersAssert) HasDateInputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterDateInputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasDateOutputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterDateOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasEnableUnloadPhysicalTypeOptimization(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) + return u +} + +func (u *UserParametersAssert) HasErrorOnNondeterministicMerge(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) + return u +} + +func (u *UserParametersAssert) HasErrorOnNondeterministicUpdate(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) + return u +} + +func (u *UserParametersAssert) HasGeographyOutputFormat(expected sdk.GeographyOutputFormat) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeographyOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasGeometryOutputFormat(expected sdk.GeometryOutputFormat) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeometryOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasJdbcTreatDecimalAsInt(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) + return u +} + +func (u *UserParametersAssert) HasJdbcTreatTimestampNtzAsUtc(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) + return u +} + +func (u *UserParametersAssert) HasJdbcUseSessionTimezone(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) + return u +} + +func (u *UserParametersAssert) HasJsonIndent(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterJsonIndent, expected)) + return u +} + +func (u *UserParametersAssert) HasLockTimeout(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterLockTimeout, expected)) + return u +} + +func (u *UserParametersAssert) HasLogLevel(expected sdk.LogLevel) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterLogLevel, expected)) + return u +} + +func (u *UserParametersAssert) HasMultiStatementCount(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterMultiStatementCount, expected)) + return u +} + +func (u *UserParametersAssert) HasNoorderSequenceAsDefault(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) + return u +} + +func (u *UserParametersAssert) HasOdbcTreatDecimalAsInt(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) + return u +} + +func (u *UserParametersAssert) HasQueryTag(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterQueryTag, expected)) + return u +} + +func (u *UserParametersAssert) HasQuotedIdentifiersIgnoreCase(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) + return u +} + +func (u *UserParametersAssert) HasRowsPerResultset(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterRowsPerResultset, expected)) + return u +} + +func (u *UserParametersAssert) HasS3StageVpceDnsName(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterS3StageVpceDnsName, expected)) + return u +} + +func (u *UserParametersAssert) HasSearchPath(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterSearchPath, expected)) + return u +} + +func (u *UserParametersAssert) HasSimulatedDataSharingConsumer(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) + return u +} + +func (u *UserParametersAssert) HasStatementQueuedTimeoutInSeconds(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) + return u +} + +func (u *UserParametersAssert) HasStatementTimeoutInSeconds(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) + return u +} + +func (u *UserParametersAssert) HasStrictJsonOutput(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterStrictJsonOutput, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampDayIsAlways24h(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampInputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterTimestampInputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampLtzOutputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampNtzOutputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampOutputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterTimestampOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampTypeMapping(expected sdk.TimestampTypeMapping) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTimestampTypeMapping, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampTzOutputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterTimestampTzOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimezone(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterTimezone, expected)) + return u +} + +func (u *UserParametersAssert) HasTimeInputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterTimeInputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimeOutputFormat(expected string) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterValueSet(sdk.UserParameterTimeOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTraceLevel(expected sdk.TraceLevel) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTraceLevel, expected)) + return u +} + +func (u *UserParametersAssert) HasTransactionAbortOnError(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterTransactionAbortOnError, expected)) + return u +} + +func (u *UserParametersAssert) HasTransactionDefaultIsolationLevel(expected sdk.TransactionDefaultIsolationLevel) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) + return u +} + +func (u *UserParametersAssert) HasTwoDigitCenturyStart(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterTwoDigitCenturyStart, expected)) + return u +} + +func (u *UserParametersAssert) HasUnsupportedDdlAction(expected sdk.UnsupportedDDLAction) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterUnsupportedDdlAction, expected)) + return u +} + +func (u *UserParametersAssert) HasUseCachedResult(expected bool) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterBoolValueSet(sdk.UserParameterUseCachedResult, expected)) + return u +} + +func (u *UserParametersAssert) HasWeekOfYearPolicy(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterWeekOfYearPolicy, expected)) + return u +} + +func (u *UserParametersAssert) HasWeekStart(expected int) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.UserParameterWeekStart, expected)) + return u +} + +//////////////////////////// +// Parameter level checks // +//////////////////////////// + +func (u *UserParametersAssert) HasEnableUnredactedQuerySyntaxErrorLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) + return u +} + +func (u *UserParametersAssert) HasNetworkPolicyLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterNetworkPolicy, expected)) + return u +} + +func (u *UserParametersAssert) HasPreventUnloadToInternalStagesLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) + return u +} + +func (u *UserParametersAssert) HasAbortDetachedQueryLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterAbortDetachedQuery, expected)) + return u +} + +func (u *UserParametersAssert) HasAutocommitLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterAutocommit, expected)) + return u +} + +func (u *UserParametersAssert) HasBinaryInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterBinaryInputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasBinaryOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterBinaryOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasClientMemoryLimitLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterClientMemoryLimit, expected)) + return u +} + +func (u *UserParametersAssert) HasClientMetadataRequestUseConnectionCtxLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) + return u +} + +func (u *UserParametersAssert) HasClientPrefetchThreadsLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterClientPrefetchThreads, expected)) + return u +} + +func (u *UserParametersAssert) HasClientResultChunkSizeLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterClientResultChunkSize, expected)) + return u +} + +func (u *UserParametersAssert) HasClientResultColumnCaseInsensitiveLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) + return u +} + +func (u *UserParametersAssert) HasClientSessionKeepAliveLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAlive, expected)) + return u +} + +func (u *UserParametersAssert) HasClientSessionKeepAliveHeartbeatFrequencyLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) + return u +} + +func (u *UserParametersAssert) HasClientTimestampTypeMappingLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterClientTimestampTypeMapping, expected)) + return u +} + +func (u *UserParametersAssert) HasDateInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterDateInputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasDateOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterDateOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasEnableUnloadPhysicalTypeOptimizationLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) + return u +} + +func (u *UserParametersAssert) HasErrorOnNondeterministicMergeLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) + return u +} + +func (u *UserParametersAssert) HasErrorOnNondeterministicUpdateLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) + return u +} + +func (u *UserParametersAssert) HasGeographyOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterGeographyOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasGeometryOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterGeometryOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasJdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) + return u +} + +func (u *UserParametersAssert) HasJdbcTreatTimestampNtzAsUtcLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) + return u +} + +func (u *UserParametersAssert) HasJdbcUseSessionTimezoneLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) + return u +} + +func (u *UserParametersAssert) HasJsonIndentLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterJsonIndent, expected)) + return u +} + +func (u *UserParametersAssert) HasLockTimeoutLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterLockTimeout, expected)) + return u +} + +func (u *UserParametersAssert) HasLogLevelLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterLogLevel, expected)) + return u +} + +func (u *UserParametersAssert) HasMultiStatementCountLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterMultiStatementCount, expected)) + return u +} + +func (u *UserParametersAssert) HasNoorderSequenceAsDefaultLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) + return u +} + +func (u *UserParametersAssert) HasOdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) + return u +} + +func (u *UserParametersAssert) HasQueryTagLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterQueryTag, expected)) + return u +} + +func (u *UserParametersAssert) HasQuotedIdentifiersIgnoreCaseLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) + return u +} + +func (u *UserParametersAssert) HasRowsPerResultsetLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterRowsPerResultset, expected)) + return u +} + +func (u *UserParametersAssert) HasS3StageVpceDnsNameLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterS3StageVpceDnsName, expected)) + return u +} + +func (u *UserParametersAssert) HasSearchPathLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterSearchPath, expected)) + return u +} + +func (u *UserParametersAssert) HasSimulatedDataSharingConsumerLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) + return u +} + +func (u *UserParametersAssert) HasStatementQueuedTimeoutInSecondsLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) + return u +} + +func (u *UserParametersAssert) HasStatementTimeoutInSecondsLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) + return u +} + +func (u *UserParametersAssert) HasStrictJsonOutputLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterStrictJsonOutput, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampDayIsAlways24hLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimestampInputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampLtzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampNtzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimestampOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampTypeMappingLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimestampTypeMapping, expected)) + return u +} + +func (u *UserParametersAssert) HasTimestampTzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimestampTzOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimezoneLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimezone, expected)) + return u +} + +func (u *UserParametersAssert) HasTimeInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimeInputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTimeOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTimeOutputFormat, expected)) + return u +} + +func (u *UserParametersAssert) HasTraceLevelLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTraceLevel, expected)) + return u +} + +func (u *UserParametersAssert) HasTransactionAbortOnErrorLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTransactionAbortOnError, expected)) + return u +} + +func (u *UserParametersAssert) HasTransactionDefaultIsolationLevelLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) + return u +} + +func (u *UserParametersAssert) HasTwoDigitCenturyStartLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterTwoDigitCenturyStart, expected)) + return u +} + +func (u *UserParametersAssert) HasUnsupportedDdlActionLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterUnsupportedDdlAction, expected)) + return u +} + +func (u *UserParametersAssert) HasUseCachedResultLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterUseCachedResult, expected)) + return u +} + +func (u *UserParametersAssert) HasWeekOfYearPolicyLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterWeekOfYearPolicy, expected)) + return u +} + +func (u *UserParametersAssert) HasWeekStartLevel(expected sdk.ParameterType) *UserParametersAssert { + u.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.UserParameterWeekStart, expected)) + return u +} + +//////////////////////////////////// +// Parameter default value checks // +//////////////////////////////////// + +func (u *UserParametersAssert) HasDefaultEnableUnredactedQuerySyntaxErrorValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterEnableUnredactedQuerySyntaxError) +} + +func (u *UserParametersAssert) HasDefaultNetworkPolicyValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterNetworkPolicy) +} + +func (u *UserParametersAssert) HasDefaultPreventUnloadToInternalStagesValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterPreventUnloadToInternalStages) +} + +func (u *UserParametersAssert) HasDefaultAbortDetachedQueryValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterAbortDetachedQuery) +} + +func (u *UserParametersAssert) HasDefaultAutocommitValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterAutocommit) +} + +func (u *UserParametersAssert) HasDefaultBinaryInputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterBinaryInputFormat) +} + +func (u *UserParametersAssert) HasDefaultBinaryOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterBinaryOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultClientMemoryLimitValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterClientMemoryLimit) +} + +func (u *UserParametersAssert) HasDefaultClientMetadataRequestUseConnectionCtxValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterClientMetadataRequestUseConnectionCtx) +} + +func (u *UserParametersAssert) HasDefaultClientPrefetchThreadsValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterClientPrefetchThreads) +} + +func (u *UserParametersAssert) HasDefaultClientResultChunkSizeValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterClientResultChunkSize) +} + +func (u *UserParametersAssert) HasDefaultClientResultColumnCaseInsensitiveValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterClientResultColumnCaseInsensitive) +} + +func (u *UserParametersAssert) HasDefaultClientSessionKeepAliveValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterClientSessionKeepAlive) +} + +func (u *UserParametersAssert) HasDefaultClientSessionKeepAliveHeartbeatFrequencyValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency) +} + +func (u *UserParametersAssert) HasDefaultClientTimestampTypeMappingValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterClientTimestampTypeMapping) +} + +func (u *UserParametersAssert) HasDefaultDateInputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterDateInputFormat) +} + +func (u *UserParametersAssert) HasDefaultDateOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterDateOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultEnableUnloadPhysicalTypeOptimizationValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterEnableUnloadPhysicalTypeOptimization) +} + +func (u *UserParametersAssert) HasDefaultErrorOnNondeterministicMergeValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterErrorOnNondeterministicMerge) +} + +func (u *UserParametersAssert) HasDefaultErrorOnNondeterministicUpdateValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterErrorOnNondeterministicUpdate) +} + +func (u *UserParametersAssert) HasDefaultGeographyOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterGeographyOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultGeometryOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterGeometryOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultJdbcTreatDecimalAsIntValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterJdbcTreatDecimalAsInt) +} + +func (u *UserParametersAssert) HasDefaultJdbcTreatTimestampNtzAsUtcValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterJdbcTreatTimestampNtzAsUtc) +} + +func (u *UserParametersAssert) HasDefaultJdbcUseSessionTimezoneValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterJdbcUseSessionTimezone) +} + +func (u *UserParametersAssert) HasDefaultJsonIndentValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterJsonIndent) +} + +func (u *UserParametersAssert) HasDefaultLockTimeoutValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterLockTimeout) +} + +func (u *UserParametersAssert) HasDefaultLogLevelValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterLogLevel) +} + +func (u *UserParametersAssert) HasDefaultMultiStatementCountValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterMultiStatementCount) +} + +func (u *UserParametersAssert) HasDefaultNoorderSequenceAsDefaultValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterNoorderSequenceAsDefault) +} + +func (u *UserParametersAssert) HasDefaultOdbcTreatDecimalAsIntValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterOdbcTreatDecimalAsInt) +} + +func (u *UserParametersAssert) HasDefaultQueryTagValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterQueryTag) +} + +func (u *UserParametersAssert) HasDefaultQuotedIdentifiersIgnoreCaseValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterQuotedIdentifiersIgnoreCase) +} + +func (u *UserParametersAssert) HasDefaultRowsPerResultsetValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterRowsPerResultset) +} + +func (u *UserParametersAssert) HasDefaultS3StageVpceDnsNameValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterS3StageVpceDnsName) +} + +func (u *UserParametersAssert) HasDefaultSearchPathValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterSearchPath) +} + +func (u *UserParametersAssert) HasDefaultSimulatedDataSharingConsumerValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterSimulatedDataSharingConsumer) +} + +func (u *UserParametersAssert) HasDefaultStatementQueuedTimeoutInSecondsValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterStatementQueuedTimeoutInSeconds) +} + +func (u *UserParametersAssert) HasDefaultStatementTimeoutInSecondsValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterStatementTimeoutInSeconds) +} + +func (u *UserParametersAssert) HasDefaultStrictJsonOutputValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterStrictJsonOutput) +} + +func (u *UserParametersAssert) HasDefaultTimestampDayIsAlways24hValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimestampDayIsAlways24h) +} + +func (u *UserParametersAssert) HasDefaultTimestampInputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimestampInputFormat) +} + +func (u *UserParametersAssert) HasDefaultTimestampLtzOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimestampLtzOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultTimestampNtzOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimestampNtzOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultTimestampOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimestampOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultTimestampTypeMappingValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimestampTypeMapping) +} + +func (u *UserParametersAssert) HasDefaultTimestampTzOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimestampTzOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultTimezoneValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimezone) +} + +func (u *UserParametersAssert) HasDefaultTimeInputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimeInputFormat) +} + +func (u *UserParametersAssert) HasDefaultTimeOutputFormatValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTimeOutputFormat) +} + +func (u *UserParametersAssert) HasDefaultTraceLevelValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTraceLevel) +} + +func (u *UserParametersAssert) HasDefaultTransactionAbortOnErrorValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTransactionAbortOnError) +} + +func (u *UserParametersAssert) HasDefaultTransactionDefaultIsolationLevelValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTransactionDefaultIsolationLevel) +} + +func (u *UserParametersAssert) HasDefaultTwoDigitCenturyStartValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterTwoDigitCenturyStart) +} + +func (u *UserParametersAssert) HasDefaultUnsupportedDdlActionValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterUnsupportedDdlAction) +} + +func (u *UserParametersAssert) HasDefaultUseCachedResultValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterUseCachedResult) +} + +func (u *UserParametersAssert) HasDefaultWeekOfYearPolicyValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterWeekOfYearPolicy) +} + +func (u *UserParametersAssert) HasDefaultWeekStartValue() *UserParametersAssert { + return u.HasDefaultParameterValue(sdk.UserParameterWeekStart) +} + +///////////////////////////////////////////// +// Parameter explicit default value checks // +///////////////////////////////////////////// + +func (u *UserParametersAssert) HasDefaultEnableUnredactedQuerySyntaxErrorValueExplicit() *UserParametersAssert { + return u.HasEnableUnredactedQuerySyntaxError(false) +} + +func (u *UserParametersAssert) HasDefaultNetworkPolicyValueExplicit() *UserParametersAssert { + return u.HasNetworkPolicy("") +} + +func (u *UserParametersAssert) HasDefaultPreventUnloadToInternalStagesValueExplicit() *UserParametersAssert { + return u.HasPreventUnloadToInternalStages(false) +} + +func (u *UserParametersAssert) HasDefaultAbortDetachedQueryValueExplicit() *UserParametersAssert { + return u.HasAbortDetachedQuery(false) +} + +func (u *UserParametersAssert) HasDefaultAutocommitValueExplicit() *UserParametersAssert { + return u.HasAutocommit(true) +} + +func (u *UserParametersAssert) HasDefaultBinaryInputFormatValueExplicit() *UserParametersAssert { + return u.HasBinaryInputFormat(sdk.BinaryInputFormatHex) +} + +func (u *UserParametersAssert) HasDefaultBinaryOutputFormatValueExplicit() *UserParametersAssert { + return u.HasBinaryOutputFormat(sdk.BinaryOutputFormatHex) +} + +func (u *UserParametersAssert) HasDefaultClientMemoryLimitValueExplicit() *UserParametersAssert { + return u.HasClientMemoryLimit(1536) +} + +func (u *UserParametersAssert) HasDefaultClientMetadataRequestUseConnectionCtxValueExplicit() *UserParametersAssert { + return u.HasClientMetadataRequestUseConnectionCtx(false) +} + +func (u *UserParametersAssert) HasDefaultClientPrefetchThreadsValueExplicit() *UserParametersAssert { + return u.HasClientPrefetchThreads(4) +} + +func (u *UserParametersAssert) HasDefaultClientResultChunkSizeValueExplicit() *UserParametersAssert { + return u.HasClientResultChunkSize(160) +} + +func (u *UserParametersAssert) HasDefaultClientResultColumnCaseInsensitiveValueExplicit() *UserParametersAssert { + return u.HasClientResultColumnCaseInsensitive(false) +} + +func (u *UserParametersAssert) HasDefaultClientSessionKeepAliveValueExplicit() *UserParametersAssert { + return u.HasClientSessionKeepAlive(false) +} + +func (u *UserParametersAssert) HasDefaultClientSessionKeepAliveHeartbeatFrequencyValueExplicit() *UserParametersAssert { + return u.HasClientSessionKeepAliveHeartbeatFrequency(3600) +} + +func (u *UserParametersAssert) HasDefaultClientTimestampTypeMappingValueExplicit() *UserParametersAssert { + return u.HasClientTimestampTypeMapping(sdk.ClientTimestampTypeMappingLtz) +} + +func (u *UserParametersAssert) HasDefaultDateInputFormatValueExplicit() *UserParametersAssert { + return u.HasDateInputFormat("AUTO") +} + +func (u *UserParametersAssert) HasDefaultDateOutputFormatValueExplicit() *UserParametersAssert { + return u.HasDateOutputFormat("YYYY-MM-DD") +} + +func (u *UserParametersAssert) HasDefaultEnableUnloadPhysicalTypeOptimizationValueExplicit() *UserParametersAssert { + return u.HasEnableUnloadPhysicalTypeOptimization(true) +} + +func (u *UserParametersAssert) HasDefaultErrorOnNondeterministicMergeValueExplicit() *UserParametersAssert { + return u.HasErrorOnNondeterministicMerge(true) +} + +func (u *UserParametersAssert) HasDefaultErrorOnNondeterministicUpdateValueExplicit() *UserParametersAssert { + return u.HasErrorOnNondeterministicUpdate(false) +} + +func (u *UserParametersAssert) HasDefaultGeographyOutputFormatValueExplicit() *UserParametersAssert { + return u.HasGeographyOutputFormat(sdk.GeographyOutputFormatGeoJSON) +} + +func (u *UserParametersAssert) HasDefaultGeometryOutputFormatValueExplicit() *UserParametersAssert { + return u.HasGeometryOutputFormat(sdk.GeometryOutputFormatGeoJSON) +} + +func (u *UserParametersAssert) HasDefaultJdbcTreatDecimalAsIntValueExplicit() *UserParametersAssert { + return u.HasJdbcTreatDecimalAsInt(true) +} + +func (u *UserParametersAssert) HasDefaultJdbcTreatTimestampNtzAsUtcValueExplicit() *UserParametersAssert { + return u.HasJdbcTreatTimestampNtzAsUtc(false) +} + +func (u *UserParametersAssert) HasDefaultJdbcUseSessionTimezoneValueExplicit() *UserParametersAssert { + return u.HasJdbcUseSessionTimezone(true) +} + +func (u *UserParametersAssert) HasDefaultJsonIndentValueExplicit() *UserParametersAssert { + return u.HasJsonIndent(2) +} + +func (u *UserParametersAssert) HasDefaultLockTimeoutValueExplicit() *UserParametersAssert { + return u.HasLockTimeout(43200) +} + +func (u *UserParametersAssert) HasDefaultLogLevelValueExplicit() *UserParametersAssert { + return u.HasLogLevel(sdk.LogLevelOff) +} + +func (u *UserParametersAssert) HasDefaultMultiStatementCountValueExplicit() *UserParametersAssert { + return u.HasMultiStatementCount(1) +} + +func (u *UserParametersAssert) HasDefaultNoorderSequenceAsDefaultValueExplicit() *UserParametersAssert { + return u.HasNoorderSequenceAsDefault(true) +} + +func (u *UserParametersAssert) HasDefaultOdbcTreatDecimalAsIntValueExplicit() *UserParametersAssert { + return u.HasOdbcTreatDecimalAsInt(false) +} + +func (u *UserParametersAssert) HasDefaultQueryTagValueExplicit() *UserParametersAssert { + return u.HasQueryTag("") +} + +func (u *UserParametersAssert) HasDefaultQuotedIdentifiersIgnoreCaseValueExplicit() *UserParametersAssert { + return u.HasQuotedIdentifiersIgnoreCase(false) +} + +func (u *UserParametersAssert) HasDefaultRowsPerResultsetValueExplicit() *UserParametersAssert { + return u.HasRowsPerResultset(0) +} + +func (u *UserParametersAssert) HasDefaultS3StageVpceDnsNameValueExplicit() *UserParametersAssert { + return u.HasS3StageVpceDnsName("") +} + +func (u *UserParametersAssert) HasDefaultSearchPathValueExplicit() *UserParametersAssert { + return u.HasSearchPath("$current, $public") +} + +func (u *UserParametersAssert) HasDefaultSimulatedDataSharingConsumerValueExplicit() *UserParametersAssert { + return u.HasSimulatedDataSharingConsumer("") +} + +func (u *UserParametersAssert) HasDefaultStatementQueuedTimeoutInSecondsValueExplicit() *UserParametersAssert { + return u.HasStatementQueuedTimeoutInSeconds(0) +} + +func (u *UserParametersAssert) HasDefaultStatementTimeoutInSecondsValueExplicit() *UserParametersAssert { + return u.HasStatementTimeoutInSeconds(172800) +} + +func (u *UserParametersAssert) HasDefaultStrictJsonOutputValueExplicit() *UserParametersAssert { + return u.HasStrictJsonOutput(false) +} + +func (u *UserParametersAssert) HasDefaultTimestampDayIsAlways24hValueExplicit() *UserParametersAssert { + return u.HasTimestampDayIsAlways24h(false) +} + +func (u *UserParametersAssert) HasDefaultTimestampInputFormatValueExplicit() *UserParametersAssert { + return u.HasTimestampInputFormat("AUTO") +} + +func (u *UserParametersAssert) HasDefaultTimestampLtzOutputFormatValueExplicit() *UserParametersAssert { + return u.HasTimestampLtzOutputFormat("") +} + +func (u *UserParametersAssert) HasDefaultTimestampNtzOutputFormatValueExplicit() *UserParametersAssert { + return u.HasTimestampNtzOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3") +} + +func (u *UserParametersAssert) HasDefaultTimestampOutputFormatValueExplicit() *UserParametersAssert { + return u.HasTimestampOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM") +} + +func (u *UserParametersAssert) HasDefaultTimestampTypeMappingValueExplicit() *UserParametersAssert { + return u.HasTimestampTypeMapping(sdk.TimestampTypeMappingNtz) +} + +func (u *UserParametersAssert) HasDefaultTimestampTzOutputFormatValueExplicit() *UserParametersAssert { + return u.HasTimestampTzOutputFormat("") +} + +func (u *UserParametersAssert) HasDefaultTimezoneValueExplicit() *UserParametersAssert { + return u.HasTimezone("America/Los_Angeles") +} + +func (u *UserParametersAssert) HasDefaultTimeInputFormatValueExplicit() *UserParametersAssert { + return u.HasTimeInputFormat("AUTO") +} + +func (u *UserParametersAssert) HasDefaultTimeOutputFormatValueExplicit() *UserParametersAssert { + return u.HasTimeOutputFormat("HH24:MI:SS") +} + +func (u *UserParametersAssert) HasDefaultTraceLevelValueExplicit() *UserParametersAssert { + return u.HasTraceLevel(sdk.TraceLevelOff) +} + +func (u *UserParametersAssert) HasDefaultTransactionAbortOnErrorValueExplicit() *UserParametersAssert { + return u.HasTransactionAbortOnError(false) +} + +func (u *UserParametersAssert) HasDefaultTransactionDefaultIsolationLevelValueExplicit() *UserParametersAssert { + return u.HasTransactionDefaultIsolationLevel(sdk.TransactionDefaultIsolationLevelReadCommitted) +} + +func (u *UserParametersAssert) HasDefaultTwoDigitCenturyStartValueExplicit() *UserParametersAssert { + return u.HasTwoDigitCenturyStart(1970) +} + +func (u *UserParametersAssert) HasDefaultUnsupportedDdlActionValueExplicit() *UserParametersAssert { + return u.HasUnsupportedDdlAction(sdk.UnsupportedDDLAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore)))) +} + +func (u *UserParametersAssert) HasDefaultUseCachedResultValueExplicit() *UserParametersAssert { + return u.HasUseCachedResult(true) +} + +func (u *UserParametersAssert) HasDefaultWeekOfYearPolicyValueExplicit() *UserParametersAssert { + return u.HasWeekOfYearPolicy(0) +} + +func (u *UserParametersAssert) HasDefaultWeekStartValueExplicit() *UserParametersAssert { + return u.HasWeekStart(0) +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/warehouse_parameters_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/warehouse_parameters_snowflake_gen.go new file mode 100644 index 0000000000..e9eb7ef3c6 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/warehouse_parameters_snowflake_gen.go @@ -0,0 +1,150 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package objectparametersassert + +import ( + "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/sdk" +) + +type WarehouseParametersAssert struct { + *assert.SnowflakeParametersAssert[sdk.AccountObjectIdentifier] +} + +func WarehouseParameters(t *testing.T, id sdk.AccountObjectIdentifier) *WarehouseParametersAssert { + t.Helper() + return &WarehouseParametersAssert{ + assert.NewSnowflakeParametersAssertWithProvider(id, sdk.ObjectTypeWarehouse, acc.TestClient().Parameter.ShowWarehouseParameters), + } +} + +func WarehouseParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, parameters []*sdk.Parameter) *WarehouseParametersAssert { + t.Helper() + return &WarehouseParametersAssert{ + assert.NewSnowflakeParametersAssertWithParameters(id, sdk.ObjectTypeWarehouse, parameters), + } +} + +////////////////////////////// +// Generic parameter checks // +////////////////////////////// + +func (w *WarehouseParametersAssert) HasBoolParameterValue(parameterName sdk.WarehouseParameter, expected bool) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterBoolValueSet(parameterName, expected)) + return w +} + +func (w *WarehouseParametersAssert) HasIntParameterValue(parameterName sdk.WarehouseParameter, expected int) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterIntValueSet(parameterName, expected)) + return w +} + +func (w *WarehouseParametersAssert) HasStringParameterValue(parameterName sdk.WarehouseParameter, expected string) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterValueSet(parameterName, expected)) + return w +} + +func (w *WarehouseParametersAssert) HasDefaultParameterValue(parameterName sdk.WarehouseParameter) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterDefaultValueSet(parameterName)) + return w +} + +func (w *WarehouseParametersAssert) HasDefaultParameterValueOnLevel(parameterName sdk.WarehouseParameter, parameterType sdk.ParameterType) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) + return w +} + +/////////////////////////////// +// Aggregated generic checks // +/////////////////////////////// + +// HasAllDefaults checks if all the parameters: +// - have a default value by comparing current value of the sdk.Parameter with its default +// - have an expected level +func (w *WarehouseParametersAssert) HasAllDefaults() *WarehouseParametersAssert { + return w. + HasDefaultParameterValueOnLevel(sdk.WarehouseParameterMaxConcurrencyLevel, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds, sdk.ParameterTypeSnowflakeDefault). + HasDefaultParameterValueOnLevel(sdk.WarehouseParameterStatementTimeoutInSeconds, sdk.ParameterTypeSnowflakeDefault) +} + +func (w *WarehouseParametersAssert) HasAllDefaultsExplicit() *WarehouseParametersAssert { + return w. + HasDefaultMaxConcurrencyLevelValueExplicit(). + HasDefaultStatementQueuedTimeoutInSecondsValueExplicit(). + HasDefaultStatementTimeoutInSecondsValueExplicit() +} + +//////////////////////////// +// Parameter value checks // +//////////////////////////// + +func (w *WarehouseParametersAssert) HasMaxConcurrencyLevel(expected int) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.WarehouseParameterMaxConcurrencyLevel, expected)) + return w +} + +func (w *WarehouseParametersAssert) HasStatementQueuedTimeoutInSeconds(expected int) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds, expected)) + return w +} + +func (w *WarehouseParametersAssert) HasStatementTimeoutInSeconds(expected int) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterIntValueSet(sdk.WarehouseParameterStatementTimeoutInSeconds, expected)) + return w +} + +//////////////////////////// +// Parameter level checks // +//////////////////////////// + +func (w *WarehouseParametersAssert) HasMaxConcurrencyLevelLevel(expected sdk.ParameterType) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.WarehouseParameterMaxConcurrencyLevel, expected)) + return w +} + +func (w *WarehouseParametersAssert) HasStatementQueuedTimeoutInSecondsLevel(expected sdk.ParameterType) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds, expected)) + return w +} + +func (w *WarehouseParametersAssert) HasStatementTimeoutInSecondsLevel(expected sdk.ParameterType) *WarehouseParametersAssert { + w.AddAssertion(assert.SnowflakeParameterLevelSet(sdk.WarehouseParameterStatementTimeoutInSeconds, expected)) + return w +} + +//////////////////////////////////// +// Parameter default value checks // +//////////////////////////////////// + +func (w *WarehouseParametersAssert) HasDefaultMaxConcurrencyLevelValue() *WarehouseParametersAssert { + return w.HasDefaultParameterValue(sdk.WarehouseParameterMaxConcurrencyLevel) +} + +func (w *WarehouseParametersAssert) HasDefaultStatementQueuedTimeoutInSecondsValue() *WarehouseParametersAssert { + return w.HasDefaultParameterValue(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds) +} + +func (w *WarehouseParametersAssert) HasDefaultStatementTimeoutInSecondsValue() *WarehouseParametersAssert { + return w.HasDefaultParameterValue(sdk.WarehouseParameterStatementTimeoutInSeconds) +} + +///////////////////////////////////////////// +// Parameter explicit default value checks // +///////////////////////////////////////////// + +func (w *WarehouseParametersAssert) HasDefaultMaxConcurrencyLevelValueExplicit() *WarehouseParametersAssert { + return w.HasMaxConcurrencyLevel(8) +} + +func (w *WarehouseParametersAssert) HasDefaultStatementQueuedTimeoutInSecondsValueExplicit() *WarehouseParametersAssert { + return w.HasStatementQueuedTimeoutInSeconds(0) +} + +func (w *WarehouseParametersAssert) HasDefaultStatementTimeoutInSecondsValueExplicit() *WarehouseParametersAssert { + return w.HasStatementTimeoutInSeconds(172800) +} diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_assertions.go index ec6d9b234a..401a1284fa 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_assertions.go @@ -48,6 +48,10 @@ func NewSnowflakeObjectAssertWithObject[T any, I sdk.ObjectIdentifier](objectTyp } } +func (s *SnowflakeObjectAssert[T, I]) AddAssertion(assertion assertSdk[*T]) { + s.assertions = append(s.assertions, assertion) +} + // ToTerraformTestCheckFunc implements TestCheckFuncProvider to allow easier creation of new Snowflake object assertions. // It goes through all the assertion accumulated earlier and gathers the results of the checks. func (s *SnowflakeObjectAssert[_, _]) ToTerraformTestCheckFunc(t *testing.T) resource.TestCheckFunc { diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go new file mode 100644 index 0000000000..665e449efe --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -0,0 +1,177 @@ +package assert + +import ( + "errors" + "fmt" + "strconv" + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/stretchr/testify/require" +) + +type ( + parametersProvider[I sdk.ObjectIdentifier] func(*testing.T, I) []*sdk.Parameter +) + +// SnowflakeParametersAssert is an embeddable struct that should be used to construct new Snowflake parameters assertions. +// It implements both TestCheckFuncProvider and ImportStateCheckFuncProvider which makes it easy to create new resource assertions. +type SnowflakeParametersAssert[I sdk.ObjectIdentifier] struct { + assertions []SnowflakeParameterAssertion + id I + objectType sdk.ObjectType + provider parametersProvider[I] + parameters []*sdk.Parameter +} + +type snowflakeParameterAssertionType int + +const ( + snowflakeParameterAssertionTypeExpectedValue snowflakeParameterAssertionType = iota + snowflakeParameterAssertionTypeDefaultValue + snowflakeParameterAssertionTypeDefaultValueOnLevel + snowflakeParameterAssertionTypeLevel +) + +type SnowflakeParameterAssertion struct { + parameterName string + expectedValue string + parameterType sdk.ParameterType + assertionType snowflakeParameterAssertionType +} + +// NewSnowflakeParametersAssertWithProvider creates a SnowflakeParametersAssert with id and the provider. +// Object to check is lazily fetched from Snowflake when the checks are being run. +func NewSnowflakeParametersAssertWithProvider[I sdk.ObjectIdentifier](id I, objectType sdk.ObjectType, provider parametersProvider[I]) *SnowflakeParametersAssert[I] { + return &SnowflakeParametersAssert[I]{ + assertions: make([]SnowflakeParameterAssertion, 0), + id: id, + objectType: objectType, + provider: provider, + } +} + +// NewSnowflakeParametersAssertWithParameters creates a SnowflakeParametersAssert with parameters already fetched from Snowflake. +// All the checks are run against the given set of parameters. +func NewSnowflakeParametersAssertWithParameters[I sdk.ObjectIdentifier](id I, objectType sdk.ObjectType, parameters []*sdk.Parameter) *SnowflakeParametersAssert[I] { + return &SnowflakeParametersAssert[I]{ + assertions: make([]SnowflakeParameterAssertion, 0), + id: id, + objectType: objectType, + parameters: parameters, + } +} + +func (s *SnowflakeParametersAssert[I]) AddAssertion(assertion SnowflakeParameterAssertion) { + s.assertions = append(s.assertions, assertion) +} + +func SnowflakeParameterBoolValueSet[T ~string](parameterName T, expected bool) SnowflakeParameterAssertion { + return SnowflakeParameterValueSet(parameterName, strconv.FormatBool(expected)) +} + +func SnowflakeParameterIntValueSet[T ~string](parameterName T, expected int) SnowflakeParameterAssertion { + return SnowflakeParameterValueSet(parameterName, strconv.Itoa(expected)) +} + +func SnowflakeParameterStringUnderlyingValueSet[T ~string, U ~string](parameterName T, expected U) SnowflakeParameterAssertion { + return SnowflakeParameterValueSet(parameterName, string(expected)) +} + +func SnowflakeParameterValueSet[T ~string](parameterName T, expected string) SnowflakeParameterAssertion { + return SnowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: expected} +} + +func SnowflakeParameterDefaultValueSet[T ~string](parameterName T) SnowflakeParameterAssertion { + return SnowflakeParameterAssertion{parameterName: string(parameterName), assertionType: snowflakeParameterAssertionTypeDefaultValue} +} + +func SnowflakeParameterDefaultValueOnLevelSet[T ~string](parameterName T, parameterType sdk.ParameterType) SnowflakeParameterAssertion { + return SnowflakeParameterAssertion{parameterName: string(parameterName), parameterType: parameterType, assertionType: snowflakeParameterAssertionTypeDefaultValueOnLevel} +} + +func SnowflakeParameterLevelSet[T ~string](parameterName T, parameterType sdk.ParameterType) SnowflakeParameterAssertion { + return SnowflakeParameterAssertion{parameterName: string(parameterName), parameterType: parameterType, assertionType: snowflakeParameterAssertionTypeLevel} +} + +// ToTerraformTestCheckFunc implements TestCheckFuncProvider to allow easier creation of new Snowflake object parameters assertions. +// It goes through all the assertion accumulated earlier and gathers the results of the checks. +func (s *SnowflakeParametersAssert[_]) ToTerraformTestCheckFunc(t *testing.T) resource.TestCheckFunc { + t.Helper() + return func(_ *terraform.State) error { + return s.runSnowflakeParametersAssertions(t) + } +} + +// ToTerraformImportStateCheckFunc implements ImportStateCheckFuncProvider to allow easier creation of new Snowflake object parameters assertions. +// It goes through all the assertion accumulated earlier and gathers the results of the checks. +func (s *SnowflakeParametersAssert[_]) ToTerraformImportStateCheckFunc(t *testing.T) resource.ImportStateCheckFunc { + t.Helper() + return func(_ []*terraform.InstanceState) error { + return s.runSnowflakeParametersAssertions(t) + } +} + +// VerifyAll implements InPlaceAssertionVerifier to allow easier creation of new Snowflake parameters assertions. +// It verifies all the assertions accumulated earlier and gathers the results of the checks. +func (s *SnowflakeParametersAssert[_]) VerifyAll(t *testing.T) { + t.Helper() + err := s.runSnowflakeParametersAssertions(t) + require.NoError(t, err) +} + +func (s *SnowflakeParametersAssert[_]) runSnowflakeParametersAssertions(t *testing.T) error { + t.Helper() + + var parameters []*sdk.Parameter + switch { + case s.provider != nil: + parameters = s.provider(t, s.id) + case s.parameters != nil: + parameters = s.parameters + default: + return fmt.Errorf("cannot proceed with parameters assertion for object %s[%s]: parameters or parameters provider must be specified", s.objectType, s.id.FullyQualifiedName()) + } + + var result []error + + for i, assertion := range s.assertions { + switch assertion.assertionType { + case snowflakeParameterAssertionTypeExpectedValue: + if v := helpers.FindParameter(t, parameters, assertion.parameterName).Value; assertion.expectedValue != v { + result = append(result, fmt.Errorf( + "parameter assertion for %s[%s][%s][%d/%d] failed: expected value %s, got %s", + s.objectType, s.id.FullyQualifiedName(), assertion.parameterName, i+1, len(s.assertions), assertion.expectedValue, v, + )) + } + case snowflakeParameterAssertionTypeDefaultValue: + if p := helpers.FindParameter(t, parameters, assertion.parameterName); p.Default != p.Value { + result = append(result, fmt.Errorf( + "parameter assertion for %s[%s][%s][%d/%d] failed: expected default value %s, got %s", + s.objectType, s.id.FullyQualifiedName(), assertion.parameterName, i+1, len(s.assertions), p.Default, p.Value, + )) + } + case snowflakeParameterAssertionTypeDefaultValueOnLevel: + if p := helpers.FindParameter(t, parameters, assertion.parameterName); p.Default != p.Value || p.Level != assertion.parameterType { + result = append(result, fmt.Errorf( + "parameter assertion for %s[%s][%s][%d/%d] failed: expected default value %s on level %s, got %s and level %s", + s.objectType, s.id.FullyQualifiedName(), assertion.parameterName, i+1, len(s.assertions), p.Default, assertion.parameterType, p.Value, p.Level, + )) + } + case snowflakeParameterAssertionTypeLevel: + if p := helpers.FindParameter(t, parameters, assertion.parameterName); p.Level != assertion.parameterType { + result = append(result, fmt.Errorf( + "parameter assertion for %s[%s][%s][%d/%d] failed: expected level %s, got %s", + s.objectType, s.id.FullyQualifiedName(), assertion.parameterName, i+1, len(s.assertions), assertion.parameterType, p.Level, + )) + } + default: + return fmt.Errorf("cannot proceed with parameters assertion for object %s[%s]: assertion type must be specified", s.objectType, s.id.FullyQualifiedName()) + } + } + + return errors.Join(result...) +} diff --git a/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go b/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go deleted file mode 100644 index c6be645f25..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go +++ /dev/null @@ -1,171 +0,0 @@ -package assert - -import ( - "fmt" - "testing" - - acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" -) - -type WarehouseAssert struct { - *SnowflakeObjectAssert[sdk.Warehouse, sdk.AccountObjectIdentifier] -} - -func Warehouse(t *testing.T, id sdk.AccountObjectIdentifier) *WarehouseAssert { - t.Helper() - return &WarehouseAssert{ - NewSnowflakeObjectAssertWithProvider(sdk.ObjectTypeWarehouse, id, acc.TestClient().Warehouse.Show), - } -} - -func WarehouseFromObject(t *testing.T, warehouse *sdk.Warehouse) *WarehouseAssert { - t.Helper() - return &WarehouseAssert{ - NewSnowflakeObjectAssertWithObject(sdk.ObjectTypeWarehouse, warehouse.ID(), warehouse), - } -} - -func (w *WarehouseAssert) HasName(expected string) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.Name != expected { - return fmt.Errorf("expected name: %v; got: %v", expected, o.Name) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasState(expected sdk.WarehouseState) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.State != expected { - return fmt.Errorf("expected state: %v; got: %v", expected, string(o.State)) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasType(expected sdk.WarehouseType) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.Type != expected { - return fmt.Errorf("expected type: %v; got: %v", expected, string(o.Type)) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasSize(expected sdk.WarehouseSize) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.Size != expected { - return fmt.Errorf("expected size: %v; got: %v", expected, string(o.Size)) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasMinClusterCount(expected int) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.MinClusterCount != expected { - return fmt.Errorf("expected min cluster count: %v; got: %v", expected, o.MinClusterCount) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasMaxClusterCount(expected int) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.MaxClusterCount != expected { - return fmt.Errorf("expected max cluster count: %v; got: %v", expected, o.MaxClusterCount) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasAutoSuspend(expected int) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.AutoSuspend != expected { - return fmt.Errorf("expected auto suspend: %v; got: %v", expected, o.AutoSuspend) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasAutoResume(expected bool) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.AutoResume != expected { - return fmt.Errorf("expected auto resume: %v; got: %v", expected, o.AutoResume) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasComment(expected string) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.Comment != expected { - return fmt.Errorf("expected comment: %v; got: %v", expected, o.Comment) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasEnableQueryAcceleration(expected bool) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.EnableQueryAcceleration != expected { - return fmt.Errorf("expected enable query acceleration: %v; got: %v", expected, o.EnableQueryAcceleration) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasQueryAccelerationMaxScaleFactor(expected int) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.QueryAccelerationMaxScaleFactor != expected { - return fmt.Errorf("expected query acceleration max scale factor: %v; got: %v", expected, o.QueryAccelerationMaxScaleFactor) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasResourceMonitor(expected sdk.AccountObjectIdentifier) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.ResourceMonitor.Name() != expected.Name() { - return fmt.Errorf("expected resource monitor: %v; got: %v", expected.Name(), o.ResourceMonitor.Name()) - } - return nil - }) - return w -} - -func (w *WarehouseAssert) HasScalingPolicy(expected sdk.ScalingPolicy) *WarehouseAssert { - w.assertions = append(w.assertions, func(t *testing.T, o *sdk.Warehouse) error { - t.Helper() - if o.ScalingPolicy != expected { - return fmt.Errorf("expected type: %v; got: %v", expected, string(o.ScalingPolicy)) - } - return nil - }) - return w -} diff --git a/pkg/internal/genhelpers/README.md b/pkg/internal/genhelpers/README.md new file mode 100644 index 0000000000..fc5c59672f --- /dev/null +++ b/pkg/internal/genhelpers/README.md @@ -0,0 +1,62 @@ +## generator commons + +Because we generate a bunch of code in the project, and we tend to copy-paste similar setup for the generators, templates, etc., we decided to introduce common generator creation utils that can be reused by variety of generators. + +### Description + +The main building blocks of this package are: +- `generator.go` defining `Generator[T ObjectNameProvider, M GenerationModel] struct` allowing to create new generators +- `mappers.go` defining mappers that can be reused in the generated objects +- `struct_details_extractor.go` allowing to parse any struct to retrieve its information (for the later generation purposes) +- `template_commons.go` containing template helper functions and the easy way to use them without providing their name everytime +- `util.go` with a variety of util functions + +### How it works + +##### Defining and running a new generator + +Before proceeding with the following steps check [objectassert/gen](../../acceptance/bettertestspoc/assert/objectassert/gen) package for reference. + +To create a new generator: +1. Create `gen` package in the destination package with: + - `main/main.go` file + - `templates` directory + - `model.go` containing the model definition and conversion + - `templates.go` containing the templates definitions and helper functions +2. Create `generate.go` file on the same level as the `gen` package above with the following content only (in addition to the package name) `//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS`. +3. In the `gen/main/main.go` create and run a new generator. This means: + - providing an input definition for the source objects + - method to enrich source object definitions with the necessary content + - method to translate enriched objects to the models used inside the templates + - method with the generated files naming strategy + - list of all the needed templates + - (optionally) additional debug output you want to run for each of the objects + - (optionally) a filter to limit the generation to only specific objects +4. Add two entries to our Makefile: + - first for a cleanup, e.g. `rm -f ./pkg/acceptance/bettertestspoc/assert/objectparametersassert/*_gen.go` + - second for a generation itself, e.g. `go generate ./pkg/acceptance/bettertestspoc/assert/objectparametersassert/generate.go` +5. By default, generator support the following command line flags (invokable with e.g. `make generate-show-output-schemas SF_TF_GENERATOR_ARGS='--dry-run --verbose'`) + - `--dry-run` allowing to print the generated content to the command line instead of saving it to files + - `--verbose` allowing to see the all the additional debug logs + +### Next steps + +##### Known limitations + +- Currently, only 3 generators reuse the same flow; we need to include more to have more observations + +##### Improvements + +Functional improvements: +- add a generic terraform schema reader, to allow later generation from schemas +- handle the missing types (TODOs in [struct_details_extractor_test.go](./struct_details_extractor_test.go)) + +Implementation improvements: +- add acceptance test for a `testStruct` (the one from [struct_details_extractor_test.go](./struct_details_extractor_test.go)) for the whole generation flow +- add description to all publicly available structs and functions (multiple TODOs left) +- introduce a more meaningful function for the `GenerationModel` interface (TODO left in the `generator.go`) +- tackle the temporary hacky solution to allow easy passing multiple args from the make command (TODO left in the `generator.go`) +- extract a common filter by name filter (TODO left in the `pkg/schemas/gen/main`) +- describe and test all the template helpers (TODOs left in `templates_commons.go`) +- test writing to file (TODO left in `util.go`) +- use commons in the SDK generator diff --git a/pkg/internal/genhelpers/generator.go b/pkg/internal/genhelpers/generator.go new file mode 100644 index 0000000000..c3c4848290 --- /dev/null +++ b/pkg/internal/genhelpers/generator.go @@ -0,0 +1,166 @@ +package genhelpers + +import ( + "bytes" + "errors" + "flag" + "fmt" + "io" + "log" + "os" + "strings" + "text/template" +) + +// TODO [SNOW-1501905]: describe +type ObjectNameProvider interface { + ObjectName() string +} + +// TODO [SNOW-1501905]: describe +// TODO [SNOW-1501905]: better func +type GenerationModel interface { + SomeFunc() +} + +type Generator[T ObjectNameProvider, M GenerationModel] struct { + objectsProvider func() []T + modelProvider func(T) M + // TODO [SNOW-1501905]: consider adding filename to model? + filenameProvider func(T, M) string + templates []*template.Template + + additionalObjectDebugLogProviders []func([]T) + objectFilters []func(T) bool +} + +func NewGenerator[T ObjectNameProvider, M GenerationModel](objectsProvider func() []T, modelProvider func(T) M, filenameProvider func(T, M) string, templates []*template.Template) *Generator[T, M] { + return &Generator[T, M]{ + objectsProvider: objectsProvider, + modelProvider: modelProvider, + filenameProvider: filenameProvider, + templates: templates, + + additionalObjectDebugLogProviders: make([]func([]T), 0), + objectFilters: make([]func(T) bool, 0), + } +} + +func (g *Generator[T, M]) WithAdditionalObjectsDebugLogs(objectLogsProvider func([]T)) *Generator[T, M] { + g.additionalObjectDebugLogProviders = append(g.additionalObjectDebugLogProviders, objectLogsProvider) + return g +} + +func (g *Generator[T, M]) WithObjectFilter(objectFilter func(T) bool) *Generator[T, M] { + g.objectFilters = append(g.objectFilters, objectFilter) + return g +} + +func (g *Generator[T, _]) Run() error { + preprocessArgs() + + file := os.Getenv("GOFILE") + fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) + + additionalLogs := flag.Bool("verbose", false, "print additional object debug logs") + dryRun := flag.Bool("dry-run", false, "generate to std out instead of saving") + flag.Parse() + + objects := g.objectsProvider() + + if len(g.objectFilters) > 0 { + filteredObjects := make([]T, 0) + for _, o := range objects { + matches := true + for _, f := range g.objectFilters { + matches = matches && f(o) + } + if matches { + filteredObjects = append(filteredObjects, o) + } + } + objects = filteredObjects + } + + if *additionalLogs { + for _, p := range g.additionalObjectDebugLogProviders { + p(objects) + } + } + + if *dryRun { + if err := generateAndPrintForAllObjects(objects, g.modelProvider, g.templates...); err != nil { + return err + } + } else { + if err := generateAndSaveForAllObjects( + objects, + g.modelProvider, + g.filenameProvider, + g.templates..., + ); err != nil { + return err + } + } + + return nil +} + +// TODO [SNOW-1501905]: temporary hacky solution to allow easy passing multiple args from the make command +func preprocessArgs() { + rest := os.Args[1:] + newArgs := []string{os.Args[0]} + for _, a := range rest { + newArgs = append(newArgs, strings.Split(a, " ")...) + } + os.Args = newArgs +} + +func (g *Generator[_, _]) RunAndHandleOsReturn() { + err := g.Run() + if err != nil { + log.Fatal(err) + } +} + +func generateAndSaveForAllObjects[T ObjectNameProvider, M GenerationModel](objects []T, modelProvider func(T) M, filenameProvider func(T, M) string, templates ...*template.Template) error { + var errs []error + for _, s := range objects { + buffer := bytes.Buffer{} + model := modelProvider(s) + if err := executeAllTemplates(model, &buffer, templates...); err != nil { + errs = append(errs, fmt.Errorf("generating output for object %s failed with err: %w", s.ObjectName(), err)) + continue + } + filename := filenameProvider(s, model) + if err := WriteCodeToFile(&buffer, filename); err != nil { + errs = append(errs, fmt.Errorf("saving output for object %s to file %s failed with err: %w", s.ObjectName(), filename, err)) + continue + } + } + return errors.Join(errs...) +} + +func generateAndPrintForAllObjects[T ObjectNameProvider, M GenerationModel](objects []T, modelProvider func(T) M, templates ...*template.Template) error { + var errs []error + for _, s := range objects { + fmt.Println("===========================") + fmt.Printf("Generating for object %s\n", s.ObjectName()) + fmt.Println("===========================") + if err := executeAllTemplates(modelProvider(s), os.Stdout, templates...); err != nil { + errs = append(errs, fmt.Errorf("generating output for object %s failed with err: %w", s.ObjectName(), err)) + continue + } + } + return errors.Join(errs...) +} + +func executeAllTemplates[M GenerationModel](model M, writer io.Writer, templates ...*template.Template) error { + var errs []error + for _, t := range templates { + if err := t.Execute(writer, model); err != nil { + errs = append(errs, fmt.Errorf("template execution for template %s failed with err: %w", t.Name(), err)) + } + } + return errors.Join(errs...) +} diff --git a/pkg/internal/genhelpers/mappers.go b/pkg/internal/genhelpers/mappers.go new file mode 100644 index 0000000000..53f86e5521 --- /dev/null +++ b/pkg/internal/genhelpers/mappers.go @@ -0,0 +1,14 @@ +package genhelpers + +import "fmt" + +type Mapper func(string) string + +var ( + Identity = func(field string) string { return field } + ToString = func(field string) string { return fmt.Sprintf("%s.String()", field) } + FullyQualifiedName = func(field string) string { return fmt.Sprintf("%s.FullyQualifiedName()", field) } + Name = func(field string) string { return fmt.Sprintf("%s.Name()", field) } + CastToString = func(field string) string { return fmt.Sprintf("string(%s)", field) } + CastToInt = func(field string) string { return fmt.Sprintf("int(%s)", field) } +) diff --git a/pkg/internal/genhelpers/sdk_object_details.go b/pkg/internal/genhelpers/sdk_object_details.go new file mode 100644 index 0000000000..5b2c879a38 --- /dev/null +++ b/pkg/internal/genhelpers/sdk_object_details.go @@ -0,0 +1,9 @@ +package genhelpers + +import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + +type SdkObjectDetails struct { + IdType string + ObjectType sdk.ObjectType + StructDetails +} diff --git a/pkg/schemas/gen/struct_details_extractor.go b/pkg/internal/genhelpers/struct_details_extractor.go similarity index 74% rename from pkg/schemas/gen/struct_details_extractor.go rename to pkg/internal/genhelpers/struct_details_extractor.go index 4e92004ff8..34ddf34ca7 100644 --- a/pkg/schemas/gen/struct_details_extractor.go +++ b/pkg/internal/genhelpers/struct_details_extractor.go @@ -1,15 +1,19 @@ -package gen +package genhelpers import ( "reflect" "strings" ) -type Struct struct { +type StructDetails struct { Name string Fields []Field } +func (s StructDetails) ObjectName() string { + return s.Name +} + type Field struct { Name string ConcreteType string @@ -24,7 +28,12 @@ func (f *Field) IsSlice() bool { return strings.HasPrefix(f.ConcreteType, "[]") } -func ExtractStructDetails(s any) Struct { +func (f *Field) GetImportedType() (string, bool) { + parts := strings.Split(f.ConcreteType, ".") + return parts[0], len(parts) > 1 +} + +func ExtractStructDetails(s any) StructDetails { v := reflect.ValueOf(s) if v.Kind() == reflect.Pointer { v = v.Elem() @@ -54,5 +63,5 @@ func ExtractStructDetails(s any) Struct { fields[i] = Field{currentName, currentType, underlyingType} } - return Struct{v.Type().String(), fields} + return StructDetails{v.Type().String(), fields} } diff --git a/pkg/schemas/gen/struct_details_extractor_test.go b/pkg/internal/genhelpers/struct_details_extractor_test.go similarity index 98% rename from pkg/schemas/gen/struct_details_extractor_test.go rename to pkg/internal/genhelpers/struct_details_extractor_test.go index 098e081f47..b79c02cdca 100644 --- a/pkg/schemas/gen/struct_details_extractor_test.go +++ b/pkg/internal/genhelpers/struct_details_extractor_test.go @@ -1,4 +1,4 @@ -package gen +package genhelpers import ( "testing" @@ -74,7 +74,7 @@ func Test_ExtractStructDetails(t *testing.T) { t.Run("test struct details extraction", func(t *testing.T) { structDetails := ExtractStructDetails(testStruct{}) - assert.Equal(t, structDetails.Name, "gen.testStruct") + assert.Equal(t, structDetails.Name, "gencommons.testStruct") assertFieldExtracted(structDetails.Fields[0], "unexportedString", "string", "string") assertFieldExtracted(structDetails.Fields[1], "unexportedInt", "int", "int") diff --git a/pkg/internal/genhelpers/template_commons.go b/pkg/internal/genhelpers/template_commons.go new file mode 100644 index 0000000000..1480f1357f --- /dev/null +++ b/pkg/internal/genhelpers/template_commons.go @@ -0,0 +1,59 @@ +package genhelpers + +import ( + "reflect" + "runtime" + "strings" + "text/template" +) + +// TODO [SNOW-1501905]: describe all methods in this file +// TODO [SNOW-1501905]: test all methods in this file + +func FirstLetterLowercase(in string) string { + return strings.ToLower(in[:1]) + in[1:] +} + +func FirstLetter(in string) string { + return in[:1] +} + +func RunMapper(mapper Mapper, in ...string) string { + return mapper(strings.Join(in, "")) +} + +func TypeWithoutPointer(t string) string { + without, _ := strings.CutPrefix(t, "*") + return without +} + +func CamelToWords(camel string) string { + return strings.ReplaceAll(ToSnakeCase(camel), "_", " ") +} + +func SnakeCaseToCamel(snake string) string { + snake = strings.ToLower(snake) + parts := strings.Split(snake, "_") + for idx, p := range parts { + parts[idx] = strings.ToUpper(p[:1]) + p[1:] + } + return strings.Join(parts, "") +} + +func IsLastItem(itemIdx int, collectionLength int) bool { + return itemIdx+1 == collectionLength +} + +func BuildTemplateFuncMap(funcs ...any) template.FuncMap { + allFuncs := make(map[string]any) + for _, f := range funcs { + allFuncs[getFunctionName(f)] = f + } + return allFuncs +} + +func getFunctionName(f any) string { + fullFuncName := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name() + parts := strings.Split(fullFuncName, ".") + return parts[len(parts)-1] +} diff --git a/pkg/schemas/gen/util.go b/pkg/internal/genhelpers/util.go similarity index 61% rename from pkg/schemas/gen/util.go rename to pkg/internal/genhelpers/util.go index d1d08399bc..65f402c1a9 100644 --- a/pkg/schemas/gen/util.go +++ b/pkg/internal/genhelpers/util.go @@ -1,6 +1,11 @@ -package gen +package genhelpers import ( + "bytes" + "fmt" + "go/format" + "os" + "path/filepath" "regexp" "strings" ) @@ -37,3 +42,21 @@ func ColumnOutput(columnWidth int, columns ...string) string { } return sb.String() } + +// WriteCodeToFile formats and saves content from the given buffer into file relative to the current working directory. +// TODO [SNOW-1501905]: test +func WriteCodeToFile(buffer *bytes.Buffer, fileName string) error { + wd, err := os.Getwd() + if err != nil { + return fmt.Errorf("writing code to file %s failed with err: %w", fileName, err) + } + outputPath := filepath.Join(wd, fileName) + src, err := format.Source(buffer.Bytes()) + if err != nil { + return fmt.Errorf("writing code to file %s failed with err: %w", fileName, err) + } + if err := os.WriteFile(outputPath, src, 0o600); err != nil { + return fmt.Errorf("writing code to file %s failed with err: %w", fileName, err) + } + return nil +} diff --git a/pkg/schemas/gen/util_test.go b/pkg/internal/genhelpers/util_test.go similarity index 99% rename from pkg/schemas/gen/util_test.go rename to pkg/internal/genhelpers/util_test.go index dd1ea30251..fac58d7d21 100644 --- a/pkg/schemas/gen/util_test.go +++ b/pkg/internal/genhelpers/util_test.go @@ -1,4 +1,4 @@ -package gen +package genhelpers import ( "fmt" diff --git a/pkg/resources/warehouse_acceptance_test.go b/pkg/resources/warehouse_acceptance_test.go index 5536a39c5e..6a045646bc 100644 --- a/pkg/resources/warehouse_acceptance_test.go +++ b/pkg/resources/warehouse_acceptance_test.go @@ -11,6 +11,8 @@ import ( tfjson "github.com/hashicorp/terraform-json" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/importchecks" @@ -96,7 +98,7 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { HasDefaultMaxConcurrencyLevel(). HasDefaultStatementQueuedTimeoutInSeconds(). HasDefaultStatementTimeoutInSeconds(), - assert.Warehouse(t, warehouseId). + objectassert.Warehouse(t, warehouseId). HasName(warehouseId.Name()). HasState(sdk.WarehouseStateStarted). HasType(sdk.WarehouseTypeStandard). @@ -110,6 +112,9 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { HasComment(comment). HasEnableQueryAcceleration(false). HasQueryAccelerationMaxScaleFactor(8), + objectparametersassert.WarehouseParameters(t, warehouseId). + HasAllDefaults(). + HasAllDefaultsExplicit(), // we can still use normal checks assert.Check(resource.TestCheckResourceAttr("snowflake_warehouse.w", "name", warehouseId.Name())), ), @@ -144,7 +149,7 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { HasStatementQueuedTimeoutInSecondsLevel(""). HasStatementTimeoutInSeconds(172800). HasStatementTimeoutInSecondsLevel(""), - assert.Warehouse(t, warehouseId). + objectassert.Warehouse(t, warehouseId). HasName(warehouseId.Name()). HasState(sdk.WarehouseStateStarted). HasType(sdk.WarehouseTypeStandard). @@ -158,6 +163,9 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { HasComment(comment). HasEnableQueryAcceleration(false). HasQueryAccelerationMaxScaleFactor(8), + objectparametersassert.WarehouseParameters(t, warehouseId). + HasAllDefaults(). + HasAllDefaultsExplicit(), ), }, // RENAME diff --git a/pkg/schemas/gen/README.md b/pkg/schemas/gen/README.md index 79b1abbf99..78420ff9e2 100644 --- a/pkg/schemas/gen/README.md +++ b/pkg/schemas/gen/README.md @@ -22,6 +22,11 @@ To generate all show outputs (with a cleanup first) run: make clean-show-output-schemas generate-show-output-schemas ``` +To generate only chosen subset of all objects run: +```shell +make clean-show-output-schemas generate-show-output-schemas SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES="sdk.Warehouse,sdk.User" +``` + ##### Supported types The following types are supported currently in the generator (schema and mappings): @@ -77,16 +82,10 @@ If you change the show output struct in the SDK: ##### Improvements Functional improvements: -- handle the missing types (TODOs in [schema_field_mapper.go](./schema_field_mapper.go) and [struct_details_extractor_test.go](./struct_details_extractor_test.go)) +- handle the missing types (TODOs in [schema_field_mapper.go](./schema_field_mapper.go)) - parametrize the generation, e.g.: - - generate only given object(s) - now all are always generated - - manage the output - currently, the output consists of all structs displayed with fields, unique types grouped, and schemas generated - (optional) parametrize the output directory - currently, it's always written to `schemas` package - discover a change and generate as part of a `make pre-push` Implementation improvements: -- add acceptance test for a `testStruct` (the one from [struct_details_extractor_test.go](./struct_details_extractor_test.go)) for the whole generation flow -- extract common generator functions inside the project (TODO in [main.go](./main/main.go); e.g. `writeCodeToFile` function) -- test the generator part and improve error handling (TODOs in [generator.go](./generator.go)) -- extract common template functions (TODO in [templates.go](./templates.go))) - (optional) consider different implementations of `Mapper` (e.g. TODO in [schema_field_mapper_test.go](./schema_field_mapper_test.go): `ugly comparison of functions with the current implementation of mapper` and not ideal implementation in the [to_schema_mapper.tmpl](./templates/to_schema_mapper.tmpl): `runMapper .Mapper $nameLowerCase "." .OriginalName`) diff --git a/pkg/schemas/gen/generator.go b/pkg/schemas/gen/generator.go deleted file mode 100644 index da2f5d63a5..0000000000 --- a/pkg/schemas/gen/generator.go +++ /dev/null @@ -1,23 +0,0 @@ -package gen - -import ( - "io" - "log" -) - -// TODO [SNOW-1501905]: handle panics better -// TODO [SNOW-1501905]: test and describe -func Generate(model ShowResultSchemaModel, writer io.Writer) { - err := PreambleTemplate.Execute(writer, model) - if err != nil { - log.Panicln(err) - } - err = SchemaTemplate.Execute(writer, model) - if err != nil { - log.Panicln(err) - } - err = ToSchemaMapperTemplate.Execute(writer, model) - if err != nil { - log.Panicln(err) - } -} diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 23e68ef4f3..8f7978aa54 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -3,47 +3,54 @@ package main import ( - "bytes" "fmt" - "go/format" - "log" "os" - "path/filepath" "slices" + "strings" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" "golang.org/x/exp/maps" ) func main() { - file := os.Getenv("GOFILE") - fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) + genhelpers.NewGenerator( + getStructDetails, + gen.ModelFromStructDetails, + getFilename, + gen.AllTemplates, + ). + WithAdditionalObjectsDebugLogs(printAllStructsFields). + WithAdditionalObjectsDebugLogs(printUniqueTypes). + WithObjectFilter(filterByNameFromEnv). + RunAndHandleOsReturn() +} +func getStructDetails() []genhelpers.StructDetails { allObjects := append(gen.SdkShowResultStructs, gen.AdditionalStructs...) - allStructsDetails := make([]gen.Struct, len(allObjects)) + allStructsDetails := make([]genhelpers.StructDetails, len(allObjects)) for idx, s := range allObjects { - allStructsDetails[idx] = gen.ExtractStructDetails(s) + allStructsDetails[idx] = genhelpers.ExtractStructDetails(s) } + return allStructsDetails +} - printAllStructsFields(allStructsDetails) - printUniqueTypes(allStructsDetails) - generateAllStructsToStdOut(allStructsDetails) - saveAllGeneratedSchemas(allStructsDetails) +func getFilename(_ genhelpers.StructDetails, model gen.ShowResultSchemaModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_gen.go" } -func printAllStructsFields(allStructs []gen.Struct) { +func printAllStructsFields(allStructs []genhelpers.StructDetails) { for _, s := range allStructs { fmt.Println("===========================") fmt.Printf("%s\n", s.Name) fmt.Println("===========================") for _, field := range s.Fields { - fmt.Println(gen.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) + fmt.Println(genhelpers.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) } fmt.Println() } } -func printUniqueTypes(allStructs []gen.Struct) { +func printUniqueTypes(allStructs []genhelpers.StructDetails) { uniqueTypes := make(map[string]bool) for _, s := range allStructs { for _, f := range s.Fields { @@ -60,38 +67,12 @@ func printUniqueTypes(allStructs []gen.Struct) { } } -func generateAllStructsToStdOut(allStructs []gen.Struct) { - for _, s := range allStructs { - fmt.Println("===========================") - fmt.Printf("Generated for %s\n", s.Name) - fmt.Println("===========================") - model := gen.ModelFromStructDetails(s) - gen.Generate(model, os.Stdout) - } -} - -func saveAllGeneratedSchemas(allStructs []gen.Struct) { - for _, s := range allStructs { - buffer := bytes.Buffer{} - model := gen.ModelFromStructDetails(s) - gen.Generate(model, &buffer) - filename := gen.ToSnakeCase(model.Name) + "_gen.go" - writeCodeToFile(&buffer, filename) - } -} - -// TODO [SNOW-1501905]: this is copied, extract some generator helpers -func writeCodeToFile(buffer *bytes.Buffer, fileName string) { - wd, errWd := os.Getwd() - if errWd != nil { - log.Panicln(errWd) - } - outputPath := filepath.Join(wd, fileName) - src, errSrcFormat := format.Source(buffer.Bytes()) - if errSrcFormat != nil { - log.Panicln(errSrcFormat) - } - if err := os.WriteFile(outputPath, src, 0o600); err != nil { - log.Panicln(err) +// TODO: move this filter to commons and consider extracting this as a command line param +func filterByNameFromEnv(o genhelpers.StructDetails) bool { + allowedObjectNamesString := os.Getenv("SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES") + if allowedObjectNamesString == "" { + return true } + allowedObjectNames := strings.Split(allowedObjectNamesString, ",") + return slices.Contains(allowedObjectNames, o.ObjectName()) } diff --git a/pkg/schemas/gen/model.go b/pkg/schemas/gen/model.go index 2e4c850fb1..0a9d318380 100644 --- a/pkg/schemas/gen/model.go +++ b/pkg/schemas/gen/model.go @@ -1,6 +1,10 @@ package gen -import "strings" +import ( + "strings" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) type ShowResultSchemaModel struct { Name string @@ -8,7 +12,10 @@ type ShowResultSchemaModel struct { SchemaFields []SchemaField } -func ModelFromStructDetails(sdkStruct Struct) ShowResultSchemaModel { +func (m ShowResultSchemaModel) SomeFunc() { +} + +func ModelFromStructDetails(sdkStruct genhelpers.StructDetails) ShowResultSchemaModel { name, _ := strings.CutPrefix(sdkStruct.Name, "sdk.") schemaFields := make([]SchemaField, len(sdkStruct.Fields)) for idx, field := range sdkStruct.Fields { diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go index 189d70456a..be0d21af7d 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -1,66 +1,55 @@ package gen import ( - "fmt" "strings" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -type Mapper func(string) string - type SchemaField struct { Name string SchemaType schema.ValueType OriginalName string IsOriginalTypePointer bool - Mapper Mapper + Mapper genhelpers.Mapper } -var ( - Identity = func(field string) string { return field } - ToString = func(field string) string { return fmt.Sprintf("%s.String()", field) } - FullyQualifiedName = func(field string) string { return fmt.Sprintf("%s.FullyQualifiedName()", field) } - Name = func(field string) string { return fmt.Sprintf("%s.Name()", field) } - CastToString = func(field string) string { return fmt.Sprintf("string(%s)", field) } - CastToInt = func(field string) string { return fmt.Sprintf("int(%s)", field) } -) - // TODO [SNOW-1501905]: handle other basic type variants // TODO [SNOW-1501905]: handle any other interface (error) // TODO [SNOW-1501905]: handle slices // TODO [SNOW-1501905]: handle structs (chosen one or all) -func MapToSchemaField(field Field) SchemaField { +func MapToSchemaField(field genhelpers.Field) SchemaField { isPointer := field.IsPointer() concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") - name := ToSnakeCase(field.Name) + name := genhelpers.ToSnakeCase(field.Name) switch concreteTypeWithoutPtr { case "string": - return SchemaField{name, schema.TypeString, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.Identity} case "int": - return SchemaField{name, schema.TypeInt, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeInt, field.Name, isPointer, genhelpers.Identity} case "float64": - return SchemaField{name, schema.TypeFloat, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeFloat, field.Name, isPointer, genhelpers.Identity} case "bool": - return SchemaField{name, schema.TypeBool, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeBool, field.Name, isPointer, genhelpers.Identity} case "time.Time": - return SchemaField{name, schema.TypeString, field.Name, isPointer, ToString} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.ToString} case "sdk.AccountObjectIdentifier": - return SchemaField{name, schema.TypeString, field.Name, isPointer, Name} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.Name} case "sdk.AccountIdentifier", "sdk.ExternalObjectIdentifier", "sdk.DatabaseObjectIdentifier", "sdk.SchemaObjectIdentifier", "sdk.TableColumnIdentifier": - return SchemaField{name, schema.TypeString, field.Name, isPointer, FullyQualifiedName} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.FullyQualifiedName} case "sdk.ObjectIdentifier": - return SchemaField{name, schema.TypeString, field.Name, isPointer, FullyQualifiedName} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.FullyQualifiedName} } underlyingTypeWithoutPtr, _ := strings.CutPrefix(field.UnderlyingType, "*") isSdkDeclaredObject := strings.HasPrefix(concreteTypeWithoutPtr, "sdk.") switch { case isSdkDeclaredObject && underlyingTypeWithoutPtr == "string": - return SchemaField{name, schema.TypeString, field.Name, isPointer, CastToString} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.CastToString} case isSdkDeclaredObject && underlyingTypeWithoutPtr == "int": - return SchemaField{name, schema.TypeInt, field.Name, isPointer, CastToInt} + return SchemaField{name, schema.TypeInt, field.Name, isPointer, genhelpers.CastToInt} } - return SchemaField{name, schema.TypeInvalid, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeInvalid, field.Name, isPointer, genhelpers.Identity} } diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go index 1f2f23932a..ec256154b9 100644 --- a/pkg/schemas/gen/schema_field_mapper_test.go +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -4,6 +4,7 @@ import ( "reflect" "testing" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" ) @@ -13,124 +14,124 @@ func Test_MapToSchemaField(t *testing.T) { name string schemaType schema.ValueType isPointer bool - mapper Mapper + mapper genhelpers.Mapper } testCases := []struct { - field Field + field genhelpers.Field expected expectedValues }{ { - field: Field{"unexportedString", "string", "string"}, - expected: expectedValues{"unexported_string", schema.TypeString, false, Identity}, + field: genhelpers.Field{Name: "unexportedString", ConcreteType: "string", UnderlyingType: "string"}, + expected: expectedValues{"unexported_string", schema.TypeString, false, genhelpers.Identity}, }, { - field: Field{"unexportedInt", "int", "int"}, - expected: expectedValues{"unexported_int", schema.TypeInt, false, Identity}, + field: genhelpers.Field{Name: "unexportedInt", ConcreteType: "int", UnderlyingType: "int"}, + expected: expectedValues{"unexported_int", schema.TypeInt, false, genhelpers.Identity}, }, { - field: Field{"unexportedBool", "bool", "bool"}, - expected: expectedValues{"unexported_bool", schema.TypeBool, false, Identity}, + field: genhelpers.Field{Name: "unexportedBool", ConcreteType: "bool", UnderlyingType: "bool"}, + expected: expectedValues{"unexported_bool", schema.TypeBool, false, genhelpers.Identity}, }, { - field: Field{"unexportedFloat64", "float64", "float64"}, - expected: expectedValues{"unexported_float64", schema.TypeFloat, false, Identity}, + field: genhelpers.Field{Name: "unexportedFloat64", ConcreteType: "float64", UnderlyingType: "float64"}, + expected: expectedValues{"unexported_float64", schema.TypeFloat, false, genhelpers.Identity}, }, { - field: Field{"unexportedStringPtr", "*string", "*string"}, - expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, Identity}, + field: genhelpers.Field{Name: "unexportedStringPtr", ConcreteType: "*string", UnderlyingType: "*string"}, + expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, genhelpers.Identity}, }, { - field: Field{"unexportedIntPtr", "*int", "*int"}, - expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, Identity}, + field: genhelpers.Field{Name: "unexportedIntPtr", ConcreteType: "*int", UnderlyingType: "*int"}, + expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, genhelpers.Identity}, }, { - field: Field{"unexportedBoolPtr", "*bool", "*bool"}, - expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, Identity}, + field: genhelpers.Field{Name: "unexportedBoolPtr", ConcreteType: "*bool", UnderlyingType: "*bool"}, + expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, genhelpers.Identity}, }, { - field: Field{"unexportedFloat64Ptr", "*float64", "*float64"}, - expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, Identity}, + field: genhelpers.Field{Name: "unexportedFloat64Ptr", ConcreteType: "*float64", UnderlyingType: "*float64"}, + expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, genhelpers.Identity}, }, { - field: Field{"unexportedTime", "time.Time", "struct"}, - expected: expectedValues{"unexported_time", schema.TypeString, false, ToString}, + field: genhelpers.Field{Name: "unexportedTime", ConcreteType: "time.Time", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_time", schema.TypeString, false, genhelpers.ToString}, }, { - field: Field{"unexportedTimePtr", "*time.Time", "*struct"}, - expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, ToString}, + field: genhelpers.Field{Name: "unexportedTimePtr", ConcreteType: "*time.Time", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, genhelpers.ToString}, }, { - field: Field{"unexportedStringEnum", "sdk.WarehouseType", "string"}, - expected: expectedValues{"unexported_string_enum", schema.TypeString, false, CastToString}, + field: genhelpers.Field{Name: "unexportedStringEnum", ConcreteType: "sdk.WarehouseType", UnderlyingType: "string"}, + expected: expectedValues{"unexported_string_enum", schema.TypeString, false, genhelpers.CastToString}, }, { - field: Field{"unexportedStringEnumPtr", "*sdk.WarehouseType", "*string"}, - expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, CastToString}, + field: genhelpers.Field{Name: "unexportedStringEnumPtr", ConcreteType: "*sdk.WarehouseType", UnderlyingType: "*string"}, + expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, genhelpers.CastToString}, }, { - field: Field{"unexportedIntEnum", "sdk.ResourceMonitorLevel", "int"}, - expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, CastToInt}, + field: genhelpers.Field{Name: "unexportedIntEnum", ConcreteType: "sdk.ResourceMonitorLevel", UnderlyingType: "int"}, + expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, genhelpers.CastToInt}, }, { - field: Field{"unexportedIntEnumPtr", "*sdk.ResourceMonitorLevel", "*int"}, - expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, CastToInt}, + field: genhelpers.Field{Name: "unexportedIntEnumPtr", ConcreteType: "*sdk.ResourceMonitorLevel", UnderlyingType: "*int"}, + expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, genhelpers.CastToInt}, }, { - field: Field{"unexportedAccountIdentifier", "sdk.AccountIdentifier", "struct"}, - expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedAccountIdentifier", ConcreteType: "sdk.AccountIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedExternalObjectIdentifier", "sdk.ExternalObjectIdentifier", "struct"}, - expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedExternalObjectIdentifier", ConcreteType: "sdk.ExternalObjectIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedAccountObjectIdentifier", "sdk.AccountObjectIdentifier", "struct"}, - expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, Name}, + field: genhelpers.Field{Name: "unexportedAccountObjectIdentifier", ConcreteType: "sdk.AccountObjectIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, genhelpers.Name}, }, { - field: Field{"unexportedDatabaseObjectIdentifier", "sdk.DatabaseObjectIdentifier", "struct"}, - expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedDatabaseObjectIdentifier", ConcreteType: "sdk.DatabaseObjectIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedSchemaObjectIdentifier", "sdk.SchemaObjectIdentifier", "struct"}, - expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedSchemaObjectIdentifier", ConcreteType: "sdk.SchemaObjectIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedTableColumnIdentifier", "sdk.TableColumnIdentifier", "struct"}, - expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedTableColumnIdentifier", ConcreteType: "sdk.TableColumnIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedAccountIdentifierPtr", "*sdk.AccountIdentifier", "*struct"}, - expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedAccountIdentifierPtr", ConcreteType: "*sdk.AccountIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedExternalObjectIdentifierPtr", "*sdk.ExternalObjectIdentifier", "*struct"}, - expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedExternalObjectIdentifierPtr", ConcreteType: "*sdk.ExternalObjectIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedAccountObjectIdentifierPtr", "*sdk.AccountObjectIdentifier", "*struct"}, - expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, Name}, + field: genhelpers.Field{Name: "unexportedAccountObjectIdentifierPtr", ConcreteType: "*sdk.AccountObjectIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, genhelpers.Name}, }, { - field: Field{"unexportedDatabaseObjectIdentifierPtr", "*sdk.DatabaseObjectIdentifier", "*struct"}, - expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedDatabaseObjectIdentifierPtr", ConcreteType: "*sdk.DatabaseObjectIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedSchemaObjectIdentifierPtr", "*sdk.SchemaObjectIdentifier", "*struct"}, - expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedSchemaObjectIdentifierPtr", ConcreteType: "*sdk.SchemaObjectIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedTableColumnIdentifierPtr", "*sdk.TableColumnIdentifier", "*struct"}, - expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedTableColumnIdentifierPtr", ConcreteType: "*sdk.TableColumnIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: Field{"unexportedInterface", "sdk.ObjectIdentifier", "interface"}, - expected: expectedValues{"unexported_interface", schema.TypeString, false, FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedInterface", ConcreteType: "sdk.ObjectIdentifier", UnderlyingType: "interface"}, + expected: expectedValues{"unexported_interface", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, } - assertSchemaFieldMapped := func(schemaField SchemaField, originalField Field, expected expectedValues) { + assertSchemaFieldMapped := func(schemaField SchemaField, originalField genhelpers.Field, expected expectedValues) { assert.Equal(t, expected.name, schemaField.Name) assert.Equal(t, expected.schemaType, schemaField.SchemaType) assert.Equal(t, originalField.Name, schemaField.OriginalName) diff --git a/pkg/schemas/gen/templates.go b/pkg/schemas/gen/templates.go index 478e699c19..071ef8b630 100644 --- a/pkg/schemas/gen/templates.go +++ b/pkg/schemas/gen/templates.go @@ -1,13 +1,13 @@ package gen import ( - "strings" "text/template" _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" ) -// TODO [SNOW-1501905]: extract common funcs var ( //go:embed templates/preamble.tmpl preambleTemplateContent string @@ -15,14 +15,14 @@ var ( //go:embed templates/schema.tmpl schemaTemplateContent string - SchemaTemplate, _ = template.New("schemaTemplate").Funcs(template.FuncMap{ - "firstLetterLowercase": func(in string) string { return strings.ToLower(in[:1]) + in[1:] }, - }).Parse(schemaTemplateContent) + SchemaTemplate, _ = template.New("schemaTemplate").Parse(schemaTemplateContent) //go:embed templates/to_schema_mapper.tmpl toSchemaMapperTemplateContent string - ToSchemaMapperTemplate, _ = template.New("toSchemaMapperTemplate").Funcs(template.FuncMap{ - "firstLetterLowercase": func(in string) string { return strings.ToLower(in[:1]) + in[1:] }, - "runMapper": func(mapper Mapper, in ...string) string { return mapper(strings.Join(in, "")) }, - }).Parse(toSchemaMapperTemplateContent) + ToSchemaMapperTemplate, _ = template.New("toSchemaMapperTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.RunMapper, + )).Parse(toSchemaMapperTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, SchemaTemplate, ToSchemaMapperTemplate} ) diff --git a/pkg/schemas/gen/templates/schema.tmpl b/pkg/schemas/gen/templates/schema.tmpl index 3b805fbd6a..753e030e55 100644 --- a/pkg/schemas/gen/templates/schema.tmpl +++ b/pkg/schemas/gen/templates/schema.tmpl @@ -2,12 +2,12 @@ // Show{{ .Name }}Schema represents output of SHOW query for the single {{ .Name }}. var Show{{ .Name }}Schema = map[string]*schema.Schema{ - {{- range .SchemaFields }} - "{{ .Name }}": { - Type: schema.{{ .SchemaType }}, - Computed: true, - }, - {{- end }} +{{- range .SchemaFields }} + "{{ .Name }}": { + Type: schema.{{ .SchemaType }}, + Computed: true, + }, +{{- end }} } var _ = Show{{ .Name }}Schema diff --git a/pkg/schemas/gen/templates/to_schema_mapper.tmpl b/pkg/schemas/gen/templates/to_schema_mapper.tmpl index 65d7883c43..86d6e97eb8 100644 --- a/pkg/schemas/gen/templates/to_schema_mapper.tmpl +++ b/pkg/schemas/gen/templates/to_schema_mapper.tmpl @@ -1,19 +1,19 @@ {{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen.ShowResultSchemaModel*/ -}} -{{ $nameLowerCase := firstLetterLowercase .Name }} +{{ $nameLowerCase := FirstLetterLowercase .Name }} {{ $schemaName := $nameLowerCase | printf "%sSchema" }} func {{ .Name }}ToSchema({{ $nameLowerCase }} *{{ .SdkType }}) map[string]any { - {{ $schemaName }} := make(map[string]any) - {{- range .SchemaFields }} - {{ if .IsOriginalTypePointer -}} - if {{ $nameLowerCase }}.{{ .OriginalName }} != nil { - {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} - } - {{- else -}} - {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} - {{- end -}} - {{- end }} - return {{ $schemaName }} +{{ $schemaName }} := make(map[string]any) +{{- range .SchemaFields }} + {{ if .IsOriginalTypePointer -}} + if {{ $nameLowerCase }}.{{ .OriginalName }} != nil { + {{ $schemaName }}["{{ .Name }}"] = {{ RunMapper .Mapper $nameLowerCase "." .OriginalName }} + } + {{- else -}} + {{ $schemaName }}["{{ .Name }}"] = {{ RunMapper .Mapper $nameLowerCase "." .OriginalName }} + {{- end -}} +{{- end }} +return {{ $schemaName }} } var _ = {{ .Name }}ToSchema diff --git a/pkg/schemas/generate.go b/pkg/schemas/generate.go index be058d1d6b..e8901aac65 100644 --- a/pkg/schemas/generate.go +++ b/pkg/schemas/generate.go @@ -1,3 +1,3 @@ package schemas -//go:generate go run ./gen/main/main.go +//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/sdk/parameters.go b/pkg/sdk/parameters.go index 318b1de2fb..5b963db57c 100644 --- a/pkg/sdk/parameters.go +++ b/pkg/sdk/parameters.go @@ -587,6 +587,14 @@ const ( UserParameterWeekStart UserParameter = "WEEK_START" ) +type WarehouseParameter string + +const ( + WarehouseParameterMaxConcurrencyLevel WarehouseParameter = "MAX_CONCURRENCY_LEVEL" + WarehouseParameterStatementQueuedTimeoutInSeconds WarehouseParameter = "STATEMENT_QUEUED_TIMEOUT_IN_SECONDS" + WarehouseParameterStatementTimeoutInSeconds WarehouseParameter = "STATEMENT_TIMEOUT_IN_SECONDS" +) + // AccountParameters is based on https://docs.snowflake.com/en/sql-reference/parameters#account-parameters. type AccountParameters struct { // Account Parameters @@ -1012,13 +1020,14 @@ func (v *ParametersIn) validate() error { type ParameterType string const ( - ParameterTypeAccount ParameterType = "ACCOUNT" - ParameterTypeUser ParameterType = "USER" - ParameterTypeSession ParameterType = "SESSION" - ParameterTypeObject ParameterType = "OBJECT" - ParameterTypeWarehouse ParameterType = "WAREHOUSE" - ParameterTypeDatabase ParameterType = "DATABASE" - ParameterTypeSchema ParameterType = "SCHEMA" + ParameterTypeSnowflakeDefault ParameterType = "" + ParameterTypeAccount ParameterType = "ACCOUNT" + ParameterTypeUser ParameterType = "USER" + ParameterTypeSession ParameterType = "SESSION" + ParameterTypeObject ParameterType = "OBJECT" + ParameterTypeWarehouse ParameterType = "WAREHOUSE" + ParameterTypeDatabase ParameterType = "DATABASE" + ParameterTypeSchema ParameterType = "SCHEMA" ) type Parameter struct { diff --git a/pkg/sdk/poc/generator/file_util.go b/pkg/sdk/poc/generator/file_util.go deleted file mode 100644 index 1924265ef2..0000000000 --- a/pkg/sdk/poc/generator/file_util.go +++ /dev/null @@ -1,24 +0,0 @@ -package generator - -import ( - "bytes" - "go/format" - "log" - "os" - "path/filepath" -) - -func WriteCodeToFile(buffer *bytes.Buffer, fileName string) { - wd, errWd := os.Getwd() - if errWd != nil { - log.Panicln(errWd) - } - outputPath := filepath.Join(wd, fileName) - src, errSrcFormat := format.Source(buffer.Bytes()) - if errSrcFormat != nil { - log.Panicln(errSrcFormat) - } - if err := os.WriteFile(outputPath, src, 0o600); err != nil { - log.Panicln(err) - } -} diff --git a/pkg/sdk/poc/main.go b/pkg/sdk/poc/main.go index 81634fb637..ed5b340deb 100644 --- a/pkg/sdk/poc/main.go +++ b/pkg/sdk/poc/main.go @@ -103,7 +103,9 @@ func runAllTemplatesAndSave(definition *generator.Interface, file string) { func runTemplateAndSave(def *generator.Interface, genFunc func(io.Writer, *generator.Interface), fileName string) { buffer := bytes.Buffer{} genFunc(&buffer, def) - generator.WriteCodeToFile(&buffer, fileName) + if err := genhelpers.WriteCodeToFile(&buffer, fileName); err != nil { + log.Panicln(err) + } } func filenameFor(prefix string, part string) string { diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index 5d7d45a1df..0c99018e25 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -4,9 +4,10 @@ import ( "strings" "testing" - objectAssert "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + assertions "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/stretchr/testify/assert" @@ -47,135 +48,69 @@ func TestInt_Users(t *testing.T) { networkPolicy, networkPolicyCleanup := testClientHelper().NetworkPolicy.CreateNetworkPolicy(t) t.Cleanup(networkPolicyCleanup) - // TODO [SNOW-1348101]: extract as custom assertions - assertDefaultParameters := func(id sdk.AccountObjectIdentifier) { - parameters := testClientHelper().Parameter.ShowUserParameters(t, id) - - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterAbortDetachedQuery).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterAutocommit).Value) - assert.Equal(t, string(sdk.BinaryInputFormatHex), helpers.FindParameter(t, parameters, sdk.UserParameterBinaryInputFormat).Value) - assert.Equal(t, string(sdk.BinaryOutputFormatHex), helpers.FindParameter(t, parameters, sdk.UserParameterBinaryOutputFormat).Value) - assert.Equal(t, "1536", helpers.FindParameter(t, parameters, sdk.UserParameterClientMemoryLimit).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterClientMetadataRequestUseConnectionCtx).Value) - assert.Equal(t, "4", helpers.FindParameter(t, parameters, sdk.UserParameterClientPrefetchThreads).Value) - assert.Equal(t, "160", helpers.FindParameter(t, parameters, sdk.UserParameterClientResultChunkSize).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterClientResultColumnCaseInsensitive).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterClientSessionKeepAlive).Value) - assert.Equal(t, "3600", helpers.FindParameter(t, parameters, sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency).Value) - assert.Equal(t, string(sdk.ClientTimestampTypeMappingLtz), helpers.FindParameter(t, parameters, sdk.UserParameterClientTimestampTypeMapping).Value) - assert.Equal(t, "AUTO", helpers.FindParameter(t, parameters, sdk.UserParameterDateInputFormat).Value) - assert.Equal(t, "YYYY-MM-DD", helpers.FindParameter(t, parameters, sdk.UserParameterDateOutputFormat).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterEnableUnloadPhysicalTypeOptimization).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterErrorOnNondeterministicMerge).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterErrorOnNondeterministicUpdate).Value) - assert.Equal(t, string(sdk.GeographyOutputFormatGeoJSON), helpers.FindParameter(t, parameters, sdk.UserParameterGeographyOutputFormat).Value) - assert.Equal(t, string(sdk.GeometryOutputFormatGeoJSON), helpers.FindParameter(t, parameters, sdk.UserParameterGeometryOutputFormat).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterJdbcTreatDecimalAsInt).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterJdbcTreatTimestampNtzAsUtc).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterJdbcUseSessionTimezone).Value) - assert.Equal(t, "2", helpers.FindParameter(t, parameters, sdk.UserParameterJsonIndent).Value) - assert.Equal(t, "43200", helpers.FindParameter(t, parameters, sdk.UserParameterLockTimeout).Value) - assert.Equal(t, string(sdk.LogLevelOff), helpers.FindParameter(t, parameters, sdk.UserParameterLogLevel).Value) - assert.Equal(t, "1", helpers.FindParameter(t, parameters, sdk.UserParameterMultiStatementCount).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterNoorderSequenceAsDefault).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterOdbcTreatDecimalAsInt).Value) - assert.Equal(t, "", helpers.FindParameter(t, parameters, sdk.UserParameterQueryTag).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterQuotedIdentifiersIgnoreCase).Value) - assert.Equal(t, "0", helpers.FindParameter(t, parameters, sdk.UserParameterRowsPerResultset).Value) - assert.Equal(t, "", helpers.FindParameter(t, parameters, sdk.UserParameterS3StageVpceDnsName).Value) - assert.Equal(t, "$current, $public", helpers.FindParameter(t, parameters, sdk.UserParameterSearchPath).Value) - assert.Equal(t, "", helpers.FindParameter(t, parameters, sdk.UserParameterSimulatedDataSharingConsumer).Value) - assert.Equal(t, "0", helpers.FindParameter(t, parameters, sdk.UserParameterStatementQueuedTimeoutInSeconds).Value) - assert.Equal(t, "172800", helpers.FindParameter(t, parameters, sdk.UserParameterStatementTimeoutInSeconds).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterStrictJsonOutput).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampDayIsAlways24h).Value) - assert.Equal(t, "AUTO", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampInputFormat).Value) - assert.Equal(t, "", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampLtzOutputFormat).Value) - assert.Equal(t, "YYYY-MM-DD HH24:MI:SS.FF3", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampNtzOutputFormat).Value) - assert.Equal(t, "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampOutputFormat).Value) - assert.Equal(t, string(sdk.TimestampTypeMappingNtz), helpers.FindParameter(t, parameters, sdk.UserParameterTimestampTypeMapping).Value) - assert.Equal(t, "", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampTzOutputFormat).Value) - assert.Equal(t, "America/Los_Angeles", helpers.FindParameter(t, parameters, sdk.UserParameterTimezone).Value) - assert.Equal(t, "AUTO", helpers.FindParameter(t, parameters, sdk.UserParameterTimeInputFormat).Value) - assert.Equal(t, "HH24:MI:SS", helpers.FindParameter(t, parameters, sdk.UserParameterTimeOutputFormat).Value) - assert.Equal(t, string(sdk.TraceLevelOff), helpers.FindParameter(t, parameters, sdk.UserParameterTraceLevel).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterTransactionAbortOnError).Value) - assert.Equal(t, string(sdk.TransactionDefaultIsolationLevelReadCommitted), helpers.FindParameter(t, parameters, sdk.UserParameterTransactionDefaultIsolationLevel).Value) - assert.Equal(t, "1970", helpers.FindParameter(t, parameters, sdk.UserParameterTwoDigitCenturyStart).Value) - // lowercase by default in Snowflake - assert.Equal(t, strings.ToLower(string(sdk.UnsupportedDDLActionIgnore)), helpers.FindParameter(t, parameters, sdk.UserParameterUnsupportedDdlAction).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterUseCachedResult).Value) - assert.Equal(t, "0", helpers.FindParameter(t, parameters, sdk.UserParameterWeekOfYearPolicy).Value) - assert.Equal(t, "0", helpers.FindParameter(t, parameters, sdk.UserParameterWeekStart).Value) - - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterEnableUnredactedQuerySyntaxError).Value) - assert.Equal(t, "", helpers.FindParameter(t, parameters, sdk.UserParameterNetworkPolicy).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterPreventUnloadToInternalStages).Value) - } - - // TODO [SNOW-1348101]: extract as custom assertions - assertParametersSet := func(id sdk.AccountObjectIdentifier) { - parameters := testClientHelper().Parameter.ShowUserParameters(t, id) - - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterAbortDetachedQuery).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterAutocommit).Value) - assert.Equal(t, string(sdk.BinaryInputFormatUTF8), helpers.FindParameter(t, parameters, sdk.UserParameterBinaryInputFormat).Value) - assert.Equal(t, string(sdk.BinaryOutputFormatBase64), helpers.FindParameter(t, parameters, sdk.UserParameterBinaryOutputFormat).Value) - assert.Equal(t, "1024", helpers.FindParameter(t, parameters, sdk.UserParameterClientMemoryLimit).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterClientMetadataRequestUseConnectionCtx).Value) - assert.Equal(t, "2", helpers.FindParameter(t, parameters, sdk.UserParameterClientPrefetchThreads).Value) - assert.Equal(t, "48", helpers.FindParameter(t, parameters, sdk.UserParameterClientResultChunkSize).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterClientResultColumnCaseInsensitive).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterClientSessionKeepAlive).Value) - assert.Equal(t, "2400", helpers.FindParameter(t, parameters, sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency).Value) - assert.Equal(t, string(sdk.ClientTimestampTypeMappingNtz), helpers.FindParameter(t, parameters, sdk.UserParameterClientTimestampTypeMapping).Value) - assert.Equal(t, "YYYY-MM-DD", helpers.FindParameter(t, parameters, sdk.UserParameterDateInputFormat).Value) - assert.Equal(t, "YY-MM-DD", helpers.FindParameter(t, parameters, sdk.UserParameterDateOutputFormat).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterEnableUnloadPhysicalTypeOptimization).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterErrorOnNondeterministicMerge).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterErrorOnNondeterministicUpdate).Value) - assert.Equal(t, string(sdk.GeographyOutputFormatWKB), helpers.FindParameter(t, parameters, sdk.UserParameterGeographyOutputFormat).Value) - assert.Equal(t, string(sdk.GeometryOutputFormatWKB), helpers.FindParameter(t, parameters, sdk.UserParameterGeometryOutputFormat).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterJdbcTreatDecimalAsInt).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterJdbcTreatTimestampNtzAsUtc).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterJdbcUseSessionTimezone).Value) - assert.Equal(t, "4", helpers.FindParameter(t, parameters, sdk.UserParameterJsonIndent).Value) - assert.Equal(t, "21222", helpers.FindParameter(t, parameters, sdk.UserParameterLockTimeout).Value) - assert.Equal(t, string(sdk.LogLevelError), helpers.FindParameter(t, parameters, sdk.UserParameterLogLevel).Value) - assert.Equal(t, "0", helpers.FindParameter(t, parameters, sdk.UserParameterMultiStatementCount).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterNoorderSequenceAsDefault).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterOdbcTreatDecimalAsInt).Value) - assert.Equal(t, "some_tag", helpers.FindParameter(t, parameters, sdk.UserParameterQueryTag).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterQuotedIdentifiersIgnoreCase).Value) - assert.Equal(t, "2", helpers.FindParameter(t, parameters, sdk.UserParameterRowsPerResultset).Value) - assert.Equal(t, "vpce-some_dns-vpce.amazonaws.com", helpers.FindParameter(t, parameters, sdk.UserParameterS3StageVpceDnsName).Value) - assert.Equal(t, "$public, $current", helpers.FindParameter(t, parameters, sdk.UserParameterSearchPath).Value) - assert.Equal(t, "some_consumer", helpers.FindParameter(t, parameters, sdk.UserParameterSimulatedDataSharingConsumer).Value) - assert.Equal(t, "10", helpers.FindParameter(t, parameters, sdk.UserParameterStatementQueuedTimeoutInSeconds).Value) - assert.Equal(t, "10", helpers.FindParameter(t, parameters, sdk.UserParameterStatementTimeoutInSeconds).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterStrictJsonOutput).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampDayIsAlways24h).Value) - assert.Equal(t, "YYYY-MM-DD", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampInputFormat).Value) - assert.Equal(t, "YYYY-MM-DD HH24:MI:SS", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampLtzOutputFormat).Value) - assert.Equal(t, "YYYY-MM-DD HH24:MI:SS", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampNtzOutputFormat).Value) - assert.Equal(t, "YYYY-MM-DD HH24:MI:SS", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampOutputFormat).Value) - assert.Equal(t, string(sdk.TimestampTypeMappingLtz), helpers.FindParameter(t, parameters, sdk.UserParameterTimestampTypeMapping).Value) - assert.Equal(t, "YYYY-MM-DD HH24:MI:SS", helpers.FindParameter(t, parameters, sdk.UserParameterTimestampTzOutputFormat).Value) - assert.Equal(t, "Europe/Warsaw", helpers.FindParameter(t, parameters, sdk.UserParameterTimezone).Value) - assert.Equal(t, "HH24:MI", helpers.FindParameter(t, parameters, sdk.UserParameterTimeInputFormat).Value) - assert.Equal(t, "HH24:MI", helpers.FindParameter(t, parameters, sdk.UserParameterTimeOutputFormat).Value) - assert.Equal(t, string(sdk.TraceLevelOnEvent), helpers.FindParameter(t, parameters, sdk.UserParameterTraceLevel).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterTransactionAbortOnError).Value) - assert.Equal(t, string(sdk.TransactionDefaultIsolationLevelReadCommitted), helpers.FindParameter(t, parameters, sdk.UserParameterTransactionDefaultIsolationLevel).Value) - assert.Equal(t, "1980", helpers.FindParameter(t, parameters, sdk.UserParameterTwoDigitCenturyStart).Value) - assert.Equal(t, string(sdk.UnsupportedDDLActionFail), helpers.FindParameter(t, parameters, sdk.UserParameterUnsupportedDdlAction).Value) - assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterUseCachedResult).Value) - assert.Equal(t, "1", helpers.FindParameter(t, parameters, sdk.UserParameterWeekOfYearPolicy).Value) - assert.Equal(t, "1", helpers.FindParameter(t, parameters, sdk.UserParameterWeekStart).Value) - - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterEnableUnredactedQuerySyntaxError).Value) - assert.Equal(t, networkPolicy.ID().Name(), helpers.FindParameter(t, parameters, sdk.UserParameterNetworkPolicy).Value) - assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterPreventUnloadToInternalStages).Value) + assertParametersSet := func(t *testing.T, id sdk.AccountObjectIdentifier) { + t.Helper() + assertions.AssertThatObject(t, objectparametersassert.UserParameters(t, id). + HasEnableUnredactedQuerySyntaxError(true). + HasNetworkPolicy(networkPolicy.ID().Name()). + HasPreventUnloadToInternalStages(true). + HasAbortDetachedQuery(true). + HasAutocommit(false). + HasBinaryInputFormat(sdk.BinaryInputFormatUTF8). + HasBinaryOutputFormat(sdk.BinaryOutputFormatBase64). + HasClientMemoryLimit(1024). + HasClientMetadataRequestUseConnectionCtx(true). + HasClientPrefetchThreads(2). + HasClientResultChunkSize(48). + HasClientResultColumnCaseInsensitive(true). + HasClientSessionKeepAlive(true). + HasClientSessionKeepAliveHeartbeatFrequency(2400). + HasClientTimestampTypeMapping(sdk.ClientTimestampTypeMappingNtz). + HasDateInputFormat("YYYY-MM-DD"). + HasDateOutputFormat("YY-MM-DD"). + HasEnableUnloadPhysicalTypeOptimization(false). + HasErrorOnNondeterministicMerge(false). + HasErrorOnNondeterministicUpdate(true). + HasGeographyOutputFormat(sdk.GeographyOutputFormatWKB). + HasGeometryOutputFormat(sdk.GeometryOutputFormatWKB). + HasJdbcTreatDecimalAsInt(false). + HasJdbcTreatTimestampNtzAsUtc(true). + HasJdbcUseSessionTimezone(false). + HasJsonIndent(4). + HasLockTimeout(21222). + HasLogLevel(sdk.LogLevelError). + HasMultiStatementCount(0). + HasNoorderSequenceAsDefault(false). + HasOdbcTreatDecimalAsInt(true). + HasQueryTag("some_tag"). + HasQuotedIdentifiersIgnoreCase(true). + HasRowsPerResultset(2). + HasS3StageVpceDnsName("vpce-some_dns-vpce.amazonaws.com"). + HasSearchPath("$public, $current"). + HasSimulatedDataSharingConsumer("some_consumer"). + HasStatementQueuedTimeoutInSeconds(10). + HasStatementTimeoutInSeconds(10). + HasStrictJsonOutput(true). + HasTimestampDayIsAlways24h(true). + HasTimestampInputFormat("YYYY-MM-DD"). + HasTimestampLtzOutputFormat("YYYY-MM-DD HH24:MI:SS"). + HasTimestampNtzOutputFormat("YYYY-MM-DD HH24:MI:SS"). + HasTimestampOutputFormat("YYYY-MM-DD HH24:MI:SS"). + HasTimestampTypeMapping(sdk.TimestampTypeMappingLtz). + HasTimestampTzOutputFormat("YYYY-MM-DD HH24:MI:SS"). + HasTimezone("Europe/Warsaw"). + HasTimeInputFormat("HH24:MI"). + HasTimeOutputFormat("HH24:MI"). + HasTraceLevel(sdk.TraceLevelOnEvent). + HasTransactionAbortOnError(true). + HasTransactionDefaultIsolationLevel(sdk.TransactionDefaultIsolationLevelReadCommitted). + HasTwoDigitCenturyStart(1980). + HasUnsupportedDdlAction(sdk.UnsupportedDDLActionFail). + HasUseCachedResult(false). + HasWeekOfYearPolicy(1). + HasWeekStart(1). + HasBoolParameterValue(sdk.UserParameterUseCachedResult, false), + ) } t.Run("create: all types of params", func(t *testing.T) { @@ -220,7 +155,7 @@ func TestInt_Users(t *testing.T) { user, err := client.Users.ShowByID(ctx, id) require.NoError(t, err) - objectAssert.AssertThatObject(t, objectAssert.UserFromObject(t, user). + assertions.AssertThatObject(t, objectassert.UserFromObject(t, user). HasName(id.Name()). HasHasPassword(true). HasLoginName(strings.ToUpper(loginName)). @@ -267,7 +202,7 @@ func TestInt_Users(t *testing.T) { user, err := client.Users.ShowByID(ctx, id) require.NoError(t, err) - objectAssert.AssertThatObject(t, objectAssert.UserFromObject(t, user). + assertions.AssertThatObject(t, objectassert.UserFromObject(t, user). HasName(id.Name()). HasHasPassword(true). HasLoginName(strings.ToUpper(loginName)), @@ -292,7 +227,7 @@ func TestInt_Users(t *testing.T) { user, err := client.Users.ShowByID(ctx, id) require.NoError(t, err) - objectAssert.AssertThatObject(t, objectAssert.UserFromObject(t, user). + assertions.AssertThatObject(t, objectassert.UserFromObject(t, user). HasDefaults(id.Name()). HasDisplayName(id.Name()). HasOwner(currentRole.Name()), @@ -341,7 +276,7 @@ func TestInt_Users(t *testing.T) { user, err := client.Users.ShowByID(ctx, id) require.NoError(t, err) - objectAssert.AssertThatObject(t, objectAssert.User(t, user.ID()). + assertions.AssertThatObject(t, objectassert.User(t, user.ID()). HasName(user.Name). HasCreatedOnNotEmpty(). // login name is always case-insensitive @@ -430,7 +365,7 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - objectAssert.AssertThatObject(t, objectAssert.User(t, id). + assertions.AssertThatObject(t, objectassert.User(t, id). HasDefaultRole(defaultRole), ) }) @@ -449,7 +384,7 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - objectAssert.AssertThatObject(t, objectAssert.User(t, id). + assertions.AssertThatObject(t, objectassert.User(t, id). HasDefaultRole(defaultRole), ) }) @@ -490,7 +425,7 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - objectAssert.AssertThatObject(t, objectAssert.User(t, id). + assertions.AssertThatObject(t, objectassert.User(t, id). // login name is always case-insensitive HasLoginName(strings.ToUpper(randomWithHyphenAndMixedCase)). HasDisplayName(randomWithHyphenAndMixedCase). @@ -586,7 +521,7 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - assertParametersSet(id) + assertParametersSet(t, id) }) t.Run("create: with all parameters default", func(t *testing.T) { @@ -596,7 +531,10 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - assertDefaultParameters(id) + assertions.AssertThatObject(t, objectparametersassert.UserParameters(t, id). + HasAllDefaults(). + HasAllDefaultsExplicit(), + ) }) t.Run("alter: rename", func(t *testing.T) { @@ -622,7 +560,7 @@ func TestInt_Users(t *testing.T) { currentRole := testClientHelper().Context.CurrentRole(t) - objectAssert.AssertThatObject(t, objectAssert.UserFromObject(t, user). + assertions.AssertThatObject(t, objectassert.UserFromObject(t, user). HasDefaults(user.Name). HasDisplayName(user.Name). HasOwner(currentRole.Name()), @@ -657,7 +595,7 @@ func TestInt_Users(t *testing.T) { err := client.Users.Alter(ctx, user.ID(), alterOpts) require.NoError(t, err) - objectAssert.AssertThatObject(t, objectAssert.User(t, user.ID()). + assertions.AssertThatObject(t, objectassert.User(t, user.ID()). HasName(user.Name). HasCreatedOnNotEmpty(). // login name is always case-insensitive @@ -714,7 +652,7 @@ func TestInt_Users(t *testing.T) { err = client.Users.Alter(ctx, user.ID(), alterOpts) require.NoError(t, err) - objectAssert.AssertThatObject(t, objectAssert.User(t, user.ID()). + assertions.AssertThatObject(t, objectassert.User(t, user.ID()). HasDefaults(user.Name). HasDisplayName(""). HasOwner(currentRole.Name()), @@ -798,7 +736,7 @@ func TestInt_Users(t *testing.T) { err = client.Users.Alter(ctx, id, alterOpts) require.NoError(t, err) - assertParametersSet(id) + assertParametersSet(t, id) // unset is split into two because: // 1. this is how it's written in the docs https://docs.snowflake.com/en/sql-reference/sql/alter-user#syntax @@ -882,7 +820,10 @@ func TestInt_Users(t *testing.T) { err = client.Users.Alter(ctx, id, alterOpts) require.NoError(t, err) - assertDefaultParameters(id) + assertions.AssertThatObject(t, objectparametersassert.UserParameters(t, id). + HasAllDefaults(). + HasAllDefaultsExplicit(), + ) }) t.Run("alter: set and unset tags", func(t *testing.T) { diff --git a/pkg/sdk/testint/warehouses_integration_test.go b/pkg/sdk/testint/warehouses_integration_test.go index e5685dd0dc..43957cb340 100644 --- a/pkg/sdk/testint/warehouses_integration_test.go +++ b/pkg/sdk/testint/warehouses_integration_test.go @@ -5,8 +5,9 @@ import ( "testing" "time" - objectAssert "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + assertions "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" @@ -116,7 +117,7 @@ func TestInt_Warehouses(t *testing.T) { t.Cleanup(testClientHelper().Warehouse.DropWarehouseFunc(t, id)) // we can use the same assertion builder in the SDK tests - objectAssert.AssertThatObject(t, objectAssert.Warehouse(t, id). + assertions.AssertThatObject(t, objectassert.Warehouse(t, id). HasName(id.Name()). HasType(sdk.WarehouseTypeStandard). HasSize(sdk.WarehouseSizeSmall). @@ -148,7 +149,7 @@ func TestInt_Warehouses(t *testing.T) { assert.Equal(t, 90, warehouse.QueryAccelerationMaxScaleFactor) // we can also use the read object to initialize: - objectAssert.AssertThatObject(t, objectAssert.WarehouseFromObject(t, warehouse). + assertions.AssertThatObject(t, objectassert.WarehouseFromObject(t, warehouse). HasName(id.Name()). HasType(sdk.WarehouseTypeStandard). HasSize(sdk.WarehouseSizeSmall).