From 3e158bc535372a8bce36e3dc0573aca0337c155b Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 11:29:45 +0200 Subject: [PATCH 01/62] Add PoC of snowflake parameters assertions --- .../assert/snowflake_parameters_assertions.go | 88 +++++++++++++++++++ .../assert/user_parameters_snowflake.go | 49 +++++++++++ pkg/sdk/testint/users_integration_test.go | 14 +++ 3 files changed, 151 insertions(+) create mode 100644 pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go create mode 100644 pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go 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..76517d0a8a --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -0,0 +1,88 @@ +package assert + +import ( + "errors" + "fmt" + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "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 snowflakeParameterAssertion struct { + parameterName string + expectedValue string +} + +// 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 snowflakeParameterValueSet[T ~string](parameterName T, expected string) snowflakeParameterAssertion { + return snowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: expected} +} + +// 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 { + 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)) + } + } + + return errors.Join(result...) +} diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go new file mode 100644 index 0000000000..8d35a063b9 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -0,0 +1,49 @@ +package assert + +import ( + "strconv" + "testing" + + acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +// TODO: make assertions naming consistent (resource paramaters vs snowflake parameters) +type UserParametersAssert struct { + *SnowflakeParametersAssert[sdk.AccountObjectIdentifier] +} + +func UserParameters(t *testing.T, id sdk.AccountObjectIdentifier) *UserParametersAssert { + t.Helper() + return &UserParametersAssert{ + NewSnowflakeParametersAssertWithProvider(id, sdk.ObjectTypeUser, acc.TestClient().Parameter.ShowUserParameters), + } +} + +func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, parameters []*sdk.Parameter) *UserParametersAssert { + t.Helper() + return &UserParametersAssert{ + NewSnowflakeParametersAssertWithParameters(id, sdk.ObjectTypeUser, parameters), + } +} + +func (w *UserParametersAssert) HasAbortDetachedQuery(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterAbortDetachedQuery, strconv.FormatBool(expected))) + return w +} + +func (w *UserParametersAssert) HasBinaryInputFormat(expected sdk.BinaryInputFormat) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterBinaryInputFormat, string(expected))) + return w +} + +func (w *UserParametersAssert) HasClientMemoryLimit(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterClientMemoryLimit, strconv.Itoa(expected))) + return w +} + +func (w *UserParametersAssert) HasDateOutputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterDateOutputFormat, expected)) + return w +} diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index 5d7d45a1df..8bc01a1e5e 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -51,6 +51,20 @@ func TestInt_Users(t *testing.T) { assertDefaultParameters := func(id sdk.AccountObjectIdentifier) { parameters := testClientHelper().Parameter.ShowUserParameters(t, id) + objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). + HasAbortDetachedQuery(false). + HasBinaryInputFormat(sdk.BinaryInputFormatHex). + HasClientMemoryLimit(1536). + HasDateOutputFormat("YYYY-MM-DD"), + ) + + objectAssert.AssertThatObject(t, objectAssert.UserParametersPrefetched(t, id, parameters). + HasAbortDetachedQuery(true). + HasBinaryInputFormat(sdk.BinaryInputFormatUTF8). + HasClientMemoryLimit(1537). + HasDateOutputFormat("YY-MM-DD"), + ) + 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) From 751d730dcdd982ea1c031cfd6930d01614a3cebc Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 11:55:49 +0200 Subject: [PATCH 02/62] Add all user parameters assertions --- .../assert/snowflake_parameters_assertions.go | 17 ++ .../assert/user_parameters_snowflake.go | 279 +++++++++++++++++- 2 files changed, 292 insertions(+), 4 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index 76517d0a8a..eec4bd441e 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -3,6 +3,7 @@ package assert import ( "errors" "fmt" + "strconv" "testing" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers" @@ -51,10 +52,26 @@ func NewSnowflakeParametersAssertWithParameters[I sdk.ObjectIdentifier](id I, ob } } +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 snowflakeParameterValueSetGeneric[T ~string, U bool | int | ~string](parameterName T, expected U) snowflakeParameterAssertion { + return snowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: fmt.Sprintf("%s", expected)} +} + // 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) { diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index 8d35a063b9..acd0bbd340 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -1,7 +1,7 @@ package assert import ( - "strconv" + "strings" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" @@ -28,18 +28,83 @@ func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, para } } +func (w *UserParametersAssert) HasEnableUnredactedQuerySyntaxError(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) + return w +} + +func (w *UserParametersAssert) HasNetworkPolicy(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterNetworkPolicy, expected)) + return w +} + +func (w *UserParametersAssert) HasPreventUnloadToInternalStages(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) + return w +} + func (w *UserParametersAssert) HasAbortDetachedQuery(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterAbortDetachedQuery, strconv.FormatBool(expected))) + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterAbortDetachedQuery, expected)) + return w +} + +func (w *UserParametersAssert) HasAutocommit(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterAutocommit, expected)) return w } func (w *UserParametersAssert) HasBinaryInputFormat(expected sdk.BinaryInputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterBinaryInputFormat, string(expected))) + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryInputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasBinaryOutputFormat(expected sdk.BinaryOutputFormat) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryOutputFormat, expected)) return w } func (w *UserParametersAssert) HasClientMemoryLimit(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterClientMemoryLimit, strconv.Itoa(expected))) + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterClientMemoryLimit, expected)) + return w +} + +func (w *UserParametersAssert) HasClientMetadataRequestUseConnectionCtx(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) + return w +} + +func (w *UserParametersAssert) HasClientPrefetchThreads(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterClientPrefetchThreads, expected)) + return w +} + +func (w *UserParametersAssert) HasClientResultChunkSize(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterClientResultChunkSize, expected)) + return w +} + +func (w *UserParametersAssert) HasClientResultColumnCaseInsensitive(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) + return w +} + +func (w *UserParametersAssert) HasClientSessionKeepAlive(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterClientSessionKeepAlive, expected)) + return w +} + +func (w *UserParametersAssert) HasClientSessionKeepAliveHeartbeatFrequency(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) + return w +} + +func (w *UserParametersAssert) HasClientTimestampTypeMapping(expected sdk.ClientTimestampTypeMapping) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterClientTimestampTypeMapping, expected)) + return w +} + +func (w *UserParametersAssert) HasDateInputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterDateInputFormat, expected)) return w } @@ -47,3 +112,209 @@ func (w *UserParametersAssert) HasDateOutputFormat(expected string) *UserParamet w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterDateOutputFormat, expected)) return w } + +func (w *UserParametersAssert) HasEnableUnloadPhysicalTypeOptimization(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) + return w +} + +func (w *UserParametersAssert) HasErrorOnNondeterministicMerge(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) + return w +} + +func (w *UserParametersAssert) HasErrorOnNondeterministicUpdate(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) + return w +} + +func (w *UserParametersAssert) HasGeographyOutputFormat(expected sdk.GeographyOutputFormat) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeographyOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasGeometryOutputFormat(expected sdk.GeometryOutputFormat) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeometryOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasJdbcTreatDecimalAsInt(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) + return w +} + +func (w *UserParametersAssert) HasJdbcTreatTimestampNtzAsUtc(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) + return w +} + +func (w *UserParametersAssert) HasJdbcUseSessionTimezone(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) + return w +} + +func (w *UserParametersAssert) HasJsonIndent(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterJsonIndent, expected)) + return w +} + +func (w *UserParametersAssert) HasLockTimeout(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterLockTimeout, expected)) + return w +} + +func (w *UserParametersAssert) HasLogLevel(expected sdk.LogLevel) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterLogLevel, expected)) + return w +} + +func (w *UserParametersAssert) HasMultiStatementCount(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterMultiStatementCount, expected)) + return w +} + +func (w *UserParametersAssert) HasNoorderSequenceAsDefault(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) + return w +} + +func (w *UserParametersAssert) HasOdbcTreatDecimalAsInt(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) + return w +} + +func (w *UserParametersAssert) HasQueryTag(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterQueryTag, expected)) + return w +} + +func (w *UserParametersAssert) HasQuotedIdentifiersIgnoreCase(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) + return w +} + +func (w *UserParametersAssert) HasRowsPerResultset(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterRowsPerResultset, expected)) + return w +} + +func (w *UserParametersAssert) HasS3StageVpceDnsName(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterS3StageVpceDnsName, expected)) + return w +} + +func (w *UserParametersAssert) HasSearchPath(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterSearchPath, expected)) + return w +} + +func (w *UserParametersAssert) HasSimulatedDataSharingConsumer(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) + return w +} + +func (w *UserParametersAssert) HasStatementQueuedTimeoutInSeconds(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) + return w +} + +func (w *UserParametersAssert) HasStatementTimeoutInSeconds(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) + return w +} + +func (w *UserParametersAssert) HasStrictJsonOutput(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterStrictJsonOutput, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampDayIsAlways24h(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampInputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampInputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampLtzOutputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampNtzOutputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampOutputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampTypeMapping(expected sdk.TimestampTypeMapping) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTimestampTypeMapping, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampTzOutputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampTzOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimezone(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimezone, expected)) + return w +} + +func (w *UserParametersAssert) HasTimeInputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimeInputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimeOutputFormat(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimeOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTraceLevel(expected sdk.TraceLevel) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTraceLevel, expected)) + return w +} + +func (w *UserParametersAssert) HasTransactionAbortOnError(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterTransactionAbortOnError, expected)) + return w +} + +func (w *UserParametersAssert) HasTransactionDefaultIsolationLevel(expected sdk.TransactionDefaultIsolationLevel) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) + return w +} + +func (w *UserParametersAssert) HasTwoDigitCenturyStart(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterTwoDigitCenturyStart, expected)) + return w +} + +func (w *UserParametersAssert) HasUnsupportedDdlAction(expected sdk.UnsupportedDDLAction) *UserParametersAssert { + // lowercase by default in Snowflake + w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterUnsupportedDdlAction, strings.ToLower(string(expected)))) + return w +} + +func (w *UserParametersAssert) HasUseCachedResult(expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterUseCachedResult, expected)) + return w +} + +func (w *UserParametersAssert) HasWeekOfYearPolicy(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterWeekOfYearPolicy, expected)) + return w +} + +func (w *UserParametersAssert) HasWeekStart(expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterWeekStart, expected)) + return w +} From 79cf4a004acf25db1c991b560e35fb6c7b8e5685 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 12:09:19 +0200 Subject: [PATCH 03/62] Use assertions in user integration tests --- .../assert/snowflake_parameters_assertions.go | 1 + pkg/sdk/testint/users_integration_test.go | 122 +++++++++--------- 2 files changed, 61 insertions(+), 62 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index eec4bd441e..97723c197a 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -68,6 +68,7 @@ func snowflakeParameterValueSet[T ~string](parameterName T, expected string) sno return snowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: expected} } +// TODO: can we just replace all above with this one? func snowflakeParameterValueSetGeneric[T ~string, U bool | int | ~string](parameterName T, expected U) snowflakeParameterAssertion { return snowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: fmt.Sprintf("%s", expected)} } diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index 8bc01a1e5e..b10601d99b 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -127,69 +127,67 @@ func TestInt_Users(t *testing.T) { 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) + objectAssert.AssertThatObject(t, objectAssert.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), + ) } t.Run("create: all types of params", func(t *testing.T) { From 86b6890a1611e64801bbd89fa6bcf31f31b69ab1 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 12:30:04 +0200 Subject: [PATCH 04/62] Fix the tests --- .../assert/user_parameters_snowflake.go | 7 +++-- pkg/sdk/testint/users_integration_test.go | 26 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index acd0bbd340..38e04dbba2 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -1,7 +1,6 @@ package assert import ( - "strings" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" @@ -298,9 +297,9 @@ func (w *UserParametersAssert) HasTwoDigitCenturyStart(expected int) *UserParame return w } -func (w *UserParametersAssert) HasUnsupportedDdlAction(expected sdk.UnsupportedDDLAction) *UserParametersAssert { - // lowercase by default in Snowflake - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterUnsupportedDdlAction, strings.ToLower(string(expected)))) +// lowercase for ignore in snowflake by default but uppercase for FAIL +func (w *UserParametersAssert) HasUnsupportedDdlAction(expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterUnsupportedDdlAction, expected)) return w } diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index b10601d99b..ebf0047a97 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -48,7 +48,7 @@ func TestInt_Users(t *testing.T) { t.Cleanup(networkPolicyCleanup) // TODO [SNOW-1348101]: extract as custom assertions - assertDefaultParameters := func(id sdk.AccountObjectIdentifier) { + assertDefaultParameters := func(t *testing.T, id sdk.AccountObjectIdentifier) { parameters := testClientHelper().Parameter.ShowUserParameters(t, id) objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). @@ -58,12 +58,12 @@ func TestInt_Users(t *testing.T) { HasDateOutputFormat("YYYY-MM-DD"), ) - objectAssert.AssertThatObject(t, objectAssert.UserParametersPrefetched(t, id, parameters). - HasAbortDetachedQuery(true). - HasBinaryInputFormat(sdk.BinaryInputFormatUTF8). - HasClientMemoryLimit(1537). - HasDateOutputFormat("YY-MM-DD"), - ) + //objectAssert.AssertThatObject(t, objectAssert.UserParametersPrefetched(t, id, parameters). + // HasAbortDetachedQuery(true). + // HasBinaryInputFormat(sdk.BinaryInputFormatUTF8). + // HasClientMemoryLimit(1537). + // HasDateOutputFormat("YY-MM-DD"), + //) assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterAbortDetachedQuery).Value) assert.Equal(t, "true", helpers.FindParameter(t, parameters, sdk.UserParameterAutocommit).Value) @@ -127,7 +127,7 @@ func TestInt_Users(t *testing.T) { assert.Equal(t, "false", helpers.FindParameter(t, parameters, sdk.UserParameterPreventUnloadToInternalStages).Value) } - assertParametersSet := func(id sdk.AccountObjectIdentifier) { + assertParametersSet := func(t *testing.T, id sdk.AccountObjectIdentifier) { objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). HasEnableUnredactedQuerySyntaxError(true). HasNetworkPolicy(networkPolicy.ID().Name()). @@ -183,7 +183,7 @@ func TestInt_Users(t *testing.T) { HasTransactionAbortOnError(true). HasTransactionDefaultIsolationLevel(sdk.TransactionDefaultIsolationLevelReadCommitted). HasTwoDigitCenturyStart(1980). - HasUnsupportedDdlAction(sdk.UnsupportedDDLActionFail). + HasUnsupportedDdlAction(string(sdk.UnsupportedDDLActionFail)). HasUseCachedResult(false). HasWeekOfYearPolicy(1). HasWeekStart(1), @@ -598,7 +598,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) { @@ -608,7 +608,7 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - assertDefaultParameters(id) + assertDefaultParameters(t, id) }) t.Run("alter: rename", func(t *testing.T) { @@ -810,7 +810,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 @@ -894,7 +894,7 @@ func TestInt_Users(t *testing.T) { err = client.Users.Alter(ctx, id, alterOpts) require.NoError(t, err) - assertDefaultParameters(id) + assertDefaultParameters(t, id) }) t.Run("alter: set and unset tags", func(t *testing.T) { From 262f776f9bb40e7a201d47f5ea94d8e8eb9130e7 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 12:42:23 +0200 Subject: [PATCH 05/62] Add generic checks --- .../assert/user_parameters_snowflake.go | 23 +++++++++++++++++++ pkg/sdk/testint/users_integration_test.go | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index 38e04dbba2..b2103a14e5 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -27,6 +27,29 @@ func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, para } } +////////////////////////////// +// Generic parameter checks // +////////////////////////////// + +func (w *UserParametersAssert) HasBoolParameter(parameterName sdk.UserParameter, expected bool) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(parameterName, expected)) + return w +} + +func (w *UserParametersAssert) HasIntParameter(parameterName sdk.UserParameter, expected int) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterIntValueSet(parameterName, expected)) + return w +} + +func (w *UserParametersAssert) HasStringParameter(parameterName sdk.UserParameter, expected string) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterValueSet(parameterName, expected)) + return w +} + +/////////////////////////////// +// Specific parameter checks // +/////////////////////////////// + func (w *UserParametersAssert) HasEnableUnredactedQuerySyntaxError(expected bool) *UserParametersAssert { w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) return w diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index ebf0047a97..b1038445fc 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -186,7 +186,8 @@ func TestInt_Users(t *testing.T) { HasUnsupportedDdlAction(string(sdk.UnsupportedDDLActionFail)). HasUseCachedResult(false). HasWeekOfYearPolicy(1). - HasWeekStart(1), + HasWeekStart(1). + HasBoolParameter(sdk.UserParameterUseCachedResult, false), ) } From 077a861a12ac6cfe79549d54616f893c12141833 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 13:17:28 +0200 Subject: [PATCH 06/62] Add generic default checks --- .../assert/snowflake_parameters_assertions.go | 44 ++++++++- .../assert/user_parameters_snowflake.go | 85 ++++++++++++++++- .../assert/user_parameters_snowflake_ext.go | 70 ++++++++++++++ pkg/sdk/parameters.go | 13 +-- pkg/sdk/testint/users_integration_test.go | 93 ++----------------- 5 files changed, 210 insertions(+), 95 deletions(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index 97723c197a..ae56c8d05c 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -25,9 +25,19 @@ type SnowflakeParametersAssert[I sdk.ObjectIdentifier] struct { parameters []*sdk.Parameter } +type snowflakeParameterAssertionType int + +const ( + snowflakeParameterAssertionTypeExpectedValue = iota + snowflakeParameterAssertionTypeDefaultValue + snowflakeParameterAssertionTypeDefaultValueOnLevel +) + type snowflakeParameterAssertion struct { parameterName string expectedValue string + parameterType sdk.ParameterType + assertionType snowflakeParameterAssertionType } // NewSnowflakeParametersAssertWithProvider creates a SnowflakeParametersAssert with id and the provider. @@ -73,6 +83,14 @@ func snowflakeParameterValueSetGeneric[T ~string, U bool | int | ~string](parame return snowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: fmt.Sprintf("%s", 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} +} + // 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) { @@ -97,8 +115,30 @@ func (s *SnowflakeParametersAssert[_]) runSnowflakeParametersAssertions(t *testi var result []error for i, assertion := range s.assertions { - 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)) + 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, + )) + } + default: + return fmt.Errorf("cannot proceed with parameters assertion for object %s[%s]: assertion type must be specified", s.objectType, s.id.FullyQualifiedName()) } } diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index b2103a14e5..5191370ae4 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -31,21 +31,100 @@ func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, para // Generic parameter checks // ////////////////////////////// -func (w *UserParametersAssert) HasBoolParameter(parameterName sdk.UserParameter, expected bool) *UserParametersAssert { +func (w *UserParametersAssert) HasBoolParameterValue(parameterName sdk.UserParameter, expected bool) *UserParametersAssert { w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(parameterName, expected)) return w } -func (w *UserParametersAssert) HasIntParameter(parameterName sdk.UserParameter, expected int) *UserParametersAssert { +func (w *UserParametersAssert) HasIntParameterValue(parameterName sdk.UserParameter, expected int) *UserParametersAssert { w.assertions = append(w.assertions, snowflakeParameterIntValueSet(parameterName, expected)) return w } -func (w *UserParametersAssert) HasStringParameter(parameterName sdk.UserParameter, expected string) *UserParametersAssert { +func (w *UserParametersAssert) HasStringParameterValue(parameterName sdk.UserParameter, expected string) *UserParametersAssert { w.assertions = append(w.assertions, snowflakeParameterValueSet(parameterName, expected)) return w } +func (w *UserParametersAssert) HasDefaultParameterValue(parameterName sdk.UserParameter) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterDefaultValueSet(parameterName)) + return w +} + +func (w *UserParametersAssert) HasDefaultParameterValueOnLevel(parameterName sdk.UserParameter, parameterType sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, 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 a expected level +func (w *UserParametersAssert) HasAllDefaults() *UserParametersAssert { + return w. + 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.ParameterTypeAccount). + 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) +} + /////////////////////////////// // Specific parameter checks // /////////////////////////////// diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go new file mode 100644 index 0000000000..927f6479d3 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go @@ -0,0 +1,70 @@ +package assert + +import ( + "strings" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +// TODO: use generated explicit check default functions instead +func (w *UserParametersAssert) HasAllDefaultsExplicit() *UserParametersAssert { + return w. + HasEnableUnredactedQuerySyntaxError(false). + HasNetworkPolicy(""). + HasPreventUnloadToInternalStages(false). + HasAbortDetachedQuery(false). + HasAutocommit(true). + HasBinaryInputFormat(sdk.BinaryInputFormatHex). + HasBinaryOutputFormat(sdk.BinaryOutputFormatHex). + HasClientMemoryLimit(1536). + HasClientMetadataRequestUseConnectionCtx(false). + HasClientPrefetchThreads(4). + HasClientResultChunkSize(160). + HasClientResultColumnCaseInsensitive(false). + HasClientSessionKeepAlive(false). + HasClientSessionKeepAliveHeartbeatFrequency(3600). + HasClientTimestampTypeMapping(sdk.ClientTimestampTypeMappingLtz). + HasDateInputFormat("AUTO"). + HasDateOutputFormat("YYYY-MM-DD"). + HasEnableUnloadPhysicalTypeOptimization(true). + HasErrorOnNondeterministicMerge(true). + HasErrorOnNondeterministicUpdate(false). + HasGeographyOutputFormat(sdk.GeographyOutputFormatGeoJSON). + HasGeometryOutputFormat(sdk.GeometryOutputFormatGeoJSON). + HasJdbcTreatDecimalAsInt(true). + HasJdbcTreatTimestampNtzAsUtc(false). + HasJdbcUseSessionTimezone(true). + HasJsonIndent(2). + HasLockTimeout(43200). + HasLogLevel(sdk.LogLevelOff). + HasMultiStatementCount(1). + HasNoorderSequenceAsDefault(true). + HasOdbcTreatDecimalAsInt(false). + HasQueryTag(""). + HasQuotedIdentifiersIgnoreCase(false). + HasRowsPerResultset(0). + HasS3StageVpceDnsName(""). + HasSearchPath("$current, $public"). + HasSimulatedDataSharingConsumer(""). + HasStatementQueuedTimeoutInSeconds(0). + HasStatementTimeoutInSeconds(172800). + HasStrictJsonOutput(false). + HasTimestampDayIsAlways24h(false). + HasTimestampInputFormat("AUTO"). + HasTimestampLtzOutputFormat(""). + HasTimestampNtzOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3"). + HasTimestampOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM"). + HasTimestampTypeMapping(sdk.TimestampTypeMappingNtz). + HasTimestampTzOutputFormat(""). + HasTimezone("America/Los_Angeles"). + HasTimeInputFormat("AUTO"). + HasTimeOutputFormat("HH24:MI:SS"). + HasTraceLevel(sdk.TraceLevelOff). + HasTransactionAbortOnError(false). + HasTransactionDefaultIsolationLevel(sdk.TransactionDefaultIsolationLevelReadCommitted). + HasTwoDigitCenturyStart(1970). + HasUnsupportedDdlAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore))). + HasUseCachedResult(true). + HasWeekOfYearPolicy(0). + HasWeekStart(0) +} diff --git a/pkg/sdk/parameters.go b/pkg/sdk/parameters.go index 18dce38eaa..f68b217251 100644 --- a/pkg/sdk/parameters.go +++ b/pkg/sdk/parameters.go @@ -1012,12 +1012,13 @@ 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" + ParameterTypeSnowflakeDefault ParameterType = "" + ParameterTypeAccount ParameterType = "ACCOUNT" + ParameterTypeUser ParameterType = "USER" + ParameterTypeSession ParameterType = "SESSION" + ParameterTypeObject ParameterType = "OBJECT" + ParameterTypeWarehouse ParameterType = "WAREHOUSE" + ParameterTypeDatabase ParameterType = "DATABASE" ) type Parameter struct { diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index b1038445fc..4e4cad2a5f 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -6,7 +6,6 @@ import ( objectAssert "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/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/stretchr/testify/assert" @@ -47,86 +46,6 @@ func TestInt_Users(t *testing.T) { networkPolicy, networkPolicyCleanup := testClientHelper().NetworkPolicy.CreateNetworkPolicy(t) t.Cleanup(networkPolicyCleanup) - // TODO [SNOW-1348101]: extract as custom assertions - assertDefaultParameters := func(t *testing.T, id sdk.AccountObjectIdentifier) { - parameters := testClientHelper().Parameter.ShowUserParameters(t, id) - - objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). - HasAbortDetachedQuery(false). - HasBinaryInputFormat(sdk.BinaryInputFormatHex). - HasClientMemoryLimit(1536). - HasDateOutputFormat("YYYY-MM-DD"), - ) - - //objectAssert.AssertThatObject(t, objectAssert.UserParametersPrefetched(t, id, parameters). - // HasAbortDetachedQuery(true). - // HasBinaryInputFormat(sdk.BinaryInputFormatUTF8). - // HasClientMemoryLimit(1537). - // HasDateOutputFormat("YY-MM-DD"), - //) - - 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) - } - assertParametersSet := func(t *testing.T, id sdk.AccountObjectIdentifier) { objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). HasEnableUnredactedQuerySyntaxError(true). @@ -187,7 +106,7 @@ func TestInt_Users(t *testing.T) { HasUseCachedResult(false). HasWeekOfYearPolicy(1). HasWeekStart(1). - HasBoolParameter(sdk.UserParameterUseCachedResult, false), + HasBoolParameterValue(sdk.UserParameterUseCachedResult, false), ) } @@ -609,7 +528,10 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - assertDefaultParameters(t, id) + objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). + HasAllDefaults(). + HasAllDefaultsExplicit(), + ) }) t.Run("alter: rename", func(t *testing.T) { @@ -895,7 +817,10 @@ func TestInt_Users(t *testing.T) { err = client.Users.Alter(ctx, id, alterOpts) require.NoError(t, err) - assertDefaultParameters(t, id) + objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). + HasAllDefaults(). + HasAllDefaultsExplicit(), + ) }) t.Run("alter: set and unset tags", func(t *testing.T) { From 47bb554e2a715b66390739307a8b866af035aa04 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 13:25:35 +0200 Subject: [PATCH 07/62] Add TODOs --- .../assert/snowflake_parameters_assertions.go | 25 +++++++++++++++++++ .../assert/user_parameters_snowflake.go | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index ae56c8d05c..ccee3df673 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -144,3 +144,28 @@ func (s *SnowflakeParametersAssert[_]) runSnowflakeParametersAssertions(t *testi return errors.Join(result...) } + +func (s *SnowflakeParametersAssert[I]) HasBoolParameterValue(parameterName sdk.UserParameter, expected bool) *SnowflakeParametersAssert[I] { + s.assertions = append(s.assertions, snowflakeParameterBoolValueSet(parameterName, expected)) + return s +} + +func (s *SnowflakeParametersAssert[I]) HasIntParameterValue(parameterName sdk.UserParameter, expected int) *SnowflakeParametersAssert[I] { + s.assertions = append(s.assertions, snowflakeParameterIntValueSet(parameterName, expected)) + return s +} + +func (s *SnowflakeParametersAssert[I]) HasStringParameterValue(parameterName sdk.UserParameter, expected string) *SnowflakeParametersAssert[I] { + s.assertions = append(s.assertions, snowflakeParameterValueSet(parameterName, expected)) + return s +} + +func (s *SnowflakeParametersAssert[I]) HasDefaultParameterValue(parameterName sdk.UserParameter) *SnowflakeParametersAssert[I] { + s.assertions = append(s.assertions, snowflakeParameterDefaultValueSet(parameterName)) + return s +} + +func (s *SnowflakeParametersAssert[I]) HasDefaultParameterValueOnLevel(parameterName sdk.UserParameter, parameterType sdk.ParameterType) *SnowflakeParametersAssert[I] { + s.assertions = append(s.assertions, snowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) + return s +} diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index 5191370ae4..11e0d7575a 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -27,6 +27,7 @@ func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, para } } +// TODO: move this section to SnowflakeParametersAssert and not copy it for every object ////////////////////////////// // Generic parameter checks // ////////////////////////////// @@ -62,7 +63,7 @@ func (w *UserParametersAssert) HasDefaultParameterValueOnLevel(parameterName sdk // HasAllDefaults checks if all the parameters: // - have a default value by comparing current value of the sdk.Parameter with its default -// - have a expected level +// - have an expected level func (w *UserParametersAssert) HasAllDefaults() *UserParametersAssert { return w. HasDefaultParameterValueOnLevel(sdk.UserParameterEnableUnredactedQuerySyntaxError, sdk.ParameterTypeSnowflakeDefault). From 74412d2a3a46b461e0e9b653ff55961d72615911 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 13:50:05 +0200 Subject: [PATCH 08/62] Add TODOs --- .../assert/snowflake_parameters_assertions.go | 25 ------------------- .../assert/user_parameters_snowflake.go | 2 +- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index ccee3df673..ae56c8d05c 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -144,28 +144,3 @@ func (s *SnowflakeParametersAssert[_]) runSnowflakeParametersAssertions(t *testi return errors.Join(result...) } - -func (s *SnowflakeParametersAssert[I]) HasBoolParameterValue(parameterName sdk.UserParameter, expected bool) *SnowflakeParametersAssert[I] { - s.assertions = append(s.assertions, snowflakeParameterBoolValueSet(parameterName, expected)) - return s -} - -func (s *SnowflakeParametersAssert[I]) HasIntParameterValue(parameterName sdk.UserParameter, expected int) *SnowflakeParametersAssert[I] { - s.assertions = append(s.assertions, snowflakeParameterIntValueSet(parameterName, expected)) - return s -} - -func (s *SnowflakeParametersAssert[I]) HasStringParameterValue(parameterName sdk.UserParameter, expected string) *SnowflakeParametersAssert[I] { - s.assertions = append(s.assertions, snowflakeParameterValueSet(parameterName, expected)) - return s -} - -func (s *SnowflakeParametersAssert[I]) HasDefaultParameterValue(parameterName sdk.UserParameter) *SnowflakeParametersAssert[I] { - s.assertions = append(s.assertions, snowflakeParameterDefaultValueSet(parameterName)) - return s -} - -func (s *SnowflakeParametersAssert[I]) HasDefaultParameterValueOnLevel(parameterName sdk.UserParameter, parameterType sdk.ParameterType) *SnowflakeParametersAssert[I] { - s.assertions = append(s.assertions, snowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) - return s -} diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index 11e0d7575a..a3801833af 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -27,7 +27,7 @@ func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, para } } -// TODO: move this section to SnowflakeParametersAssert and not copy it for every object +// TODO: try to move this section to SnowflakeParametersAssert to not copy it for every object; persist the type-safe assertions ////////////////////////////// // Generic parameter checks // ////////////////////////////// From ed54823ea3cad1e91a29a9857952e486f6325f89 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 14:10:26 +0200 Subject: [PATCH 09/62] Add default checks for user parameters --- .../assert/user_parameters_snowflake.go | 472 ++++++++++++++++++ .../assert/user_parameters_snowflake_ext.go | 123 +++-- 2 files changed, 530 insertions(+), 65 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index a3801833af..f28a13936a 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -1,6 +1,7 @@ package assert import ( + "strings" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" @@ -130,6 +131,8 @@ func (w *UserParametersAssert) HasAllDefaults() *UserParametersAssert { // Specific parameter checks // /////////////////////////////// +// value checks + func (w *UserParametersAssert) HasEnableUnredactedQuerySyntaxError(expected bool) *UserParametersAssert { w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) return w @@ -420,3 +423,472 @@ func (w *UserParametersAssert) HasWeekStart(expected int) *UserParametersAssert w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterWeekStart, expected)) return w } + +// default checks + +func (w *UserParametersAssert) HasDefaultEnableUnredactedQuerySyntaxErrorValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterEnableUnredactedQuerySyntaxError) +} + +func (w *UserParametersAssert) HasDefaultNetworkPolicyValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterNetworkPolicy) +} + +func (w *UserParametersAssert) HasDefaultPreventUnloadToInternalStagesValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterPreventUnloadToInternalStages) +} + +func (w *UserParametersAssert) HasDefaultAbortDetachedQueryValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterAbortDetachedQuery) +} + +func (w *UserParametersAssert) HasDefaultAutocommitValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterAutocommit) +} + +func (w *UserParametersAssert) HasDefaultBinaryInputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterBinaryInputFormat) +} + +func (w *UserParametersAssert) HasDefaultBinaryOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterBinaryOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultClientMemoryLimitValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterClientMemoryLimit) +} + +func (w *UserParametersAssert) HasDefaultClientMetadataRequestUseConnectionCtxValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterClientMetadataRequestUseConnectionCtx) +} + +func (w *UserParametersAssert) HasDefaultClientPrefetchThreadsValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterClientPrefetchThreads) +} + +func (w *UserParametersAssert) HasDefaultClientResultChunkSizeValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterClientResultChunkSize) +} + +func (w *UserParametersAssert) HasDefaultClientResultColumnCaseInsensitiveValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterClientResultColumnCaseInsensitive) +} + +func (w *UserParametersAssert) HasDefaultClientSessionKeepAliveValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterClientSessionKeepAlive) +} + +func (w *UserParametersAssert) HasDefaultClientSessionKeepAliveHeartbeatFrequencyValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency) +} + +func (w *UserParametersAssert) HasDefaultClientTimestampTypeMappingValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterClientTimestampTypeMapping) +} + +func (w *UserParametersAssert) HasDefaultDateInputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterDateInputFormat) +} + +func (w *UserParametersAssert) HasDefaultDateOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterDateOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultEnableUnloadPhysicalTypeOptimizationValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterEnableUnloadPhysicalTypeOptimization) +} + +func (w *UserParametersAssert) HasDefaultErrorOnNondeterministicMergeValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterErrorOnNondeterministicMerge) +} + +func (w *UserParametersAssert) HasDefaultErrorOnNondeterministicUpdateValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterErrorOnNondeterministicUpdate) +} + +func (w *UserParametersAssert) HasDefaultGeographyOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterGeographyOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultGeometryOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterGeometryOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultJdbcTreatDecimalAsIntValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterJdbcTreatDecimalAsInt) +} + +func (w *UserParametersAssert) HasDefaultJdbcTreatTimestampNtzAsUtcValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterJdbcTreatTimestampNtzAsUtc) +} + +func (w *UserParametersAssert) HasDefaultJdbcUseSessionTimezoneValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterJdbcUseSessionTimezone) +} + +func (w *UserParametersAssert) HasDefaultJsonIndentValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterJsonIndent) +} + +func (w *UserParametersAssert) HasDefaultLockTimeoutValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterLockTimeout) +} + +func (w *UserParametersAssert) HasDefaultLogLevelValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterLogLevel) +} + +func (w *UserParametersAssert) HasDefaultMultiStatementCountValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterMultiStatementCount) +} + +func (w *UserParametersAssert) HasDefaultNoorderSequenceAsDefaultValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterNoorderSequenceAsDefault) +} + +func (w *UserParametersAssert) HasDefaultOdbcTreatDecimalAsIntValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterOdbcTreatDecimalAsInt) +} + +func (w *UserParametersAssert) HasDefaultQueryTagValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterQueryTag) +} + +func (w *UserParametersAssert) HasDefaultQuotedIdentifiersIgnoreCaseValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterQuotedIdentifiersIgnoreCase) +} + +func (w *UserParametersAssert) HasDefaultRowsPerResultsetValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterRowsPerResultset) +} + +func (w *UserParametersAssert) HasDefaultS3StageVpceDnsNameValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterS3StageVpceDnsName) +} + +func (w *UserParametersAssert) HasDefaultSearchPathValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterSearchPath) +} + +func (w *UserParametersAssert) HasDefaultSimulatedDataSharingConsumerValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterSimulatedDataSharingConsumer) +} + +func (w *UserParametersAssert) HasDefaultStatementQueuedTimeoutInSecondsValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterStatementQueuedTimeoutInSeconds) +} + +func (w *UserParametersAssert) HasDefaultStatementTimeoutInSecondsValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterStatementTimeoutInSeconds) +} + +func (w *UserParametersAssert) HasDefaultStrictJsonOutputValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterStrictJsonOutput) +} + +func (w *UserParametersAssert) HasDefaultTimestampDayIsAlways24hValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimestampDayIsAlways24h) +} + +func (w *UserParametersAssert) HasDefaultTimestampInputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimestampInputFormat) +} + +func (w *UserParametersAssert) HasDefaultTimestampLtzOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimestampLtzOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultTimestampNtzOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimestampNtzOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultTimestampOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimestampOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultTimestampTypeMappingValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimestampTypeMapping) +} + +func (w *UserParametersAssert) HasDefaultTimestampTzOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimestampTzOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultTimezoneValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimezone) +} + +func (w *UserParametersAssert) HasDefaultTimeInputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimeInputFormat) +} + +func (w *UserParametersAssert) HasDefaultTimeOutputFormatValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTimeOutputFormat) +} + +func (w *UserParametersAssert) HasDefaultTraceLevelValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTraceLevel) +} + +func (w *UserParametersAssert) HasDefaultTransactionAbortOnErrorValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTransactionAbortOnError) +} + +func (w *UserParametersAssert) HasDefaultTransactionDefaultIsolationLevelValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTransactionDefaultIsolationLevel) +} + +func (w *UserParametersAssert) HasDefaultTwoDigitCenturyStartValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterTwoDigitCenturyStart) +} + +func (w *UserParametersAssert) HasDefaultUnsupportedDdlActionValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterUnsupportedDdlAction) +} + +func (w *UserParametersAssert) HasDefaultUseCachedResultValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterUseCachedResult) +} + +func (w *UserParametersAssert) HasDefaultWeekOfYearPolicyValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterWeekOfYearPolicy) +} + +func (w *UserParametersAssert) HasDefaultWeekStartValue() *UserParametersAssert { + return w.HasDefaultParameterValue(sdk.UserParameterWeekStart) +} + +// default checks explicit + +func (w *UserParametersAssert) HasDefaultEnableUnredactedQuerySyntaxErrorValueExplicit() *UserParametersAssert { + return w.HasEnableUnredactedQuerySyntaxError(false) +} + +func (w *UserParametersAssert) HasDefaultNetworkPolicyValueExplicit() *UserParametersAssert { + return w.HasNetworkPolicy("") +} + +func (w *UserParametersAssert) HasDefaultPreventUnloadToInternalStagesValueExplicit() *UserParametersAssert { + return w.HasPreventUnloadToInternalStages(false) +} + +func (w *UserParametersAssert) HasDefaultAbortDetachedQueryValueExplicit() *UserParametersAssert { + return w.HasAbortDetachedQuery(false) +} + +func (w *UserParametersAssert) HasDefaultAutocommitValueExplicit() *UserParametersAssert { + return w.HasAutocommit(true) +} + +func (w *UserParametersAssert) HasDefaultBinaryInputFormatValueExplicit() *UserParametersAssert { + return w.HasBinaryInputFormat(sdk.BinaryInputFormatHex) +} + +func (w *UserParametersAssert) HasDefaultBinaryOutputFormatValueExplicit() *UserParametersAssert { + return w.HasBinaryOutputFormat(sdk.BinaryOutputFormatHex) +} + +func (w *UserParametersAssert) HasDefaultClientMemoryLimitValueExplicit() *UserParametersAssert { + return w.HasClientMemoryLimit(1536) +} + +func (w *UserParametersAssert) HasDefaultClientMetadataRequestUseConnectionCtxValueExplicit() *UserParametersAssert { + return w.HasClientMetadataRequestUseConnectionCtx(false) +} + +func (w *UserParametersAssert) HasDefaultClientPrefetchThreadsValueExplicit() *UserParametersAssert { + return w.HasClientPrefetchThreads(4) +} + +func (w *UserParametersAssert) HasDefaultClientResultChunkSizeValueExplicit() *UserParametersAssert { + return w.HasClientResultChunkSize(160) +} + +func (w *UserParametersAssert) HasDefaultClientResultColumnCaseInsensitiveValueExplicit() *UserParametersAssert { + return w.HasClientResultColumnCaseInsensitive(false) +} + +func (w *UserParametersAssert) HasDefaultClientSessionKeepAliveValueExplicit() *UserParametersAssert { + return w.HasClientSessionKeepAlive(false) +} + +func (w *UserParametersAssert) HasDefaultClientSessionKeepAliveHeartbeatFrequencyValueExplicit() *UserParametersAssert { + return w.HasClientSessionKeepAliveHeartbeatFrequency(3600) +} + +func (w *UserParametersAssert) HasDefaultClientTimestampTypeMappingValueExplicit() *UserParametersAssert { + return w.HasClientTimestampTypeMapping(sdk.ClientTimestampTypeMappingLtz) +} + +func (w *UserParametersAssert) HasDefaultDateInputFormatValueExplicit() *UserParametersAssert { + return w.HasDateInputFormat("AUTO") +} + +func (w *UserParametersAssert) HasDefaultDateOutputFormatValueExplicit() *UserParametersAssert { + return w.HasDateOutputFormat("YYYY-MM-DD") +} + +func (w *UserParametersAssert) HasDefaultEnableUnloadPhysicalTypeOptimizationValueExplicit() *UserParametersAssert { + return w.HasEnableUnloadPhysicalTypeOptimization(true) +} + +func (w *UserParametersAssert) HasDefaultErrorOnNondeterministicMergeValueExplicit() *UserParametersAssert { + return w.HasErrorOnNondeterministicMerge(true) +} + +func (w *UserParametersAssert) HasDefaultErrorOnNondeterministicUpdateValueExplicit() *UserParametersAssert { + return w.HasErrorOnNondeterministicUpdate(false) +} + +func (w *UserParametersAssert) HasDefaultGeographyOutputFormatValueExplicit() *UserParametersAssert { + return w.HasGeographyOutputFormat(sdk.GeographyOutputFormatGeoJSON) +} + +func (w *UserParametersAssert) HasDefaultGeometryOutputFormatValueExplicit() *UserParametersAssert { + return w.HasGeometryOutputFormat(sdk.GeometryOutputFormatGeoJSON) +} + +func (w *UserParametersAssert) HasDefaultJdbcTreatDecimalAsIntValueExplicit() *UserParametersAssert { + return w.HasJdbcTreatDecimalAsInt(true) +} + +func (w *UserParametersAssert) HasDefaultJdbcTreatTimestampNtzAsUtcValueExplicit() *UserParametersAssert { + return w.HasJdbcTreatTimestampNtzAsUtc(false) +} + +func (w *UserParametersAssert) HasDefaultJdbcUseSessionTimezoneValueExplicit() *UserParametersAssert { + return w.HasJdbcUseSessionTimezone(true) +} + +func (w *UserParametersAssert) HasDefaultJsonIndentValueExplicit() *UserParametersAssert { + return w.HasJsonIndent(2) +} + +func (w *UserParametersAssert) HasDefaultLockTimeoutValueExplicit() *UserParametersAssert { + return w.HasLockTimeout(43200) +} + +func (w *UserParametersAssert) HasDefaultLogLevelValueExplicit() *UserParametersAssert { + return w.HasLogLevel(sdk.LogLevelOff) +} + +func (w *UserParametersAssert) HasDefaultMultiStatementCountValueExplicit() *UserParametersAssert { + return w.HasMultiStatementCount(1) +} + +func (w *UserParametersAssert) HasDefaultNoorderSequenceAsDefaultValueExplicit() *UserParametersAssert { + return w.HasNoorderSequenceAsDefault(true) +} + +func (w *UserParametersAssert) HasDefaultOdbcTreatDecimalAsIntValueExplicit() *UserParametersAssert { + return w.HasOdbcTreatDecimalAsInt(false) +} + +func (w *UserParametersAssert) HasDefaultQueryTagValueExplicit() *UserParametersAssert { + return w.HasQueryTag("") +} + +func (w *UserParametersAssert) HasDefaultQuotedIdentifiersIgnoreCaseValueExplicit() *UserParametersAssert { + return w.HasQuotedIdentifiersIgnoreCase(false) +} + +func (w *UserParametersAssert) HasDefaultRowsPerResultsetValueExplicit() *UserParametersAssert { + return w.HasRowsPerResultset(0) +} + +func (w *UserParametersAssert) HasDefaultS3StageVpceDnsNameValueExplicit() *UserParametersAssert { + return w.HasS3StageVpceDnsName("") +} + +func (w *UserParametersAssert) HasDefaultSearchPathValueExplicit() *UserParametersAssert { + return w.HasSearchPath("$current, $public") +} + +func (w *UserParametersAssert) HasDefaultSimulatedDataSharingConsumerValueExplicit() *UserParametersAssert { + return w.HasSimulatedDataSharingConsumer("") +} + +func (w *UserParametersAssert) HasDefaultStatementQueuedTimeoutInSecondsValueExplicit() *UserParametersAssert { + return w.HasStatementQueuedTimeoutInSeconds(0) +} + +func (w *UserParametersAssert) HasDefaultStatementTimeoutInSecondsValueExplicit() *UserParametersAssert { + return w.HasStatementTimeoutInSeconds(172800) +} + +func (w *UserParametersAssert) HasDefaultStrictJsonOutputValueExplicit() *UserParametersAssert { + return w.HasStrictJsonOutput(false) +} + +func (w *UserParametersAssert) HasDefaultTimestampDayIsAlways24hValueExplicit() *UserParametersAssert { + return w.HasTimestampDayIsAlways24h(false) +} + +func (w *UserParametersAssert) HasDefaultTimestampInputFormatValueExplicit() *UserParametersAssert { + return w.HasTimestampInputFormat("AUTO") +} + +func (w *UserParametersAssert) HasDefaultTimestampLtzOutputFormatValueExplicit() *UserParametersAssert { + return w.HasTimestampLtzOutputFormat("") +} + +func (w *UserParametersAssert) HasDefaultTimestampNtzOutputFormatValueExplicit() *UserParametersAssert { + return w.HasTimestampNtzOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3") +} + +func (w *UserParametersAssert) HasDefaultTimestampOutputFormatValueExplicit() *UserParametersAssert { + return w.HasTimestampOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM") +} + +func (w *UserParametersAssert) HasDefaultTimestampTypeMappingValueExplicit() *UserParametersAssert { + return w.HasTimestampTypeMapping(sdk.TimestampTypeMappingNtz) +} + +func (w *UserParametersAssert) HasDefaultTimestampTzOutputFormatValueExplicit() *UserParametersAssert { + return w.HasTimestampTzOutputFormat("") +} + +func (w *UserParametersAssert) HasDefaultTimezoneValueExplicit() *UserParametersAssert { + return w.HasTimezone("America/Los_Angeles") +} + +func (w *UserParametersAssert) HasDefaultTimeInputFormatValueExplicit() *UserParametersAssert { + return w.HasTimeInputFormat("AUTO") +} + +func (w *UserParametersAssert) HasDefaultTimeOutputFormatValueExplicit() *UserParametersAssert { + return w.HasTimeOutputFormat("HH24:MI:SS") +} + +func (w *UserParametersAssert) HasDefaultTraceLevelValueExplicit() *UserParametersAssert { + return w.HasTraceLevel(sdk.TraceLevelOff) +} + +func (w *UserParametersAssert) HasDefaultTransactionAbortOnErrorValueExplicit() *UserParametersAssert { + return w.HasTransactionAbortOnError(false) +} + +func (w *UserParametersAssert) HasDefaultTransactionDefaultIsolationLevelValueExplicit() *UserParametersAssert { + return w.HasTransactionDefaultIsolationLevel(sdk.TransactionDefaultIsolationLevelReadCommitted) +} + +func (w *UserParametersAssert) HasDefaultTwoDigitCenturyStartValueExplicit() *UserParametersAssert { + return w.HasTwoDigitCenturyStart(1970) +} + +// lowercase for ignore in snowflake by default but uppercase for FAIL +func (w *UserParametersAssert) HasDefaultUnsupportedDdlActionValueExplicit() *UserParametersAssert { + return w.HasUnsupportedDdlAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore))) +} + +func (w *UserParametersAssert) HasDefaultUseCachedResultValueExplicit() *UserParametersAssert { + return w.HasUseCachedResult(true) +} + +func (w *UserParametersAssert) HasDefaultWeekOfYearPolicyValueExplicit() *UserParametersAssert { + return w.HasWeekOfYearPolicy(0) +} + +func (w *UserParametersAssert) HasDefaultWeekStartValueExplicit() *UserParametersAssert { + return w.HasWeekStart(0) +} diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go index 927f6479d3..62ea272379 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go @@ -1,70 +1,63 @@ package assert -import ( - "strings" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" -) - -// TODO: use generated explicit check default functions instead func (w *UserParametersAssert) HasAllDefaultsExplicit() *UserParametersAssert { return w. - HasEnableUnredactedQuerySyntaxError(false). - HasNetworkPolicy(""). - HasPreventUnloadToInternalStages(false). - HasAbortDetachedQuery(false). - HasAutocommit(true). - HasBinaryInputFormat(sdk.BinaryInputFormatHex). - HasBinaryOutputFormat(sdk.BinaryOutputFormatHex). - HasClientMemoryLimit(1536). - HasClientMetadataRequestUseConnectionCtx(false). - HasClientPrefetchThreads(4). - HasClientResultChunkSize(160). - HasClientResultColumnCaseInsensitive(false). - HasClientSessionKeepAlive(false). - HasClientSessionKeepAliveHeartbeatFrequency(3600). - HasClientTimestampTypeMapping(sdk.ClientTimestampTypeMappingLtz). - HasDateInputFormat("AUTO"). - HasDateOutputFormat("YYYY-MM-DD"). - HasEnableUnloadPhysicalTypeOptimization(true). - HasErrorOnNondeterministicMerge(true). - HasErrorOnNondeterministicUpdate(false). - HasGeographyOutputFormat(sdk.GeographyOutputFormatGeoJSON). - HasGeometryOutputFormat(sdk.GeometryOutputFormatGeoJSON). - HasJdbcTreatDecimalAsInt(true). - HasJdbcTreatTimestampNtzAsUtc(false). - HasJdbcUseSessionTimezone(true). - HasJsonIndent(2). - HasLockTimeout(43200). - HasLogLevel(sdk.LogLevelOff). - HasMultiStatementCount(1). - HasNoorderSequenceAsDefault(true). - HasOdbcTreatDecimalAsInt(false). - HasQueryTag(""). - HasQuotedIdentifiersIgnoreCase(false). - HasRowsPerResultset(0). - HasS3StageVpceDnsName(""). - HasSearchPath("$current, $public"). - HasSimulatedDataSharingConsumer(""). - HasStatementQueuedTimeoutInSeconds(0). - HasStatementTimeoutInSeconds(172800). - HasStrictJsonOutput(false). - HasTimestampDayIsAlways24h(false). - HasTimestampInputFormat("AUTO"). - HasTimestampLtzOutputFormat(""). - HasTimestampNtzOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3"). - HasTimestampOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM"). - HasTimestampTypeMapping(sdk.TimestampTypeMappingNtz). - HasTimestampTzOutputFormat(""). - HasTimezone("America/Los_Angeles"). - HasTimeInputFormat("AUTO"). - HasTimeOutputFormat("HH24:MI:SS"). - HasTraceLevel(sdk.TraceLevelOff). - HasTransactionAbortOnError(false). - HasTransactionDefaultIsolationLevel(sdk.TransactionDefaultIsolationLevelReadCommitted). - HasTwoDigitCenturyStart(1970). - HasUnsupportedDdlAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore))). - HasUseCachedResult(true). - HasWeekOfYearPolicy(0). - HasWeekStart(0) + 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() } From 52f99e942ba110ad64165bc31e5b536f472a7132 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 14:20:51 +0200 Subject: [PATCH 10/62] Add level assertions --- .../assert/snowflake_parameters_assertions.go | 12 + .../assert/user_parameters_snowflake.go | 354 ++++++++++++++++++ .../assert/user_parameters_snowflake_ext.go | 63 ---- 3 files changed, 366 insertions(+), 63 deletions(-) delete mode 100644 pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index ae56c8d05c..20a48c3155 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -31,6 +31,7 @@ const ( snowflakeParameterAssertionTypeExpectedValue = iota snowflakeParameterAssertionTypeDefaultValue snowflakeParameterAssertionTypeDefaultValueOnLevel + snowflakeParameterAssertionTypeLevel ) type snowflakeParameterAssertion struct { @@ -91,6 +92,10 @@ func snowflakeParameterDefaultValueOnLevelSet[T ~string](parameterName T, parame 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} +} + // 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) { @@ -137,6 +142,13 @@ func (s *SnowflakeParametersAssert[_]) runSnowflakeParametersAssertions(t *testi 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()) } diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index f28a13936a..be751d4828 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -127,6 +127,68 @@ func (w *UserParametersAssert) HasAllDefaults() *UserParametersAssert { HasDefaultParameterValueOnLevel(sdk.UserParameterWeekStart, sdk.ParameterTypeSnowflakeDefault) } +func (w *UserParametersAssert) HasAllDefaultsExplicit() *UserParametersAssert { + return w. + 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() +} + /////////////////////////////// // Specific parameter checks // /////////////////////////////// @@ -424,6 +486,298 @@ func (w *UserParametersAssert) HasWeekStart(expected int) *UserParametersAssert return w } +// level checks + +func (w *UserParametersAssert) HasEnableUnredactedQuerySyntaxErrorLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) + return w +} + +func (w *UserParametersAssert) HasNetworkPolicyLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterNetworkPolicy, expected)) + return w +} + +func (w *UserParametersAssert) HasPreventUnloadToInternalStagesLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) + return w +} + +func (w *UserParametersAssert) HasAbortDetachedQueryLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterAbortDetachedQuery, expected)) + return w +} + +func (w *UserParametersAssert) HasAutocommitLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterAutocommit, expected)) + return w +} + +func (w *UserParametersAssert) HasBinaryInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterBinaryInputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasBinaryOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterBinaryOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasClientMemoryLimitLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientMemoryLimit, expected)) + return w +} + +func (w *UserParametersAssert) HasClientMetadataRequestUseConnectionCtxLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) + return w +} + +func (w *UserParametersAssert) HasClientPrefetchThreadsLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientPrefetchThreads, expected)) + return w +} + +func (w *UserParametersAssert) HasClientResultChunkSizeLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientResultChunkSize, expected)) + return w +} + +func (w *UserParametersAssert) HasClientResultColumnCaseInsensitiveLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) + return w +} + +func (w *UserParametersAssert) HasClientSessionKeepAliveLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAlive, expected)) + return w +} + +func (w *UserParametersAssert) HasClientSessionKeepAliveHeartbeatFrequencyLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) + return w +} + +func (w *UserParametersAssert) HasClientTimestampTypeMappingLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientTimestampTypeMapping, expected)) + return w +} + +func (w *UserParametersAssert) HasDateInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterDateInputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasDateOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterDateOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasEnableUnloadPhysicalTypeOptimizationLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) + return w +} + +func (w *UserParametersAssert) HasErrorOnNondeterministicMergeLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) + return w +} + +func (w *UserParametersAssert) HasErrorOnNondeterministicUpdateLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) + return w +} + +func (w *UserParametersAssert) HasGeographyOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterGeographyOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasGeometryOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterGeometryOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasJdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) + return w +} + +func (w *UserParametersAssert) HasJdbcTreatTimestampNtzAsUtcLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) + return w +} + +func (w *UserParametersAssert) HasJdbcUseSessionTimezoneLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) + return w +} + +func (w *UserParametersAssert) HasJsonIndentLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterJsonIndent, expected)) + return w +} + +func (w *UserParametersAssert) HasLockTimeoutLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterLockTimeout, expected)) + return w +} + +func (w *UserParametersAssert) HasLogLevelLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterLogLevel, expected)) + return w +} + +func (w *UserParametersAssert) HasMultiStatementCountLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterMultiStatementCount, expected)) + return w +} + +func (w *UserParametersAssert) HasNoorderSequenceAsDefaultLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) + return w +} + +func (w *UserParametersAssert) HasOdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) + return w +} + +func (w *UserParametersAssert) HasQueryTagLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterQueryTag, expected)) + return w +} + +func (w *UserParametersAssert) HasQuotedIdentifiersIgnoreCaseLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) + return w +} + +func (w *UserParametersAssert) HasRowsPerResultsetLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterRowsPerResultset, expected)) + return w +} + +func (w *UserParametersAssert) HasS3StageVpceDnsNameLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterS3StageVpceDnsName, expected)) + return w +} + +func (w *UserParametersAssert) HasSearchPathLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterSearchPath, expected)) + return w +} + +func (w *UserParametersAssert) HasSimulatedDataSharingConsumerLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) + return w +} + +func (w *UserParametersAssert) HasStatementQueuedTimeoutInSecondsLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) + return w +} + +func (w *UserParametersAssert) HasStatementTimeoutInSecondsLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) + return w +} + +func (w *UserParametersAssert) HasStrictJsonOutputLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterStrictJsonOutput, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampDayIsAlways24hLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampInputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampLtzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampNtzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampTypeMappingLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampTypeMapping, expected)) + return w +} + +func (w *UserParametersAssert) HasTimestampTzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampTzOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimezoneLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimezone, expected)) + return w +} + +func (w *UserParametersAssert) HasTimeInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimeInputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTimeOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimeOutputFormat, expected)) + return w +} + +func (w *UserParametersAssert) HasTraceLevelLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTraceLevel, expected)) + return w +} + +func (w *UserParametersAssert) HasTransactionAbortOnErrorLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTransactionAbortOnError, expected)) + return w +} + +func (w *UserParametersAssert) HasTransactionDefaultIsolationLevelLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) + return w +} + +func (w *UserParametersAssert) HasTwoDigitCenturyStartLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTwoDigitCenturyStart, expected)) + return w +} + +func (w *UserParametersAssert) HasUnsupportedDdlActionLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterUnsupportedDdlAction, expected)) + return w +} + +func (w *UserParametersAssert) HasUseCachedResultLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterUseCachedResult, expected)) + return w +} + +func (w *UserParametersAssert) HasWeekOfYearPolicyLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterWeekOfYearPolicy, expected)) + return w +} + +func (w *UserParametersAssert) HasWeekStartLevel(expected sdk.ParameterType) *UserParametersAssert { + w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterWeekStart, expected)) + return w +} + // default checks func (w *UserParametersAssert) HasDefaultEnableUnredactedQuerySyntaxErrorValue() *UserParametersAssert { diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go deleted file mode 100644 index 62ea272379..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake_ext.go +++ /dev/null @@ -1,63 +0,0 @@ -package assert - -func (w *UserParametersAssert) HasAllDefaultsExplicit() *UserParametersAssert { - return w. - 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() -} From ff89925cd945352f45d63845201bef0fece214ad Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 14:30:39 +0200 Subject: [PATCH 11/62] Move gen utils to separate gencommons --- pkg/{schemas/gen => internal/gencommons}/util.go | 2 +- pkg/{schemas/gen => internal/gencommons}/util_test.go | 2 +- pkg/schemas/gen/main/main.go | 5 +++-- pkg/schemas/gen/schema_field_mapper.go | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) rename pkg/{schemas/gen => internal/gencommons}/util.go (98%) rename pkg/{schemas/gen => internal/gencommons}/util_test.go (99%) diff --git a/pkg/schemas/gen/util.go b/pkg/internal/gencommons/util.go similarity index 98% rename from pkg/schemas/gen/util.go rename to pkg/internal/gencommons/util.go index d1d08399bc..2143e62541 100644 --- a/pkg/schemas/gen/util.go +++ b/pkg/internal/gencommons/util.go @@ -1,4 +1,4 @@ -package gen +package gencommons import ( "regexp" diff --git a/pkg/schemas/gen/util_test.go b/pkg/internal/gencommons/util_test.go similarity index 99% rename from pkg/schemas/gen/util_test.go rename to pkg/internal/gencommons/util_test.go index dd1ea30251..0c3720f2ed 100644 --- a/pkg/schemas/gen/util_test.go +++ b/pkg/internal/gencommons/util_test.go @@ -1,4 +1,4 @@ -package gen +package gencommons import ( "fmt" diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 23e68ef4f3..eba022667d 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -11,6 +11,7 @@ import ( "path/filepath" "slices" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" "golang.org/x/exp/maps" ) @@ -37,7 +38,7 @@ func printAllStructsFields(allStructs []gen.Struct) { 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(gencommons.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) } fmt.Println() } @@ -75,7 +76,7 @@ func saveAllGeneratedSchemas(allStructs []gen.Struct) { buffer := bytes.Buffer{} model := gen.ModelFromStructDetails(s) gen.Generate(model, &buffer) - filename := gen.ToSnakeCase(model.Name) + "_gen.go" + filename := gencommons.ToSnakeCase(model.Name) + "_gen.go" writeCodeToFile(&buffer, filename) } } diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go index 189d70456a..872efa9fc5 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -33,7 +34,7 @@ var ( func MapToSchemaField(field Field) SchemaField { isPointer := field.IsPointer() concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") - name := ToSnakeCase(field.Name) + name := gencommons.ToSnakeCase(field.Name) switch concreteTypeWithoutPtr { case "string": return SchemaField{name, schema.TypeString, field.Name, isPointer, Identity} From b4a8c71e6bc76b5f364377459df8b9ab04476d0c Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 14:37:17 +0200 Subject: [PATCH 12/62] Move struct details extractor to separate gencommons --- .../gencommons}/struct_details_extractor.go | 2 +- .../struct_details_extractor_test.go | 2 +- pkg/schemas/gen/main/main.go | 12 ++-- pkg/schemas/gen/model.go | 8 ++- pkg/schemas/gen/schema_field_mapper.go | 2 +- pkg/schemas/gen/schema_field_mapper_test.go | 59 ++++++++++--------- 6 files changed, 45 insertions(+), 40 deletions(-) rename pkg/{schemas/gen => internal/gencommons}/struct_details_extractor.go (98%) rename pkg/{schemas/gen => internal/gencommons}/struct_details_extractor_test.go (99%) diff --git a/pkg/schemas/gen/struct_details_extractor.go b/pkg/internal/gencommons/struct_details_extractor.go similarity index 98% rename from pkg/schemas/gen/struct_details_extractor.go rename to pkg/internal/gencommons/struct_details_extractor.go index 4e92004ff8..1501fe4247 100644 --- a/pkg/schemas/gen/struct_details_extractor.go +++ b/pkg/internal/gencommons/struct_details_extractor.go @@ -1,4 +1,4 @@ -package gen +package gencommons import ( "reflect" diff --git a/pkg/schemas/gen/struct_details_extractor_test.go b/pkg/internal/gencommons/struct_details_extractor_test.go similarity index 99% rename from pkg/schemas/gen/struct_details_extractor_test.go rename to pkg/internal/gencommons/struct_details_extractor_test.go index 098e081f47..84a7159762 100644 --- a/pkg/schemas/gen/struct_details_extractor_test.go +++ b/pkg/internal/gencommons/struct_details_extractor_test.go @@ -1,4 +1,4 @@ -package gen +package gencommons import ( "testing" diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index eba022667d..5faed749d9 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -21,9 +21,9 @@ func main() { fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) allObjects := append(gen.SdkShowResultStructs, gen.AdditionalStructs...) - allStructsDetails := make([]gen.Struct, len(allObjects)) + allStructsDetails := make([]gencommons.Struct, len(allObjects)) for idx, s := range allObjects { - allStructsDetails[idx] = gen.ExtractStructDetails(s) + allStructsDetails[idx] = gencommons.ExtractStructDetails(s) } printAllStructsFields(allStructsDetails) @@ -32,7 +32,7 @@ func main() { saveAllGeneratedSchemas(allStructsDetails) } -func printAllStructsFields(allStructs []gen.Struct) { +func printAllStructsFields(allStructs []gencommons.Struct) { for _, s := range allStructs { fmt.Println("===========================") fmt.Printf("%s\n", s.Name) @@ -44,7 +44,7 @@ func printAllStructsFields(allStructs []gen.Struct) { } } -func printUniqueTypes(allStructs []gen.Struct) { +func printUniqueTypes(allStructs []gencommons.Struct) { uniqueTypes := make(map[string]bool) for _, s := range allStructs { for _, f := range s.Fields { @@ -61,7 +61,7 @@ func printUniqueTypes(allStructs []gen.Struct) { } } -func generateAllStructsToStdOut(allStructs []gen.Struct) { +func generateAllStructsToStdOut(allStructs []gencommons.Struct) { for _, s := range allStructs { fmt.Println("===========================") fmt.Printf("Generated for %s\n", s.Name) @@ -71,7 +71,7 @@ func generateAllStructsToStdOut(allStructs []gen.Struct) { } } -func saveAllGeneratedSchemas(allStructs []gen.Struct) { +func saveAllGeneratedSchemas(allStructs []gencommons.Struct) { for _, s := range allStructs { buffer := bytes.Buffer{} model := gen.ModelFromStructDetails(s) diff --git a/pkg/schemas/gen/model.go b/pkg/schemas/gen/model.go index 2e4c850fb1..fedbcbce26 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/gencommons" +) type ShowResultSchemaModel struct { Name string @@ -8,7 +12,7 @@ type ShowResultSchemaModel struct { SchemaFields []SchemaField } -func ModelFromStructDetails(sdkStruct Struct) ShowResultSchemaModel { +func ModelFromStructDetails(sdkStruct gencommons.Struct) 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 872efa9fc5..140b93180c 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -31,7 +31,7 @@ var ( // 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 gencommons.Field) SchemaField { isPointer := field.IsPointer() concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") name := gencommons.ToSnakeCase(field.Name) diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go index 1f2f23932a..9ba98a6e66 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/gencommons" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" ) @@ -17,120 +18,120 @@ func Test_MapToSchemaField(t *testing.T) { } testCases := []struct { - field Field + field gencommons.Field expected expectedValues }{ { - field: Field{"unexportedString", "string", "string"}, + field: gencommons.Field{"unexportedString", "string", "string"}, expected: expectedValues{"unexported_string", schema.TypeString, false, Identity}, }, { - field: Field{"unexportedInt", "int", "int"}, + field: gencommons.Field{"unexportedInt", "int", "int"}, expected: expectedValues{"unexported_int", schema.TypeInt, false, Identity}, }, { - field: Field{"unexportedBool", "bool", "bool"}, + field: gencommons.Field{"unexportedBool", "bool", "bool"}, expected: expectedValues{"unexported_bool", schema.TypeBool, false, Identity}, }, { - field: Field{"unexportedFloat64", "float64", "float64"}, + field: gencommons.Field{"unexportedFloat64", "float64", "float64"}, expected: expectedValues{"unexported_float64", schema.TypeFloat, false, Identity}, }, { - field: Field{"unexportedStringPtr", "*string", "*string"}, + field: gencommons.Field{"unexportedStringPtr", "*string", "*string"}, expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, Identity}, }, { - field: Field{"unexportedIntPtr", "*int", "*int"}, + field: gencommons.Field{"unexportedIntPtr", "*int", "*int"}, expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, Identity}, }, { - field: Field{"unexportedBoolPtr", "*bool", "*bool"}, + field: gencommons.Field{"unexportedBoolPtr", "*bool", "*bool"}, expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, Identity}, }, { - field: Field{"unexportedFloat64Ptr", "*float64", "*float64"}, + field: gencommons.Field{"unexportedFloat64Ptr", "*float64", "*float64"}, expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, Identity}, }, { - field: Field{"unexportedTime", "time.Time", "struct"}, + field: gencommons.Field{"unexportedTime", "time.Time", "struct"}, expected: expectedValues{"unexported_time", schema.TypeString, false, ToString}, }, { - field: Field{"unexportedTimePtr", "*time.Time", "*struct"}, + field: gencommons.Field{"unexportedTimePtr", "*time.Time", "*struct"}, expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, ToString}, }, { - field: Field{"unexportedStringEnum", "sdk.WarehouseType", "string"}, + field: gencommons.Field{"unexportedStringEnum", "sdk.WarehouseType", "string"}, expected: expectedValues{"unexported_string_enum", schema.TypeString, false, CastToString}, }, { - field: Field{"unexportedStringEnumPtr", "*sdk.WarehouseType", "*string"}, + field: gencommons.Field{"unexportedStringEnumPtr", "*sdk.WarehouseType", "*string"}, expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, CastToString}, }, { - field: Field{"unexportedIntEnum", "sdk.ResourceMonitorLevel", "int"}, + field: gencommons.Field{"unexportedIntEnum", "sdk.ResourceMonitorLevel", "int"}, expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, CastToInt}, }, { - field: Field{"unexportedIntEnumPtr", "*sdk.ResourceMonitorLevel", "*int"}, + field: gencommons.Field{"unexportedIntEnumPtr", "*sdk.ResourceMonitorLevel", "*int"}, expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, CastToInt}, }, { - field: Field{"unexportedAccountIdentifier", "sdk.AccountIdentifier", "struct"}, + field: gencommons.Field{"unexportedAccountIdentifier", "sdk.AccountIdentifier", "struct"}, expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, FullyQualifiedName}, }, { - field: Field{"unexportedExternalObjectIdentifier", "sdk.ExternalObjectIdentifier", "struct"}, + field: gencommons.Field{"unexportedExternalObjectIdentifier", "sdk.ExternalObjectIdentifier", "struct"}, expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, FullyQualifiedName}, }, { - field: Field{"unexportedAccountObjectIdentifier", "sdk.AccountObjectIdentifier", "struct"}, + field: gencommons.Field{"unexportedAccountObjectIdentifier", "sdk.AccountObjectIdentifier", "struct"}, expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, Name}, }, { - field: Field{"unexportedDatabaseObjectIdentifier", "sdk.DatabaseObjectIdentifier", "struct"}, + field: gencommons.Field{"unexportedDatabaseObjectIdentifier", "sdk.DatabaseObjectIdentifier", "struct"}, expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, FullyQualifiedName}, }, { - field: Field{"unexportedSchemaObjectIdentifier", "sdk.SchemaObjectIdentifier", "struct"}, + field: gencommons.Field{"unexportedSchemaObjectIdentifier", "sdk.SchemaObjectIdentifier", "struct"}, expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, FullyQualifiedName}, }, { - field: Field{"unexportedTableColumnIdentifier", "sdk.TableColumnIdentifier", "struct"}, + field: gencommons.Field{"unexportedTableColumnIdentifier", "sdk.TableColumnIdentifier", "struct"}, expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, FullyQualifiedName}, }, { - field: Field{"unexportedAccountIdentifierPtr", "*sdk.AccountIdentifier", "*struct"}, + field: gencommons.Field{"unexportedAccountIdentifierPtr", "*sdk.AccountIdentifier", "*struct"}, expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, }, { - field: Field{"unexportedExternalObjectIdentifierPtr", "*sdk.ExternalObjectIdentifier", "*struct"}, + field: gencommons.Field{"unexportedExternalObjectIdentifierPtr", "*sdk.ExternalObjectIdentifier", "*struct"}, expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, }, { - field: Field{"unexportedAccountObjectIdentifierPtr", "*sdk.AccountObjectIdentifier", "*struct"}, + field: gencommons.Field{"unexportedAccountObjectIdentifierPtr", "*sdk.AccountObjectIdentifier", "*struct"}, expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, Name}, }, { - field: Field{"unexportedDatabaseObjectIdentifierPtr", "*sdk.DatabaseObjectIdentifier", "*struct"}, + field: gencommons.Field{"unexportedDatabaseObjectIdentifierPtr", "*sdk.DatabaseObjectIdentifier", "*struct"}, expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, }, { - field: Field{"unexportedSchemaObjectIdentifierPtr", "*sdk.SchemaObjectIdentifier", "*struct"}, + field: gencommons.Field{"unexportedSchemaObjectIdentifierPtr", "*sdk.SchemaObjectIdentifier", "*struct"}, expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, }, { - field: Field{"unexportedTableColumnIdentifierPtr", "*sdk.TableColumnIdentifier", "*struct"}, + field: gencommons.Field{"unexportedTableColumnIdentifierPtr", "*sdk.TableColumnIdentifier", "*struct"}, expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, }, { - field: Field{"unexportedInterface", "sdk.ObjectIdentifier", "interface"}, + field: gencommons.Field{"unexportedInterface", "sdk.ObjectIdentifier", "interface"}, expected: expectedValues{"unexported_interface", schema.TypeString, false, FullyQualifiedName}, }, } - assertSchemaFieldMapped := func(schemaField SchemaField, originalField Field, expected expectedValues) { + assertSchemaFieldMapped := func(schemaField SchemaField, originalField gencommons.Field, expected expectedValues) { assert.Equal(t, expected.name, schemaField.Name) assert.Equal(t, expected.schemaType, schemaField.SchemaType) assert.Equal(t, originalField.Name, schemaField.OriginalName) From cbb2026951c12fb8c0f3338441decb87f129b179 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 14:42:10 +0200 Subject: [PATCH 13/62] Extract write to file helper func --- pkg/internal/gencommons/util.go | 21 +++++++++++++++++++++ pkg/schemas/gen/README.md | 1 - pkg/schemas/gen/main/main.go | 21 +-------------------- pkg/sdk/poc/generator/file_util.go | 24 ------------------------ pkg/sdk/poc/main.go | 3 ++- 5 files changed, 24 insertions(+), 46 deletions(-) delete mode 100644 pkg/sdk/poc/generator/file_util.go diff --git a/pkg/internal/gencommons/util.go b/pkg/internal/gencommons/util.go index 2143e62541..5fd13c0403 100644 --- a/pkg/internal/gencommons/util.go +++ b/pkg/internal/gencommons/util.go @@ -1,6 +1,11 @@ package gencommons import ( + "bytes" + "go/format" + "log" + "os" + "path/filepath" "regexp" "strings" ) @@ -37,3 +42,19 @@ 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. +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/schemas/gen/README.md b/pkg/schemas/gen/README.md index 79b1abbf99..0646af163d 100644 --- a/pkg/schemas/gen/README.md +++ b/pkg/schemas/gen/README.md @@ -86,7 +86,6 @@ Functional improvements: 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/main/main.go b/pkg/schemas/gen/main/main.go index 5faed749d9..b0329ea550 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -5,10 +5,7 @@ package main import ( "bytes" "fmt" - "go/format" - "log" "os" - "path/filepath" "slices" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" @@ -77,22 +74,6 @@ func saveAllGeneratedSchemas(allStructs []gencommons.Struct) { model := gen.ModelFromStructDetails(s) gen.Generate(model, &buffer) filename := gencommons.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) + gencommons.WriteCodeToFile(&buffer, filename) } } 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..87d362bcaf 100644 --- a/pkg/sdk/poc/main.go +++ b/pkg/sdk/poc/main.go @@ -10,6 +10,7 @@ import ( "os" "strings" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/example" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator" @@ -103,7 +104,7 @@ 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) + gencommons.WriteCodeToFile(&buffer, fileName) } func filenameFor(prefix string, part string) string { From 50fbd3a2a6f29d3013503f2afb71d50316941e4d Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 14:43:26 +0200 Subject: [PATCH 14/62] Rename to struct details --- pkg/internal/gencommons/struct_details_extractor.go | 6 +++--- pkg/schemas/gen/main/main.go | 10 +++++----- pkg/schemas/gen/model.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/internal/gencommons/struct_details_extractor.go b/pkg/internal/gencommons/struct_details_extractor.go index 1501fe4247..c6229cbe65 100644 --- a/pkg/internal/gencommons/struct_details_extractor.go +++ b/pkg/internal/gencommons/struct_details_extractor.go @@ -5,7 +5,7 @@ import ( "strings" ) -type Struct struct { +type StructDetails struct { Name string Fields []Field } @@ -24,7 +24,7 @@ func (f *Field) IsSlice() bool { return strings.HasPrefix(f.ConcreteType, "[]") } -func ExtractStructDetails(s any) Struct { +func ExtractStructDetails(s any) StructDetails { v := reflect.ValueOf(s) if v.Kind() == reflect.Pointer { v = v.Elem() @@ -54,5 +54,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/main/main.go b/pkg/schemas/gen/main/main.go index b0329ea550..c0052892c0 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -18,7 +18,7 @@ func main() { fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) allObjects := append(gen.SdkShowResultStructs, gen.AdditionalStructs...) - allStructsDetails := make([]gencommons.Struct, len(allObjects)) + allStructsDetails := make([]gencommons.StructDetails, len(allObjects)) for idx, s := range allObjects { allStructsDetails[idx] = gencommons.ExtractStructDetails(s) } @@ -29,7 +29,7 @@ func main() { saveAllGeneratedSchemas(allStructsDetails) } -func printAllStructsFields(allStructs []gencommons.Struct) { +func printAllStructsFields(allStructs []gencommons.StructDetails) { for _, s := range allStructs { fmt.Println("===========================") fmt.Printf("%s\n", s.Name) @@ -41,7 +41,7 @@ func printAllStructsFields(allStructs []gencommons.Struct) { } } -func printUniqueTypes(allStructs []gencommons.Struct) { +func printUniqueTypes(allStructs []gencommons.StructDetails) { uniqueTypes := make(map[string]bool) for _, s := range allStructs { for _, f := range s.Fields { @@ -58,7 +58,7 @@ func printUniqueTypes(allStructs []gencommons.Struct) { } } -func generateAllStructsToStdOut(allStructs []gencommons.Struct) { +func generateAllStructsToStdOut(allStructs []gencommons.StructDetails) { for _, s := range allStructs { fmt.Println("===========================") fmt.Printf("Generated for %s\n", s.Name) @@ -68,7 +68,7 @@ func generateAllStructsToStdOut(allStructs []gencommons.Struct) { } } -func saveAllGeneratedSchemas(allStructs []gencommons.Struct) { +func saveAllGeneratedSchemas(allStructs []gencommons.StructDetails) { for _, s := range allStructs { buffer := bytes.Buffer{} model := gen.ModelFromStructDetails(s) diff --git a/pkg/schemas/gen/model.go b/pkg/schemas/gen/model.go index fedbcbce26..b254619b71 100644 --- a/pkg/schemas/gen/model.go +++ b/pkg/schemas/gen/model.go @@ -12,7 +12,7 @@ type ShowResultSchemaModel struct { SchemaFields []SchemaField } -func ModelFromStructDetails(sdkStruct gencommons.Struct) ShowResultSchemaModel { +func ModelFromStructDetails(sdkStruct gencommons.StructDetails) ShowResultSchemaModel { name, _ := strings.CutPrefix(sdkStruct.Name, "sdk.") schemaFields := make([]SchemaField, len(sdkStruct.Fields)) for idx, field := range sdkStruct.Fields { From b4cf5efaeff19b88b548c2c5883979d20cf218e6 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 15:23:55 +0200 Subject: [PATCH 15/62] Extract a common func for template execution for all objects --- .../gencommons/struct_details_extractor.go | 4 ++ pkg/internal/gencommons/util.go | 57 ++++++++++++++++--- pkg/schemas/gen/generator.go | 23 -------- pkg/schemas/gen/main/main.go | 21 +++---- pkg/schemas/gen/templates.go | 2 + pkg/sdk/poc/main.go | 4 +- 6 files changed, 64 insertions(+), 47 deletions(-) delete mode 100644 pkg/schemas/gen/generator.go diff --git a/pkg/internal/gencommons/struct_details_extractor.go b/pkg/internal/gencommons/struct_details_extractor.go index c6229cbe65..fe858ac967 100644 --- a/pkg/internal/gencommons/struct_details_extractor.go +++ b/pkg/internal/gencommons/struct_details_extractor.go @@ -10,6 +10,10 @@ type StructDetails struct { Fields []Field } +func (s *StructDetails) ObjectName() string { + return s.Name +} + type Field struct { Name string ConcreteType string diff --git a/pkg/internal/gencommons/util.go b/pkg/internal/gencommons/util.go index 5fd13c0403..13be494eab 100644 --- a/pkg/internal/gencommons/util.go +++ b/pkg/internal/gencommons/util.go @@ -2,12 +2,15 @@ package gencommons import ( "bytes" + "errors" + "fmt" "go/format" - "log" + "io" "os" "path/filepath" "regexp" "strings" + "text/template" ) var ( @@ -43,18 +46,54 @@ func ColumnOutput(columnWidth int, columns ...string) string { return sb.String() } +// TODO: describe +type ObjectNameProvider interface { + ObjectName() string +} + +// TODO: describe +func GenerateAndSaveForAllObjects[T ObjectNameProvider, M any](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...) +} + +// TODO: describe +func ExecuteAllTemplates[M any](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...) +} + // WriteCodeToFile formats and saves content from the given buffer into file relative to the current working directory. -func WriteCodeToFile(buffer *bytes.Buffer, fileName string) { - wd, errWd := os.Getwd() - if errWd != nil { - log.Panicln(errWd) +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, errSrcFormat := format.Source(buffer.Bytes()) - if errSrcFormat != nil { - log.Panicln(errSrcFormat) + 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 { - log.Panicln(err) + return fmt.Errorf("writing code to file %s failed with err: %w", fileName, err) } + return nil } 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 c0052892c0..453bf3190c 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -3,7 +3,6 @@ package main import ( - "bytes" "fmt" "os" "slices" @@ -26,7 +25,12 @@ func main() { printAllStructsFields(allStructsDetails) printUniqueTypes(allStructsDetails) generateAllStructsToStdOut(allStructsDetails) - saveAllGeneratedSchemas(allStructsDetails) + gencommons.GenerateAndSaveForAllObjects( + allStructsDetails, + gen.ModelFromStructDetails, + func(_, model gen.ShowResultSchemaModel) { return gencommons.ToSnakeCase(model.Name) + "_gen.go" }, + gen.AllTemplates, + ) } func printAllStructsFields(allStructs []gencommons.StructDetails) { @@ -63,17 +67,6 @@ func generateAllStructsToStdOut(allStructs []gencommons.StructDetails) { fmt.Println("===========================") fmt.Printf("Generated for %s\n", s.Name) fmt.Println("===========================") - model := gen.ModelFromStructDetails(s) - gen.Generate(model, os.Stdout) - } -} - -func saveAllGeneratedSchemas(allStructs []gencommons.StructDetails) { - for _, s := range allStructs { - buffer := bytes.Buffer{} - model := gen.ModelFromStructDetails(s) - gen.Generate(model, &buffer) - filename := gencommons.ToSnakeCase(model.Name) + "_gen.go" - gencommons.WriteCodeToFile(&buffer, filename) + gencommons.ExecuteAllTemplates(gen.ModelFromStructDetails(s), os.Stdout, gen.AllTemplates) } } diff --git a/pkg/schemas/gen/templates.go b/pkg/schemas/gen/templates.go index 478e699c19..20855572a0 100644 --- a/pkg/schemas/gen/templates.go +++ b/pkg/schemas/gen/templates.go @@ -25,4 +25,6 @@ var ( "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) + + AllTemplates = []*template.Template{PreambleTemplate, SchemaTemplate, ToSchemaMapperTemplate} ) diff --git a/pkg/sdk/poc/main.go b/pkg/sdk/poc/main.go index 87d362bcaf..5f89d414f3 100644 --- a/pkg/sdk/poc/main.go +++ b/pkg/sdk/poc/main.go @@ -104,7 +104,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) - gencommons.WriteCodeToFile(&buffer, fileName) + if err := gencommons.WriteCodeToFile(&buffer, fileName); err != nil { + log.Panicln(err) + } } func filenameFor(prefix string, part string) string { From 2b8f7254cc71949a894baf9031c4dfbd0e894329 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 15:31:09 +0200 Subject: [PATCH 16/62] Move common func to generate and print --- pkg/internal/gencommons/util.go | 15 +++++++++++++++ pkg/schemas/gen/main/main.go | 12 ++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/internal/gencommons/util.go b/pkg/internal/gencommons/util.go index 13be494eab..ffc0b38321 100644 --- a/pkg/internal/gencommons/util.go +++ b/pkg/internal/gencommons/util.go @@ -70,6 +70,21 @@ func GenerateAndSaveForAllObjects[T ObjectNameProvider, M any](objects []T, mode return errors.Join(errs...) } +// TODO: describe +func GenerateAndPrintForAllObjects[T ObjectNameProvider, M any](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...) +} + // TODO: describe func ExecuteAllTemplates[M any](model M, writer io.Writer, templates ...*template.Template) error { var errs []error diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 453bf3190c..8a23a5bfc6 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -24,7 +24,8 @@ func main() { printAllStructsFields(allStructsDetails) printUniqueTypes(allStructsDetails) - generateAllStructsToStdOut(allStructsDetails) + // TODO: handle objects + gencommons.GenerateAndPrintForAllObjects(allStructsDetails, gen.ModelFromStructDetails, gen.AllTemplates) gencommons.GenerateAndSaveForAllObjects( allStructsDetails, gen.ModelFromStructDetails, @@ -61,12 +62,3 @@ func printUniqueTypes(allStructs []gencommons.StructDetails) { fmt.Println(k) } } - -func generateAllStructsToStdOut(allStructs []gencommons.StructDetails) { - for _, s := range allStructs { - fmt.Println("===========================") - fmt.Printf("Generated for %s\n", s.Name) - fmt.Println("===========================") - gencommons.ExecuteAllTemplates(gen.ModelFromStructDetails(s), os.Stdout, gen.AllTemplates) - } -} From 93fe57c5b4e5e8f13ae47433e628c6f46f5fb4ad Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 16:04:16 +0200 Subject: [PATCH 17/62] Prepare a generator skeleton (WIP) --- pkg/internal/gencommons/generator.go | 46 +++++++++++++++++++ .../gencommons/struct_details_extractor.go | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 pkg/internal/gencommons/generator.go diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go new file mode 100644 index 0000000000..52cee5fe44 --- /dev/null +++ b/pkg/internal/gencommons/generator.go @@ -0,0 +1,46 @@ +package gencommons + +import ( + "fmt" + "os" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" +) + +type Generator struct { +} + +func NewGenerator() *Generator { + return &Generator{} +} + +func (g *Generator) Run() error { + file := os.Getenv("GOFILE") + fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) + + // generating objects + allObjects := append(gen.SdkShowResultStructs, gen.AdditionalStructs...) + allStructsDetails := make([]StructDetails, len(allObjects)) + for idx, s := range allObjects { + allStructsDetails[idx] = ExtractStructDetails(s) + } + + // additional debug logs + // printAllStructsFields(allStructsDetails) + // printUniqueTypes(allStructsDetails) + + // printing objects to sdt out + _ = GenerateAndPrintForAllObjects(allStructsDetails, gen.ModelFromStructDetails, gen.AllTemplates...) + + // saving objects to file + _ = GenerateAndSaveForAllObjects( + allStructsDetails, + gen.ModelFromStructDetails, + func(_ StructDetails, model gen.ShowResultSchemaModel) string { + return ToSnakeCase(model.Name) + "_gen.go" + }, + gen.AllTemplates..., + ) + + return nil +} diff --git a/pkg/internal/gencommons/struct_details_extractor.go b/pkg/internal/gencommons/struct_details_extractor.go index fe858ac967..2a98210c4f 100644 --- a/pkg/internal/gencommons/struct_details_extractor.go +++ b/pkg/internal/gencommons/struct_details_extractor.go @@ -10,7 +10,7 @@ type StructDetails struct { Fields []Field } -func (s *StructDetails) ObjectName() string { +func (s StructDetails) ObjectName() string { return s.Name } From e2143e368f4eb46c5f735c15054ea44a8da0d7cc Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 16:37:40 +0200 Subject: [PATCH 18/62] Rewrite show output generator using the generator skeleton --- pkg/internal/gencommons/generator.go | 91 +++++++++++++++++++--------- pkg/internal/gencommons/util.go | 5 -- pkg/schemas/gen/main/main.go | 28 +++++---- pkg/schemas/gen/model.go | 4 ++ 4 files changed, 83 insertions(+), 45 deletions(-) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index 52cee5fe44..e57238a190 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -2,45 +2,82 @@ package gencommons import ( "fmt" + "log" "os" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" + "text/template" ) -type Generator struct { +// TODO: describe +type ObjectNameProvider interface { + ObjectName() string } -func NewGenerator() *Generator { - return &Generator{} +// TODO: describe +// TODO: use +// TODO: better func +type GenerationModel interface { + SomeFunc() } -func (g *Generator) Run() error { - file := os.Getenv("GOFILE") - fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) +// TODO: add type for objects provider? +// TODO: add erorrs to any of these functions? +type Generator[T ObjectNameProvider, M GenerationModel] struct { + objectsProvider func() []T + modelProvider func(T) M + // TODO: add filename to model? + filenameProvider func(T, M) string + templates []*template.Template + + additionalObjectDebugLogProviders []func([]T) +} - // generating objects - allObjects := append(gen.SdkShowResultStructs, gen.AdditionalStructs...) - allStructsDetails := make([]StructDetails, len(allObjects)) - for idx, s := range allObjects { - allStructsDetails[idx] = ExtractStructDetails(s) +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), } +} + +func (g *Generator[T, _]) WithAdditionalObjectsDebugLogs(objectLogsProvider func([]T)) *Generator[T, _] { + g.additionalObjectDebugLogProviders = append(g.additionalObjectDebugLogProviders, objectLogsProvider) + return g +} - // additional debug logs - // printAllStructsFields(allStructsDetails) - // printUniqueTypes(allStructsDetails) +func (g *Generator[_, _]) Run() error { + file := os.Getenv("GOFILE") + fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) - // printing objects to sdt out - _ = GenerateAndPrintForAllObjects(allStructsDetails, gen.ModelFromStructDetails, gen.AllTemplates...) + objects := g.objectsProvider() - // saving objects to file - _ = GenerateAndSaveForAllObjects( - allStructsDetails, - gen.ModelFromStructDetails, - func(_ StructDetails, model gen.ShowResultSchemaModel) string { - return ToSnakeCase(model.Name) + "_gen.go" - }, - gen.AllTemplates..., - ) + // TODO: print conditionally from invocation flag + for _, p := range g.additionalObjectDebugLogProviders { + p(objects) + } + + // TODO: do not generate twice? + // TODO: print conditionally from invocation flag + if err := GenerateAndPrintForAllObjects(objects, g.modelProvider, g.templates...); err != nil { + return err + } + if err := GenerateAndSaveForAllObjects( + objects, + g.modelProvider, + g.filenameProvider, + g.templates..., + ); err != nil { + return err + } return nil } + +func (g *Generator[_, _]) RunAndHandleOsReturn() { + err := g.Run() + if err != nil { + log.Fatal(err) + } +} diff --git a/pkg/internal/gencommons/util.go b/pkg/internal/gencommons/util.go index ffc0b38321..aae9859b03 100644 --- a/pkg/internal/gencommons/util.go +++ b/pkg/internal/gencommons/util.go @@ -46,11 +46,6 @@ func ColumnOutput(columnWidth int, columns ...string) string { return sb.String() } -// TODO: describe -type ObjectNameProvider interface { - ObjectName() string -} - // TODO: describe func GenerateAndSaveForAllObjects[T ObjectNameProvider, M any](objects []T, modelProvider func(T) M, filenameProvider func(T, M) string, templates ...*template.Template) error { var errs []error diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 8a23a5bfc6..09f6f8aca8 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "os" "slices" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" @@ -13,25 +12,28 @@ import ( ) func main() { - file := os.Getenv("GOFILE") - fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) + gencommons.NewGenerator( + getStructDetails, + gen.ModelFromStructDetails, + getFilename, + gen.AllTemplates, + ). + WithAdditionalObjectsDebugLogs(printAllStructsFields). + WithAdditionalObjectsDebugLogs(printUniqueTypes). + RunAndHandleOsReturn() +} +func getStructDetails() []gencommons.StructDetails { allObjects := append(gen.SdkShowResultStructs, gen.AdditionalStructs...) allStructsDetails := make([]gencommons.StructDetails, len(allObjects)) for idx, s := range allObjects { allStructsDetails[idx] = gencommons.ExtractStructDetails(s) } + return allStructsDetails +} - printAllStructsFields(allStructsDetails) - printUniqueTypes(allStructsDetails) - // TODO: handle objects - gencommons.GenerateAndPrintForAllObjects(allStructsDetails, gen.ModelFromStructDetails, gen.AllTemplates) - gencommons.GenerateAndSaveForAllObjects( - allStructsDetails, - gen.ModelFromStructDetails, - func(_, model gen.ShowResultSchemaModel) { return gencommons.ToSnakeCase(model.Name) + "_gen.go" }, - gen.AllTemplates, - ) +func getFilename(_ gencommons.StructDetails, model gen.ShowResultSchemaModel) string { + return gencommons.ToSnakeCase(model.Name) + "_gen.go" } func printAllStructsFields(allStructs []gencommons.StructDetails) { diff --git a/pkg/schemas/gen/model.go b/pkg/schemas/gen/model.go index b254619b71..813a158a84 100644 --- a/pkg/schemas/gen/model.go +++ b/pkg/schemas/gen/model.go @@ -12,6 +12,10 @@ type ShowResultSchemaModel struct { SchemaFields []SchemaField } +func (m ShowResultSchemaModel) SomeFunc() { + return +} + func ModelFromStructDetails(sdkStruct gencommons.StructDetails) ShowResultSchemaModel { name, _ := strings.CutPrefix(sdkStruct.Name, "sdk.") schemaFields := make([]SchemaField, len(sdkStruct.Fields)) From 0d3f120cb25197d9f1a9ec116e0093def2c6f733 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 16:55:11 +0200 Subject: [PATCH 19/62] Fix the gen --- pkg/internal/gencommons/generator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index e57238a190..d1ce61c6df 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -42,7 +42,7 @@ func NewGenerator[T ObjectNameProvider, M GenerationModel](objectsProvider func( } } -func (g *Generator[T, _]) WithAdditionalObjectsDebugLogs(objectLogsProvider func([]T)) *Generator[T, _] { +func (g *Generator[T, M]) WithAdditionalObjectsDebugLogs(objectLogsProvider func([]T)) *Generator[T, M] { g.additionalObjectDebugLogProviders = append(g.additionalObjectDebugLogProviders, objectLogsProvider) return g } From f5ae021b5e0a2cc145820e576eb4edc85eec6c10 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 17:02:37 +0200 Subject: [PATCH 20/62] Move helper funcs to the generator --- pkg/internal/gencommons/generator.go | 50 ++++++++++++++++++++++++++-- pkg/internal/gencommons/util.go | 48 -------------------------- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index d1ce61c6df..acd50dc2bb 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -1,7 +1,10 @@ package gencommons import ( + "bytes" + "errors" "fmt" + "io" "log" "os" "text/template" @@ -19,7 +22,6 @@ type GenerationModel interface { SomeFunc() } -// TODO: add type for objects provider? // TODO: add erorrs to any of these functions? type Generator[T ObjectNameProvider, M GenerationModel] struct { objectsProvider func() []T @@ -60,10 +62,10 @@ func (g *Generator[_, _]) Run() error { // TODO: do not generate twice? // TODO: print conditionally from invocation flag - if err := GenerateAndPrintForAllObjects(objects, g.modelProvider, g.templates...); err != nil { + if err := generateAndPrintForAllObjects(objects, g.modelProvider, g.templates...); err != nil { return err } - if err := GenerateAndSaveForAllObjects( + if err := generateAndSaveForAllObjects( objects, g.modelProvider, g.filenameProvider, @@ -81,3 +83,45 @@ func (g *Generator[_, _]) RunAndHandleOsReturn() { 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/gencommons/util.go b/pkg/internal/gencommons/util.go index aae9859b03..701604b281 100644 --- a/pkg/internal/gencommons/util.go +++ b/pkg/internal/gencommons/util.go @@ -2,15 +2,12 @@ package gencommons import ( "bytes" - "errors" "fmt" "go/format" - "io" "os" "path/filepath" "regexp" "strings" - "text/template" ) var ( @@ -46,51 +43,6 @@ func ColumnOutput(columnWidth int, columns ...string) string { return sb.String() } -// TODO: describe -func GenerateAndSaveForAllObjects[T ObjectNameProvider, M any](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...) -} - -// TODO: describe -func GenerateAndPrintForAllObjects[T ObjectNameProvider, M any](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...) -} - -// TODO: describe -func ExecuteAllTemplates[M any](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...) -} - // WriteCodeToFile formats and saves content from the given buffer into file relative to the current working directory. func WriteCodeToFile(buffer *bytes.Buffer, fileName string) error { wd, err := os.Getwd() From 97e861d2d280667deee51dc00f6dbd39a75b722b Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 17:11:35 +0200 Subject: [PATCH 21/62] Add flags to the generator skeleton --- pkg/internal/gencommons/generator.go | 37 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index acd50dc2bb..4baf3e3437 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -3,6 +3,7 @@ package gencommons import ( "bytes" "errors" + "flag" "fmt" "io" "log" @@ -53,25 +54,31 @@ func (g *Generator[_, _]) Run() error { file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) + var additionalLogs = flag.Bool("additional-logs", false, "print additional object debug logs") + var dryRun = flag.Bool("dry-run", false, "generate to std out instead of saving") + flag.Parse() + objects := g.objectsProvider() - // TODO: print conditionally from invocation flag - for _, p := range g.additionalObjectDebugLogProviders { - p(objects) + if *additionalLogs { + for _, p := range g.additionalObjectDebugLogProviders { + p(objects) + } } - // TODO: do not generate twice? - // TODO: print conditionally from invocation flag - if err := generateAndPrintForAllObjects(objects, g.modelProvider, g.templates...); err != nil { - return err - } - if err := generateAndSaveForAllObjects( - objects, - g.modelProvider, - g.filenameProvider, - g.templates..., - ); err != nil { - return err + 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 From f9fd2041c455aa149fc51277ce5f06d5f98ee982 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 17:21:33 +0200 Subject: [PATCH 22/62] Allow passing the arguments to the generator --- pkg/internal/gencommons/generator.go | 1 + pkg/schemas/generate.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index 4baf3e3437..8f58823d39 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -54,6 +54,7 @@ func (g *Generator[_, _]) Run() error { file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) + // TODO: describe running with build flags: make generate-show-output-schemas SF_TF_GENERATOR_ARGS=--dry-run var additionalLogs = flag.Bool("additional-logs", false, "print additional object debug logs") var dryRun = flag.Bool("dry-run", false, "generate to std out instead of saving") flag.Parse() 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 From 088b5c474622ad93b5ee810a8037aed90eb31a0e Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 17:37:14 +0200 Subject: [PATCH 23/62] Extract common template functions --- pkg/internal/gencommons/template_commons.go | 34 +++++++++++++++++++++ pkg/schemas/gen/schema_field_mapper.go | 4 +-- pkg/schemas/gen/templates.go | 18 +++++------ 3 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 pkg/internal/gencommons/template_commons.go diff --git a/pkg/internal/gencommons/template_commons.go b/pkg/internal/gencommons/template_commons.go new file mode 100644 index 0000000000..0d78b92106 --- /dev/null +++ b/pkg/internal/gencommons/template_commons.go @@ -0,0 +1,34 @@ +package gencommons + +import ( + "strings" + "text/template" +) + +type Mapper func(string) string + +func firstLetterLowercase(in string) string { + return strings.ToLower(in[:1]) + in[1:] +} + +func runMapper(mapper Mapper, in ...string) string { + return mapper(strings.Join(in, "")) +} + +var FirstLetterLowercaseEntry = map[string]any{ + "firstLetterLowercase": firstLetterLowercase, +} + +var RunMapperEntry = map[string]any{ + "runMapper": runMapper, +} + +func MergeFuncsMap(funcs ...map[string]any) template.FuncMap { + var allFuncs = make(map[string]any) + for _, f := range funcs { + for k, v := range f { + allFuncs[k] = v + } + } + return allFuncs +} diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go index 140b93180c..1e323cd7ba 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -8,14 +8,12 @@ import ( "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 gencommons.Mapper } var ( diff --git a/pkg/schemas/gen/templates.go b/pkg/schemas/gen/templates.go index 20855572a0..36a6946d15 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/gencommons" ) -// TODO [SNOW-1501905]: extract common funcs var ( //go:embed templates/preamble.tmpl preambleTemplateContent string @@ -15,16 +15,16 @@ 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").Funcs(gencommons.MergeFuncsMap( + gencommons.FirstLetterLowercaseEntry, + )).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(gencommons.MergeFuncsMap( + gencommons.FirstLetterLowercaseEntry, + gencommons.RunMapperEntry, + )).Parse(toSchemaMapperTemplateContent) AllTemplates = []*template.Template{PreambleTemplate, SchemaTemplate, ToSchemaMapperTemplate} ) From da74f1e5f56173c52a7b8b1d03087cbf8aeee9aa Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 17:40:12 +0200 Subject: [PATCH 24/62] Extract mapper commons --- pkg/internal/gencommons/mapper_commons.go | 14 ++++++ pkg/internal/gencommons/template_commons.go | 2 - pkg/schemas/gen/schema_field_mapper.go | 32 ++++-------- pkg/schemas/gen/schema_field_mapper_test.go | 56 ++++++++++----------- 4 files changed, 53 insertions(+), 51 deletions(-) create mode 100644 pkg/internal/gencommons/mapper_commons.go diff --git a/pkg/internal/gencommons/mapper_commons.go b/pkg/internal/gencommons/mapper_commons.go new file mode 100644 index 0000000000..a1a3d53d89 --- /dev/null +++ b/pkg/internal/gencommons/mapper_commons.go @@ -0,0 +1,14 @@ +package gencommons + +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/gencommons/template_commons.go b/pkg/internal/gencommons/template_commons.go index 0d78b92106..faf9a07311 100644 --- a/pkg/internal/gencommons/template_commons.go +++ b/pkg/internal/gencommons/template_commons.go @@ -5,8 +5,6 @@ import ( "text/template" ) -type Mapper func(string) string - func firstLetterLowercase(in string) string { return strings.ToLower(in[:1]) + in[1:] } diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go index 1e323cd7ba..88c815ba51 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -1,7 +1,6 @@ package gen import ( - "fmt" "strings" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" @@ -16,15 +15,6 @@ type SchemaField struct { Mapper gencommons.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 @@ -35,31 +25,31 @@ func MapToSchemaField(field gencommons.Field) SchemaField { name := gencommons.ToSnakeCase(field.Name) switch concreteTypeWithoutPtr { case "string": - return SchemaField{name, schema.TypeString, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeString, field.Name, isPointer, gencommons.Identity} case "int": - return SchemaField{name, schema.TypeInt, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeInt, field.Name, isPointer, gencommons.Identity} case "float64": - return SchemaField{name, schema.TypeFloat, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeFloat, field.Name, isPointer, gencommons.Identity} case "bool": - return SchemaField{name, schema.TypeBool, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeBool, field.Name, isPointer, gencommons.Identity} case "time.Time": - return SchemaField{name, schema.TypeString, field.Name, isPointer, ToString} + return SchemaField{name, schema.TypeString, field.Name, isPointer, gencommons.ToString} case "sdk.AccountObjectIdentifier": - return SchemaField{name, schema.TypeString, field.Name, isPointer, Name} + return SchemaField{name, schema.TypeString, field.Name, isPointer, gencommons.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, gencommons.FullyQualifiedName} case "sdk.ObjectIdentifier": - return SchemaField{name, schema.TypeString, field.Name, isPointer, FullyQualifiedName} + return SchemaField{name, schema.TypeString, field.Name, isPointer, gencommons.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, gencommons.CastToString} case isSdkDeclaredObject && underlyingTypeWithoutPtr == "int": - return SchemaField{name, schema.TypeInt, field.Name, isPointer, CastToInt} + return SchemaField{name, schema.TypeInt, field.Name, isPointer, gencommons.CastToInt} } - return SchemaField{name, schema.TypeInvalid, field.Name, isPointer, Identity} + return SchemaField{name, schema.TypeInvalid, field.Name, isPointer, gencommons.Identity} } diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go index 9ba98a6e66..3581005fec 100644 --- a/pkg/schemas/gen/schema_field_mapper_test.go +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -14,7 +14,7 @@ func Test_MapToSchemaField(t *testing.T) { name string schemaType schema.ValueType isPointer bool - mapper Mapper + mapper gencommons.Mapper } testCases := []struct { @@ -23,111 +23,111 @@ func Test_MapToSchemaField(t *testing.T) { }{ { field: gencommons.Field{"unexportedString", "string", "string"}, - expected: expectedValues{"unexported_string", schema.TypeString, false, Identity}, + expected: expectedValues{"unexported_string", schema.TypeString, false, gencommons.Identity}, }, { field: gencommons.Field{"unexportedInt", "int", "int"}, - expected: expectedValues{"unexported_int", schema.TypeInt, false, Identity}, + expected: expectedValues{"unexported_int", schema.TypeInt, false, gencommons.Identity}, }, { field: gencommons.Field{"unexportedBool", "bool", "bool"}, - expected: expectedValues{"unexported_bool", schema.TypeBool, false, Identity}, + expected: expectedValues{"unexported_bool", schema.TypeBool, false, gencommons.Identity}, }, { field: gencommons.Field{"unexportedFloat64", "float64", "float64"}, - expected: expectedValues{"unexported_float64", schema.TypeFloat, false, Identity}, + expected: expectedValues{"unexported_float64", schema.TypeFloat, false, gencommons.Identity}, }, { field: gencommons.Field{"unexportedStringPtr", "*string", "*string"}, - expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, Identity}, + expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, gencommons.Identity}, }, { field: gencommons.Field{"unexportedIntPtr", "*int", "*int"}, - expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, Identity}, + expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, gencommons.Identity}, }, { field: gencommons.Field{"unexportedBoolPtr", "*bool", "*bool"}, - expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, Identity}, + expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, gencommons.Identity}, }, { field: gencommons.Field{"unexportedFloat64Ptr", "*float64", "*float64"}, - expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, Identity}, + expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, gencommons.Identity}, }, { field: gencommons.Field{"unexportedTime", "time.Time", "struct"}, - expected: expectedValues{"unexported_time", schema.TypeString, false, ToString}, + expected: expectedValues{"unexported_time", schema.TypeString, false, gencommons.ToString}, }, { field: gencommons.Field{"unexportedTimePtr", "*time.Time", "*struct"}, - expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, ToString}, + expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, gencommons.ToString}, }, { field: gencommons.Field{"unexportedStringEnum", "sdk.WarehouseType", "string"}, - expected: expectedValues{"unexported_string_enum", schema.TypeString, false, CastToString}, + expected: expectedValues{"unexported_string_enum", schema.TypeString, false, gencommons.CastToString}, }, { field: gencommons.Field{"unexportedStringEnumPtr", "*sdk.WarehouseType", "*string"}, - expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, CastToString}, + expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, gencommons.CastToString}, }, { field: gencommons.Field{"unexportedIntEnum", "sdk.ResourceMonitorLevel", "int"}, - expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, CastToInt}, + expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, gencommons.CastToInt}, }, { field: gencommons.Field{"unexportedIntEnumPtr", "*sdk.ResourceMonitorLevel", "*int"}, - expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, CastToInt}, + expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, gencommons.CastToInt}, }, { field: gencommons.Field{"unexportedAccountIdentifier", "sdk.AccountIdentifier", "struct"}, - expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, FullyQualifiedName}, + expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedExternalObjectIdentifier", "sdk.ExternalObjectIdentifier", "struct"}, - expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, FullyQualifiedName}, + expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedAccountObjectIdentifier", "sdk.AccountObjectIdentifier", "struct"}, - expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, Name}, + expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, gencommons.Name}, }, { field: gencommons.Field{"unexportedDatabaseObjectIdentifier", "sdk.DatabaseObjectIdentifier", "struct"}, - expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, FullyQualifiedName}, + expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedSchemaObjectIdentifier", "sdk.SchemaObjectIdentifier", "struct"}, - expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, FullyQualifiedName}, + expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedTableColumnIdentifier", "sdk.TableColumnIdentifier", "struct"}, - expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, FullyQualifiedName}, + expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedAccountIdentifierPtr", "*sdk.AccountIdentifier", "*struct"}, - expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedExternalObjectIdentifierPtr", "*sdk.ExternalObjectIdentifier", "*struct"}, - expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedAccountObjectIdentifierPtr", "*sdk.AccountObjectIdentifier", "*struct"}, - expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, Name}, + expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, gencommons.Name}, }, { field: gencommons.Field{"unexportedDatabaseObjectIdentifierPtr", "*sdk.DatabaseObjectIdentifier", "*struct"}, - expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedSchemaObjectIdentifierPtr", "*sdk.SchemaObjectIdentifier", "*struct"}, - expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedTableColumnIdentifierPtr", "*sdk.TableColumnIdentifier", "*struct"}, - expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { field: gencommons.Field{"unexportedInterface", "sdk.ObjectIdentifier", "interface"}, - expected: expectedValues{"unexported_interface", schema.TypeString, false, FullyQualifiedName}, + expected: expectedValues{"unexported_interface", schema.TypeString, false, gencommons.FullyQualifiedName}, }, } From 423fd3378b0200bb60f83407a7c5b4ce15e04a28 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 17:53:02 +0200 Subject: [PATCH 25/62] Take template helper func by name --- pkg/internal/gencommons/template_commons.go | 26 +++++++++---------- pkg/schemas/gen/templates.go | 10 +++---- pkg/schemas/gen/templates/schema.tmpl | 12 ++++----- .../gen/templates/to_schema_mapper.tmpl | 24 ++++++++--------- 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/pkg/internal/gencommons/template_commons.go b/pkg/internal/gencommons/template_commons.go index faf9a07311..b9e5453db3 100644 --- a/pkg/internal/gencommons/template_commons.go +++ b/pkg/internal/gencommons/template_commons.go @@ -1,32 +1,30 @@ package gencommons import ( + "reflect" + "runtime" "strings" "text/template" ) -func firstLetterLowercase(in string) string { +func FirstLetterLowercase(in string) string { return strings.ToLower(in[:1]) + in[1:] } -func runMapper(mapper Mapper, in ...string) string { +func RunMapper(mapper Mapper, in ...string) string { return mapper(strings.Join(in, "")) } -var FirstLetterLowercaseEntry = map[string]any{ - "firstLetterLowercase": firstLetterLowercase, -} - -var RunMapperEntry = map[string]any{ - "runMapper": runMapper, -} - -func MergeFuncsMap(funcs ...map[string]any) template.FuncMap { +func BuildTemplateFuncMap(funcs ...any) template.FuncMap { var allFuncs = make(map[string]any) for _, f := range funcs { - for k, v := range f { - allFuncs[k] = v - } + 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/templates.go b/pkg/schemas/gen/templates.go index 36a6946d15..e9a8105fbe 100644 --- a/pkg/schemas/gen/templates.go +++ b/pkg/schemas/gen/templates.go @@ -15,15 +15,13 @@ var ( //go:embed templates/schema.tmpl schemaTemplateContent string - SchemaTemplate, _ = template.New("schemaTemplate").Funcs(gencommons.MergeFuncsMap( - gencommons.FirstLetterLowercaseEntry, - )).Parse(schemaTemplateContent) + SchemaTemplate, _ = template.New("schemaTemplate").Parse(schemaTemplateContent) //go:embed templates/to_schema_mapper.tmpl toSchemaMapperTemplateContent string - ToSchemaMapperTemplate, _ = template.New("toSchemaMapperTemplate").Funcs(gencommons.MergeFuncsMap( - gencommons.FirstLetterLowercaseEntry, - gencommons.RunMapperEntry, + ToSchemaMapperTemplate, _ = template.New("toSchemaMapperTemplate").Funcs(gencommons.BuildTemplateFuncMap( + gencommons.FirstLetterLowercase, + gencommons.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 From a3702a6f1c82c8d9dc8c5306fe4a7d5ce146733f Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 17:55:22 +0200 Subject: [PATCH 26/62] Remove already done TODOs --- pkg/schemas/gen/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/schemas/gen/README.md b/pkg/schemas/gen/README.md index 0646af163d..a43808de10 100644 --- a/pkg/schemas/gen/README.md +++ b/pkg/schemas/gen/README.md @@ -80,12 +80,10 @@ 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)) - 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 - 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`) From a3e1004e847b8a78eeae42ea562e4faeb4893389 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 19:06:54 +0200 Subject: [PATCH 27/62] Allow using multiple flags (hacky) --- pkg/internal/gencommons/generator.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index 8f58823d39..a536188ddd 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -8,6 +8,7 @@ import ( "io" "log" "os" + "strings" "text/template" ) @@ -51,10 +52,12 @@ func (g *Generator[T, M]) WithAdditionalObjectsDebugLogs(objectLogsProvider func } func (g *Generator[_, _]) Run() error { + preprocessArgs() + file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) - // TODO: describe running with build flags: make generate-show-output-schemas SF_TF_GENERATOR_ARGS=--dry-run + // TODO: describe running with build flags: make generate-show-output-schemas SF_TF_GENERATOR_ARGS='--dry-run additional-logs' var additionalLogs = flag.Bool("additional-logs", false, "print additional object debug logs") var dryRun = flag.Bool("dry-run", false, "generate to std out instead of saving") flag.Parse() @@ -85,6 +88,17 @@ func (g *Generator[_, _]) Run() error { return nil } +// TODO: temporary hacky solution to allow easy passing multiple args from the make command +func preprocessArgs() { + rest := os.Args[1:] + newArgs := make([]string, 0) + newArgs = append(newArgs, 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 { From 6c10a18a2e525eceef6f4eb724a9fa09841f26f1 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 19:15:46 +0200 Subject: [PATCH 28/62] Add possibility to filter objects --- pkg/internal/gencommons/generator.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index a536188ddd..db6b524d34 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -33,6 +33,7 @@ type Generator[T ObjectNameProvider, M GenerationModel] struct { 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] { @@ -43,6 +44,7 @@ func NewGenerator[T ObjectNameProvider, M GenerationModel](objectsProvider func( templates: templates, additionalObjectDebugLogProviders: make([]func([]T), 0), + objectFilters: make([]func(T) bool, 0), } } @@ -51,7 +53,7 @@ func (g *Generator[T, M]) WithAdditionalObjectsDebugLogs(objectLogsProvider func return g } -func (g *Generator[_, _]) Run() error { +func (g *Generator[T, _]) Run() error { preprocessArgs() file := os.Getenv("GOFILE") @@ -64,6 +66,20 @@ func (g *Generator[_, _]) Run() error { 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) From 43fd0949324e7a03555ee9e6c21c6688e2bdec6a Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Fri, 19 Jul 2024 19:26:13 +0200 Subject: [PATCH 29/62] Add example filter --- pkg/internal/gencommons/generator.go | 5 +++++ pkg/schemas/gen/README.md | 1 - pkg/schemas/gen/main/main.go | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index db6b524d34..e5b623ad4d 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -53,6 +53,11 @@ func (g *Generator[T, M]) WithAdditionalObjectsDebugLogs(objectLogsProvider func 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() diff --git a/pkg/schemas/gen/README.md b/pkg/schemas/gen/README.md index a43808de10..591dca2ecd 100644 --- a/pkg/schemas/gen/README.md +++ b/pkg/schemas/gen/README.md @@ -79,7 +79,6 @@ If you change the show output struct in the SDK: 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)) - parametrize the generation, e.g.: - - generate only given object(s) - now all are always 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` diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 09f6f8aca8..58ccc9f106 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -4,7 +4,9 @@ package main import ( "fmt" + "os" "slices" + "strings" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" @@ -20,6 +22,7 @@ func main() { ). WithAdditionalObjectsDebugLogs(printAllStructsFields). WithAdditionalObjectsDebugLogs(printUniqueTypes). + WithObjectFilter(filterByNameFromEnv). RunAndHandleOsReturn() } @@ -64,3 +67,13 @@ func printUniqueTypes(allStructs []gencommons.StructDetails) { fmt.Println(k) } } + +// TODO: describe filtering: make generate-show-output-schemas SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES="sdk.Warehouse,sdk.User" +func filterByNameFromEnv(o gencommons.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()) +} From 0bae099b97b35723b509882a671a54294654d6d6 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 15:55:29 +0200 Subject: [PATCH 30/62] Prepare snowflake object assertions generator (WIP) --- Makefile | 6 +++ pkg/acceptance/bettertestspoc/gen/model.go | 47 ++++++++++++++++++ .../gen/snowflake_object_assertions/main.go | 49 +++++++++++++++++++ .../bettertestspoc/gen/templates.go | 32 ++++++++++++ .../gen/templates/preamble.tmpl | 12 +++++ .../snowflake_object_assertions.tmpl | 23 +++++++++ ...nowflake_object_assertions_definition.tmpl | 21 ++++++++ .../generate_snowflake_object_assertions.go | 3 ++ pkg/internal/gencommons/sdk_object_details.go | 9 ++++ pkg/internal/gencommons/template_commons.go | 13 +++++ 10 files changed, 215 insertions(+) create mode 100644 pkg/acceptance/bettertestspoc/gen/model.go create mode 100644 pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go create mode 100644 pkg/acceptance/bettertestspoc/gen/templates.go create mode 100644 pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl create mode 100644 pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl create mode 100644 pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl create mode 100644 pkg/acceptance/bettertestspoc/testgen/generate_snowflake_object_assertions.go create mode 100644 pkg/internal/gencommons/sdk_object_details.go diff --git a/Makefile b/Makefile index 1593810d0b..1eca6e78c9 100644 --- a/Makefile +++ b/Makefile @@ -123,4 +123,10 @@ 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/testgen/generate_snowflake_object_assertions.go + +clean-snowflake-object-assertions: ## Clean snowflake object assertions + rm -f ./pkg/acceptance/bettertestspoc/testgen/*_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/gen/model.go b/pkg/acceptance/bettertestspoc/gen/model.go new file mode 100644 index 0000000000..1e6a28d930 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/gen/model.go @@ -0,0 +1,47 @@ +package gen + +import ( + "strings" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" +) + +type SnowflakeObjectAssertionsModel struct { + Name string + SdkType string + IdType string + Fields []SnowflakeObjectFieldAssertion +} + +func (m SnowflakeObjectAssertionsModel) SomeFunc() { + return +} + +type SnowflakeObjectFieldAssertion struct { + Name string + ConcreteType string + IsOriginalTypePointer bool +} + +func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeObjectAssertionsModel { + name, _ := strings.CutPrefix(sdkObject.Name, "sdk.") + fields := make([]SnowflakeObjectFieldAssertion, len(sdkObject.Fields)) + for idx, field := range sdkObject.Fields { + fields[idx] = MapToSnowflakeObjectFieldAssertion(field) + } + + return SnowflakeObjectAssertionsModel{ + Name: name, + SdkType: sdkObject.Name, + IdType: sdkObject.IdType, + Fields: fields, + } +} + +func MapToSnowflakeObjectFieldAssertion(field gencommons.Field) SnowflakeObjectFieldAssertion { + return SnowflakeObjectFieldAssertion{ + Name: field.Name, + ConcreteType: field.ConcreteType, + IsOriginalTypePointer: field.IsPointer(), + } +} diff --git a/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go b/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go new file mode 100644 index 0000000000..16f98dcaa5 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go @@ -0,0 +1,49 @@ +//go:build exclude + +package main + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +func main() { + gencommons.NewGenerator( + getSdkObjectDetails, + gen.ModelFromSdkObjectDetails, + getFilename, + gen.AllTemplates, + ). + RunAndHandleOsReturn() +} + +type SdkObjectDef struct { + idType string + objectType sdk.ObjectType + objectStruct any +} + +func getSdkObjectDetails() []gencommons.SdkObjectDetails { + allObjectDefs := []SdkObjectDef{ + { + idType: "sdk.AccountObjectIdentifier", + objectType: sdk.ObjectTypeWarehouse, + objectStruct: sdk.Warehouse{}, + }, + } + allSdkObjectsDetails := make([]gencommons.SdkObjectDetails, len(allObjectDefs)) + for idx, d := range allObjectDefs { + structDetails := gencommons.ExtractStructDetails(d.objectStruct) + allSdkObjectsDetails[idx] = gencommons.SdkObjectDetails{ + IdType: d.idType, + ObjectType: d.objectType, + StructDetails: structDetails, + } + } + return allSdkObjectsDetails +} + +func getFilename(_ gencommons.SdkObjectDetails, model gen.SnowflakeObjectAssertionsModel) string { + return gencommons.ToSnakeCase(model.Name) + "_snowflake" + "_gen.go" +} diff --git a/pkg/acceptance/bettertestspoc/gen/templates.go b/pkg/acceptance/bettertestspoc/gen/templates.go new file mode 100644 index 0000000000..d9863ac61f --- /dev/null +++ b/pkg/acceptance/bettertestspoc/gen/templates.go @@ -0,0 +1,32 @@ +package gen + +import ( + "text/template" + + _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" +) + +var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + + //go:embed templates/snowflake_object_assertions_definition.tmpl + snowflakeObjectAssertionsDefinitionTemplateContent string + SnowflakeObjectAssertionsDefinitionTemplate, _ = template.New("snowflakeObjectAssertionsDefinitionTemplate").Funcs(gencommons.BuildTemplateFuncMap( + gencommons.FirstLetterLowercase, + )).Parse(snowflakeObjectAssertionsDefinitionTemplateContent) + + //go:embed templates/snowflake_object_assertions.tmpl + snowflakeObjectAssertionsTemplateContent string + SnowflakeObjectAssertionsTemplate, _ = template.New("snowflakeObjectAssertionsTemplate").Funcs(gencommons.BuildTemplateFuncMap( + gencommons.FirstLetterLowercase, + gencommons.FirstLetter, + gencommons.TypeWithoutPointer, + gencommons.CamelToWords, + )).Parse(snowflakeObjectAssertionsTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, SnowflakeObjectAssertionsTemplate} +) diff --git a/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl new file mode 100644 index 0000000000..450953e9b2 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl @@ -0,0 +1,12 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package assert + +import ( +"fmt" +"testing" + +acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + +"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) diff --git a/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl b/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl new file mode 100644 index 0000000000..41d0cc9aac --- /dev/null +++ b/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl @@ -0,0 +1,23 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/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 }}.assertions = append({{ $assertVar }}.assertions, 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 }}o.{{ .Name }} != expected { + return fmt.Errorf("expected {{ CamelToWords .Name }}: %v; got: %v", expected, {{ if .IsOriginalTypePointer }}*{{ end }}o.{{ .Name }}) + } + return nil + }) + return {{ $assertVar }} + } +{{ end }} diff --git a/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl b/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl new file mode 100644 index 0000000000..3a00bd1339 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl @@ -0,0 +1,21 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen.SnowflakeObjectAssertionsModel*/ -}} + +{{ $assertName := .Name | printf "%sAssert" }} +{{ $nameLowerCase := FirstLetterLowercase .Name }} +type {{ $assertName }} struct { +*SnowflakeObjectAssert[{{ .SdkType }}, {{ .IdType }}] +} + +func {{ .Name }}(t *testing.T, id {{ .IdType }}) *{{ $assertName }} { +t.Helper() +return &{{ $assertName }}{ +NewSnowflakeObjectAssertWithProvider(sdk.ObjectType{{ .Name }}, id, acc.TestClient().{{ .Name }}.Show), +} +} + +func {{ .Name }}FromObject(t *testing.T, {{ $nameLowerCase }} *{{ .SdkType }}) *{{ $assertName }} { +t.Helper() +return &{{ $assertName }}{ +NewSnowflakeObjectAssertWithObject(sdk.ObjectType{{ .Name }}, {{ $nameLowerCase }}.ID(), {{ $nameLowerCase }}), +} +} diff --git a/pkg/acceptance/bettertestspoc/testgen/generate_snowflake_object_assertions.go b/pkg/acceptance/bettertestspoc/testgen/generate_snowflake_object_assertions.go new file mode 100644 index 0000000000..a0e8b187f1 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/testgen/generate_snowflake_object_assertions.go @@ -0,0 +1,3 @@ +package testgen + +//go:generate go run ../gen/snowflake_object_assertions/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/internal/gencommons/sdk_object_details.go b/pkg/internal/gencommons/sdk_object_details.go new file mode 100644 index 0000000000..1d43745004 --- /dev/null +++ b/pkg/internal/gencommons/sdk_object_details.go @@ -0,0 +1,9 @@ +package gencommons + +import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + +type SdkObjectDetails struct { + IdType string + ObjectType sdk.ObjectType + StructDetails +} diff --git a/pkg/internal/gencommons/template_commons.go b/pkg/internal/gencommons/template_commons.go index b9e5453db3..8f8fde25ab 100644 --- a/pkg/internal/gencommons/template_commons.go +++ b/pkg/internal/gencommons/template_commons.go @@ -11,10 +11,23 @@ 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 BuildTemplateFuncMap(funcs ...any) template.FuncMap { var allFuncs = make(map[string]any) for _, f := range funcs { From f8cb936e69ed62ee93494b52b51b06a13d1fe97a Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 20:54:09 +0200 Subject: [PATCH 31/62] Add add assertion func --- pkg/acceptance/bettertestspoc/assert/snowflake_assertions.go | 4 ++++ pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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/warehouse_snowflake.go b/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go index c6be645f25..0fc601b563 100644 --- a/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go @@ -160,7 +160,7 @@ func (w *WarehouseAssert) HasResourceMonitor(expected sdk.AccountObjectIdentifie } func (w *WarehouseAssert) HasScalingPolicy(expected sdk.ScalingPolicy) *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 o.ScalingPolicy != expected { return fmt.Errorf("expected type: %v; got: %v", expected, string(o.ScalingPolicy)) From 4e50d808ee51c1b08dfbd700ab0877121e850c2e Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 21:11:24 +0200 Subject: [PATCH 32/62] Add assertion through method --- pkg/acceptance/bettertestspoc/gen/model.go | 11 +++++++++++ .../bettertestspoc/gen/templates/preamble.tmpl | 5 ++++- .../gen/templates/snowflake_object_assertions.tmpl | 2 +- .../snowflake_object_assertions_definition.tmpl | 6 +++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/gen/model.go b/pkg/acceptance/bettertestspoc/gen/model.go index 1e6a28d930..9a6f44be5c 100644 --- a/pkg/acceptance/bettertestspoc/gen/model.go +++ b/pkg/acceptance/bettertestspoc/gen/model.go @@ -1,16 +1,23 @@ package gen import ( + "os" "strings" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" ) +// TODO: extract to commons? +type PreambleModel struct { + PackageName string +} + type SnowflakeObjectAssertionsModel struct { Name string SdkType string IdType string Fields []SnowflakeObjectFieldAssertion + PreambleModel } func (m SnowflakeObjectAssertionsModel) SomeFunc() { @@ -30,11 +37,15 @@ func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeO fields[idx] = MapToSnowflakeObjectFieldAssertion(field) } + packageWithGenerateDirective := os.Getenv("GOPACKAGE") return SnowflakeObjectAssertionsModel{ Name: name, SdkType: sdkObject.Name, IdType: sdkObject.IdType, Fields: fields, + PreambleModel: PreambleModel{ + PackageName: packageWithGenerateDirective, + }, } } diff --git a/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl index 450953e9b2..7282690e0c 100644 --- a/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl @@ -1,6 +1,8 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen.PreambleModel*/ -}} + // Code generated by sdk-to-schema generator; DO NOT EDIT. -package assert +package {{ .PackageName }} import ( "fmt" @@ -8,5 +10,6 @@ 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" ) diff --git a/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl b/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl index 41d0cc9aac..b5e7fb25e2 100644 --- a/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl +++ b/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl @@ -6,7 +6,7 @@ {{ $assertVar := FirstLetter $nameLowerCase }} {{- range .Fields }} func ({{ $assertVar }} *{{ $assertName }}) Has{{ .Name }}(expected {{ TypeWithoutPointer .ConcreteType }}) *{{ $assertName }} { - {{ $assertVar }}.assertions = append({{ $assertVar }}.assertions, func(t *testing.T, o *{{ $sdkType }}) error { + {{ $assertVar }}.AddAssertion(func(t *testing.T, o *{{ $sdkType }}) error { t.Helper() {{ if .IsOriginalTypePointer -}} if o.{{ .Name }} == nil { diff --git a/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl b/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl index 3a00bd1339..afc9299ea5 100644 --- a/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl +++ b/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl @@ -3,19 +3,19 @@ {{ $assertName := .Name | printf "%sAssert" }} {{ $nameLowerCase := FirstLetterLowercase .Name }} type {{ $assertName }} struct { -*SnowflakeObjectAssert[{{ .SdkType }}, {{ .IdType }}] +*assert.SnowflakeObjectAssert[{{ .SdkType }}, {{ .IdType }}] } func {{ .Name }}(t *testing.T, id {{ .IdType }}) *{{ $assertName }} { t.Helper() return &{{ $assertName }}{ -NewSnowflakeObjectAssertWithProvider(sdk.ObjectType{{ .Name }}, id, acc.TestClient().{{ .Name }}.Show), +assert.NewSnowflakeObjectAssertWithProvider(sdk.ObjectType{{ .Name }}, id, acc.TestClient().{{ .Name }}.Show), } } func {{ .Name }}FromObject(t *testing.T, {{ $nameLowerCase }} *{{ .SdkType }}) *{{ $assertName }} { t.Helper() return &{{ $assertName }}{ -NewSnowflakeObjectAssertWithObject(sdk.ObjectType{{ .Name }}, {{ $nameLowerCase }}.ID(), {{ $nameLowerCase }}), +assert.NewSnowflakeObjectAssertWithObject(sdk.ObjectType{{ .Name }}, {{ $nameLowerCase }}.ID(), {{ $nameLowerCase }}), } } From a3a05256b3a4eba050bf705b050eeb28531f1259 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 21:24:49 +0200 Subject: [PATCH 33/62] Add additional standard imports (quick and dirty) --- pkg/acceptance/bettertestspoc/gen/model.go | 18 ++++++++++++++++-- .../bettertestspoc/gen/templates/preamble.tmpl | 3 +++ .../gencommons/struct_details_extractor.go | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/gen/model.go b/pkg/acceptance/bettertestspoc/gen/model.go index 9a6f44be5c..ca8618e9d2 100644 --- a/pkg/acceptance/bettertestspoc/gen/model.go +++ b/pkg/acceptance/bettertestspoc/gen/model.go @@ -2,6 +2,7 @@ package gen import ( "os" + "slices" "strings" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" @@ -9,7 +10,8 @@ import ( // TODO: extract to commons? type PreambleModel struct { - PackageName string + PackageName string + AdditionalStandardImports []string } type SnowflakeObjectAssertionsModel struct { @@ -33,8 +35,19 @@ type SnowflakeObjectFieldAssertion struct { func ModelFromSdkObjectDetails(sdkObject gencommons.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") @@ -44,7 +57,8 @@ func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeO IdType: sdkObject.IdType, Fields: fields, PreambleModel: PreambleModel{ - PackageName: packageWithGenerateDirective, + PackageName: packageWithGenerateDirective, + AdditionalStandardImports: additionalImports, }, } } diff --git a/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl index 7282690e0c..e1d5e2e056 100644 --- a/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl @@ -7,6 +7,9 @@ package {{ .PackageName }} import ( "fmt" "testing" +{{- range .AdditionalStandardImports }} +"{{- . }}" +{{- end }} acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" diff --git a/pkg/internal/gencommons/struct_details_extractor.go b/pkg/internal/gencommons/struct_details_extractor.go index 2a98210c4f..50ac34d6cc 100644 --- a/pkg/internal/gencommons/struct_details_extractor.go +++ b/pkg/internal/gencommons/struct_details_extractor.go @@ -28,6 +28,11 @@ func (f *Field) IsSlice() bool { return strings.HasPrefix(f.ConcreteType, "[]") } +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 { From 67b13cc3e55327168127bb209e378c838d340e6a Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 21:32:16 +0200 Subject: [PATCH 34/62] Extract list of objects --- .../gen/snowflake_object_assertions/main.go | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go b/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go index 16f98dcaa5..729f961318 100644 --- a/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go +++ b/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go @@ -25,15 +25,8 @@ type SdkObjectDef struct { } func getSdkObjectDetails() []gencommons.SdkObjectDetails { - allObjectDefs := []SdkObjectDef{ - { - idType: "sdk.AccountObjectIdentifier", - objectType: sdk.ObjectTypeWarehouse, - objectStruct: sdk.Warehouse{}, - }, - } - allSdkObjectsDetails := make([]gencommons.SdkObjectDetails, len(allObjectDefs)) - for idx, d := range allObjectDefs { + allSdkObjectsDetails := make([]gencommons.SdkObjectDetails, len(allStructs)) + for idx, d := range allStructs { structDetails := gencommons.ExtractStructDetails(d.objectStruct) allSdkObjectsDetails[idx] = gencommons.SdkObjectDetails{ IdType: d.idType, @@ -47,3 +40,16 @@ func getSdkObjectDetails() []gencommons.SdkObjectDetails { func getFilename(_ gencommons.SdkObjectDetails, model gen.SnowflakeObjectAssertionsModel) string { return gencommons.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{}, + }, +} From fc9d1ef167a247c61a228ec8f75639749b6d24b1 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 21:37:15 +0200 Subject: [PATCH 35/62] Move generate snowflake object to the destination package --- Makefile | 4 ++-- pkg/acceptance/bettertestspoc/assert/objectassert/generate.go | 3 +++ .../testgen/generate_snowflake_object_assertions.go | 3 --- 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectassert/generate.go delete mode 100644 pkg/acceptance/bettertestspoc/testgen/generate_snowflake_object_assertions.go diff --git a/Makefile b/Makefile index 1eca6e78c9..a06473f60a 100644 --- a/Makefile +++ b/Makefile @@ -124,9 +124,9 @@ 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/testgen/generate_snowflake_object_assertions.go + go generate ./pkg/acceptance/bettertestspoc/assert/objectassert/generate.go clean-snowflake-object-assertions: ## Clean snowflake object assertions - rm -f ./pkg/acceptance/bettertestspoc/testgen/*_gen.go + rm -f ./pkg/acceptance/bettertestspoc/assert/objectassert/*_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/assert/objectassert/generate.go b/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go new file mode 100644 index 0000000000..e0ddabfaa9 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go @@ -0,0 +1,3 @@ +package testgen + +//go:generate go run ../../gen/snowflake_object_assertions/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/acceptance/bettertestspoc/testgen/generate_snowflake_object_assertions.go b/pkg/acceptance/bettertestspoc/testgen/generate_snowflake_object_assertions.go deleted file mode 100644 index a0e8b187f1..0000000000 --- a/pkg/acceptance/bettertestspoc/testgen/generate_snowflake_object_assertions.go +++ /dev/null @@ -1,3 +0,0 @@ -package testgen - -//go:generate go run ../gen/snowflake_object_assertions/main.go $SF_TF_GENERATOR_ARGS From 0c7ce2766f47d7ceb922b29e2c51bdf76d8f67dc Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 22:00:42 +0200 Subject: [PATCH 36/62] Reorganize --- .../objectassert/gen/main}/main.go | 2 +- .../bettertestspoc/{ => assert/objectassert}/gen/model.go | 0 .../bettertestspoc/{ => assert/objectassert}/gen/templates.go | 0 .../{ => assert/objectassert}/gen/templates/preamble.tmpl | 0 .../gen/templates/snowflake_object_assertions.tmpl | 0 .../gen/templates/snowflake_object_assertions_definition.tmpl | 0 pkg/acceptance/bettertestspoc/assert/objectassert/generate.go | 2 +- 7 files changed, 2 insertions(+), 2 deletions(-) rename pkg/acceptance/bettertestspoc/{gen/snowflake_object_assertions => assert/objectassert/gen/main}/main.go (96%) rename pkg/acceptance/bettertestspoc/{ => assert/objectassert}/gen/model.go (100%) rename pkg/acceptance/bettertestspoc/{ => assert/objectassert}/gen/templates.go (100%) rename pkg/acceptance/bettertestspoc/{ => assert/objectassert}/gen/templates/preamble.tmpl (100%) rename pkg/acceptance/bettertestspoc/{ => assert/objectassert}/gen/templates/snowflake_object_assertions.tmpl (100%) rename pkg/acceptance/bettertestspoc/{ => assert/objectassert}/gen/templates/snowflake_object_assertions_definition.tmpl (100%) diff --git a/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go similarity index 96% rename from pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go rename to pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go index 729f961318..01c031cde2 100644 --- a/pkg/acceptance/bettertestspoc/gen/snowflake_object_assertions/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go @@ -3,7 +3,7 @@ package main import ( - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" ) diff --git a/pkg/acceptance/bettertestspoc/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go similarity index 100% rename from pkg/acceptance/bettertestspoc/gen/model.go rename to pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go diff --git a/pkg/acceptance/bettertestspoc/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go similarity index 100% rename from pkg/acceptance/bettertestspoc/gen/templates.go rename to pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go diff --git a/pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl similarity index 100% rename from pkg/acceptance/bettertestspoc/gen/templates/preamble.tmpl rename to pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl diff --git a/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/snowflake_object_assertions.tmpl similarity index 100% rename from pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions.tmpl rename to pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/snowflake_object_assertions.tmpl diff --git a/pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/snowflake_object_assertions_definition.tmpl similarity index 100% rename from pkg/acceptance/bettertestspoc/gen/templates/snowflake_object_assertions_definition.tmpl rename to pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/snowflake_object_assertions_definition.tmpl diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go b/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go index e0ddabfaa9..d801701e5f 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go @@ -1,3 +1,3 @@ package testgen -//go:generate go run ../../gen/snowflake_object_assertions/main.go $SF_TF_GENERATOR_ARGS +//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS From 0968d59c04c4313480c8c87289360e0e821c6481 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 22:23:40 +0200 Subject: [PATCH 37/62] Prepare snowflake object parameters generation --- Makefile | 6 +++ .../objectparametersassert/gen/commons.go | 19 +++++++++ .../objectparametersassert/gen/main/main.go | 40 +++++++++++++++++++ .../objectparametersassert/gen/model.go | 31 ++++++++++++++ .../objectparametersassert/gen/templates.go | 15 +++++++ .../gen/templates/preamble.tmpl | 18 +++++++++ .../assert/objectparametersassert/generate.go | 3 ++ 7 files changed, 132 insertions(+) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/generate.go diff --git a/Makefile b/Makefile index a06473f60a..1e0504f5bd 100644 --- a/Makefile +++ b/Makefile @@ -129,4 +129,10 @@ generate-snowflake-object-assertions: ## Generate snowflake object assertions 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/assert/objectparametersassert/gen/commons.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go new file mode 100644 index 0000000000..d035e3e6b0 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go @@ -0,0 +1,19 @@ +package gen + +import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + +type SnowflakeObjectParameters struct { + Name string + Level sdk.ParameterType + Parameters []SnowflakeParameter +} + +func (p SnowflakeObjectParameters) ObjectName() string { + return p.Name +} + +type SnowflakeParameter struct { + ParameterName string + ParameterType string + DefaultValue 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..168b1918ea --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -0,0 +1,40 @@ +//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/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +func main() { + gencommons.NewGenerator( + getAllSnowflakeObjectParameters, + gen.ModelFromSnowflakeObjectParameters, + getFilename, + gen.AllTemplates, + ). + RunAndHandleOsReturn() +} + +func getAllSnowflakeObjectParameters() []gen.SnowflakeObjectParameters { + return allObjectsParameters +} + +func getFilename(_ gen.SnowflakeObjectParameters, model gen.SnowflakeObjectParametersAssertionsModel) string { + return gencommons.ToSnakeCase(model.Name) + "_parameters_snowflake" + "_gen.go" +} + +// TODO: use SDK definition after parameters rework (+ preprocessing here) +var allObjectsParameters = []gen.SnowflakeObjectParameters{ + { + Name: "User", + Level: sdk.ParameterTypeUser, + Parameters: []gen.SnowflakeParameter{ + {string(sdk.UserParameterEnableUnredactedQuerySyntaxError), "bool", "false"}, + {string(sdk.UserParameterNetworkPolicy), "string", ""}, + {string(sdk.UserParameterPreventUnloadToInternalStages), "bool", "false"}, + }, + }, +} 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..7632b45265 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -0,0 +1,31 @@ +package gen + +import ( + "os" +) + +// TODO: extract to commons? +type PreambleModel struct { + PackageName string + AdditionalStandardImports []string +} + +type SnowflakeObjectParametersAssertionsModel struct { + Name string + PreambleModel +} + +func (m SnowflakeObjectParametersAssertionsModel) SomeFunc() { + return +} + +func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjectParameters) SnowflakeObjectParametersAssertionsModel { + packageWithGenerateDirective := os.Getenv("GOPACKAGE") + return SnowflakeObjectParametersAssertionsModel{ + Name: snowflakeObjectParameters.ObjectName(), + PreambleModel: PreambleModel{ + PackageName: packageWithGenerateDirective, + AdditionalStandardImports: []string{}, + }, + } +} 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..588c1d1e31 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -0,0 +1,15 @@ +package gen + +import ( + "text/template" + + _ "embed" +) + +var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate} +) 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..8036ea50ce --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl @@ -0,0 +1,18 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen.PreambleModel*/ -}} + +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package {{ .PackageName }} + +import ( +"strings" +"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/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 From c01ec37afa7bad6ffc010e32393f5ac4c67c9fbb Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 22:24:33 +0200 Subject: [PATCH 38/62] Rename templates --- .../bettertestspoc/assert/objectassert/gen/templates.go | 4 ++-- .../{snowflake_object_assertions.tmpl => assertions.tmpl} | 0 ...lake_object_assertions_definition.tmpl => definition.tmpl} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/{snowflake_object_assertions.tmpl => assertions.tmpl} (100%) rename pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/{snowflake_object_assertions_definition.tmpl => definition.tmpl} (100%) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go index d9863ac61f..ded37c9292 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go @@ -13,13 +13,13 @@ var ( preambleTemplateContent string PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) - //go:embed templates/snowflake_object_assertions_definition.tmpl + //go:embed templates/definition.tmpl snowflakeObjectAssertionsDefinitionTemplateContent string SnowflakeObjectAssertionsDefinitionTemplate, _ = template.New("snowflakeObjectAssertionsDefinitionTemplate").Funcs(gencommons.BuildTemplateFuncMap( gencommons.FirstLetterLowercase, )).Parse(snowflakeObjectAssertionsDefinitionTemplateContent) - //go:embed templates/snowflake_object_assertions.tmpl + //go:embed templates/assertions.tmpl snowflakeObjectAssertionsTemplateContent string SnowflakeObjectAssertionsTemplate, _ = template.New("snowflakeObjectAssertionsTemplate").Funcs(gencommons.BuildTemplateFuncMap( gencommons.FirstLetterLowercase, diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/snowflake_object_assertions.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl similarity index 100% rename from pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/snowflake_object_assertions.tmpl rename to pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/snowflake_object_assertions_definition.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl similarity index 100% rename from pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/snowflake_object_assertions_definition.tmpl rename to pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl From 94e58f48ae2542dec9cfc0b462d054f3cfc754f2 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 22:33:11 +0200 Subject: [PATCH 39/62] Continue objects parameters assertions generation --- .../gen/templates/assertions.tmpl | 2 +- .../gen/templates/definition.tmpl | 2 +- .../objectassert/gen/templates/preamble.tmpl | 2 +- .../objectparametersassert/gen/commons.go | 1 + .../objectparametersassert/gen/main/main.go | 5 +++-- .../objectparametersassert/gen/model.go | 6 ++++-- .../objectparametersassert/gen/templates.go | 6 +++++- .../gen/templates/definition.tmpl | 20 +++++++++++++++++++ .../gen/templates/preamble.tmpl | 2 +- 9 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/definition.tmpl diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl index b5e7fb25e2..dd8e63b8c3 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl @@ -1,4 +1,4 @@ -{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen.SnowflakeObjectAssertionsModel*/ -}} +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen.SnowflakeObjectAssertionsModel*/ -}} {{ $assertName := .Name | printf "%sAssert" }} {{ $sdkType := .SdkType }} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl index afc9299ea5..9ed6b410d1 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl @@ -1,4 +1,4 @@ -{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen.SnowflakeObjectAssertionsModel*/ -}} +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen.SnowflakeObjectAssertionsModel*/ -}} {{ $assertName := .Name | printf "%sAssert" }} {{ $nameLowerCase := FirstLetterLowercase .Name }} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl index e1d5e2e056..6f604544ec 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl @@ -1,4 +1,4 @@ -{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen.PreambleModel*/ -}} +{{- /*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. diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go index d035e3e6b0..404200addb 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go @@ -4,6 +4,7 @@ import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" type SnowflakeObjectParameters struct { Name string + IdType string Level sdk.ParameterType Parameters []SnowflakeParameter } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index 168b1918ea..5153344edc 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -29,8 +29,9 @@ func getFilename(_ gen.SnowflakeObjectParameters, model gen.SnowflakeObjectParam // TODO: use SDK definition after parameters rework (+ preprocessing here) var allObjectsParameters = []gen.SnowflakeObjectParameters{ { - Name: "User", - Level: sdk.ParameterTypeUser, + Name: "User", + IdType: "sdk.AccountObjectIdentifier", + Level: sdk.ParameterTypeUser, Parameters: []gen.SnowflakeParameter{ {string(sdk.UserParameterEnableUnredactedQuerySyntaxError), "bool", "false"}, {string(sdk.UserParameterNetworkPolicy), "string", ""}, diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go index 7632b45265..9e72b60e0c 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -11,7 +11,8 @@ type PreambleModel struct { } type SnowflakeObjectParametersAssertionsModel struct { - Name string + Name string + IdType string PreambleModel } @@ -22,7 +23,8 @@ func (m SnowflakeObjectParametersAssertionsModel) SomeFunc() { func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjectParameters) SnowflakeObjectParametersAssertionsModel { packageWithGenerateDirective := os.Getenv("GOPACKAGE") return SnowflakeObjectParametersAssertionsModel{ - Name: snowflakeObjectParameters.ObjectName(), + Name: snowflakeObjectParameters.ObjectName(), + IdType: snowflakeObjectParameters.IdType, PreambleModel: PreambleModel{ PackageName: packageWithGenerateDirective, AdditionalStandardImports: []string{}, diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go index 588c1d1e31..e92c934ecc 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -11,5 +11,9 @@ var ( preambleTemplateContent string PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) - AllTemplates = []*template.Template{PreambleTemplate} + //go:embed templates/definition.tmpl + snowflakeObjectAssertionsDefinitionTemplateContent string + SnowflakeObjectAssertionsDefinitionTemplate, _ = template.New("snowflakeObjectAssertionsDefinitionTemplate").Parse(snowflakeObjectAssertionsDefinitionTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate} ) 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..a29e74c701 --- /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/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl index 8036ea50ce..ad9984ca87 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl @@ -1,4 +1,4 @@ -{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/gen.PreambleModel*/ -}} +{{- /*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. From 1ab5384718ea2e4340f2e8f654af45ec69c64adb Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 22:46:23 +0200 Subject: [PATCH 40/62] Add generic checks generation --- .../objectparametersassert/gen/templates.go | 11 +++++- .../gen/templates/generic_checks.tmpl | 34 +++++++++++++++++++ .../assert/snowflake_parameters_assertions.go | 4 +++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go index e92c934ecc..a2361c52cf 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -4,6 +4,8 @@ import ( "text/template" _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" ) var ( @@ -15,5 +17,12 @@ var ( snowflakeObjectAssertionsDefinitionTemplateContent string SnowflakeObjectAssertionsDefinitionTemplate, _ = template.New("snowflakeObjectAssertionsDefinitionTemplate").Parse(snowflakeObjectAssertionsDefinitionTemplateContent) - AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate} + //go:embed templates/generic_checks.tmpl + genericChecksTemplateContent string + GenericChecksTemplate, _ = template.New("genericChecksTemplateContent").Funcs(gencommons.BuildTemplateFuncMap( + gencommons.FirstLetterLowercase, + gencommons.FirstLetter, + )).Parse(genericChecksTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, GenericChecksTemplate} ) 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..08f291ca68 --- /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(snowflakeParameterBoolValueSet(parameterName, expected)) +return {{ $assertVar }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasIntParameterValue(parameterName {{ $sdkParameterName }}, expected int) *{{ $assertName }} { +{{ $assertVar }}.AddAssertion(snowflakeParameterIntValueSet(parameterName, expected)) +return {{ $assertVar }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasStringParameterValue(parameterName {{ $sdkParameterName }}, expected string) *{{ $assertName }} { +{{ $assertVar }}.AddAssertion(snowflakeParameterValueSet(parameterName, expected)) +return {{ $assertVar }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasDefaultParameterValue(parameterName {{ $sdkParameterName }}) *{{ $assertName }} { +{{ $assertVar }}.AddAssertion(snowflakeParameterDefaultValueSet(parameterName)) +return {{ $assertVar }} +} + +func ({{ $assertVar }} *{{ $assertName }}) HasDefaultParameterValueOnLevel(parameterName {{ $sdkParameterName }}, parameterType sdk.ParameterType) *{{ $assertName }} { +{{ $assertVar }}.AddAssertion(snowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) +return {{ $assertVar }} +} diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index 20a48c3155..80d4f219f6 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -63,6 +63,10 @@ func NewSnowflakeParametersAssertWithParameters[I sdk.ObjectIdentifier](id I, ob } } +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)) } From c0ad76c4d01a5b3fffbbac07a372b39c0f54ecdf Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 22:50:18 +0200 Subject: [PATCH 41/62] Expose snowflake parameters assertions and helpers --- .../gen/templates/generic_checks.tmpl | 10 +- .../assert/snowflake_parameters_assertions.go | 42 +-- .../assert/user_parameters_snowflake.go | 242 +++++++++--------- 3 files changed, 147 insertions(+), 147 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl index 08f291ca68..143bc7e6de 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl @@ -9,26 +9,26 @@ ////////////////////////////// func ({{ $assertVar }} *{{ $assertName }}) HasBoolParameterValue(parameterName {{ $sdkParameterName }}, expected bool) *{{ $assertName }} { -{{ $assertVar }}.AddAssertion(snowflakeParameterBoolValueSet(parameterName, expected)) +{{ $assertVar }}.AddAssertion(assert.SnowflakeParameterBoolValueSet(parameterName, expected)) return {{ $assertVar }} } func ({{ $assertVar }} *{{ $assertName }}) HasIntParameterValue(parameterName {{ $sdkParameterName }}, expected int) *{{ $assertName }} { -{{ $assertVar }}.AddAssertion(snowflakeParameterIntValueSet(parameterName, expected)) +{{ $assertVar }}.AddAssertion(assert.SnowflakeParameterIntValueSet(parameterName, expected)) return {{ $assertVar }} } func ({{ $assertVar }} *{{ $assertName }}) HasStringParameterValue(parameterName {{ $sdkParameterName }}, expected string) *{{ $assertName }} { -{{ $assertVar }}.AddAssertion(snowflakeParameterValueSet(parameterName, expected)) +{{ $assertVar }}.AddAssertion(assert.SnowflakeParameterValueSet(parameterName, expected)) return {{ $assertVar }} } func ({{ $assertVar }} *{{ $assertName }}) HasDefaultParameterValue(parameterName {{ $sdkParameterName }}) *{{ $assertName }} { -{{ $assertVar }}.AddAssertion(snowflakeParameterDefaultValueSet(parameterName)) +{{ $assertVar }}.AddAssertion(assert.SnowflakeParameterDefaultValueSet(parameterName)) return {{ $assertVar }} } func ({{ $assertVar }} *{{ $assertName }}) HasDefaultParameterValueOnLevel(parameterName {{ $sdkParameterName }}, parameterType sdk.ParameterType) *{{ $assertName }} { -{{ $assertVar }}.AddAssertion(snowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) +{{ $assertVar }}.AddAssertion(assert.SnowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) return {{ $assertVar }} } diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index 80d4f219f6..db4b71d462 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -18,7 +18,7 @@ type ( // 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 + assertions []SnowflakeParameterAssertion id I objectType sdk.ObjectType provider parametersProvider[I] @@ -34,7 +34,7 @@ const ( snowflakeParameterAssertionTypeLevel ) -type snowflakeParameterAssertion struct { +type SnowflakeParameterAssertion struct { parameterName string expectedValue string parameterType sdk.ParameterType @@ -45,7 +45,7 @@ type snowflakeParameterAssertion struct { // 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), + assertions: make([]SnowflakeParameterAssertion, 0), id: id, objectType: objectType, provider: provider, @@ -56,48 +56,48 @@ func NewSnowflakeParametersAssertWithProvider[I sdk.ObjectIdentifier](id I, obje // 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), + assertions: make([]SnowflakeParameterAssertion, 0), id: id, objectType: objectType, parameters: parameters, } } -func (s *SnowflakeParametersAssert[I]) AddAssertion(assertion snowflakeParameterAssertion) { +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 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 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 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 SnowflakeParameterValueSet[T ~string](parameterName T, expected string) SnowflakeParameterAssertion { + return SnowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: expected} } // TODO: can we just replace all above with this one? -func snowflakeParameterValueSetGeneric[T ~string, U bool | int | ~string](parameterName T, expected U) snowflakeParameterAssertion { - return snowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: fmt.Sprintf("%s", expected)} +func snowflakeParameterValueSetGeneric[T ~string, U bool | int | ~string](parameterName T, expected U) SnowflakeParameterAssertion { + return SnowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: fmt.Sprintf("%s", expected)} } -func snowflakeParameterDefaultValueSet[T ~string](parameterName T) snowflakeParameterAssertion { - return snowflakeParameterAssertion{parameterName: string(parameterName), assertionType: snowflakeParameterAssertionTypeDefaultValue} +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 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} +func SnowflakeParameterLevelSet[T ~string](parameterName T, parameterType sdk.ParameterType) SnowflakeParameterAssertion { + return SnowflakeParameterAssertion{parameterName: string(parameterName), parameterType: parameterType, assertionType: snowflakeParameterAssertionTypeLevel} } // VerifyAll implements InPlaceAssertionVerifier to allow easier creation of new Snowflake parameters assertions. diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go index be751d4828..1692145c97 100644 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go @@ -34,27 +34,27 @@ func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, para ////////////////////////////// func (w *UserParametersAssert) HasBoolParameterValue(parameterName sdk.UserParameter, expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(parameterName, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(parameterName, expected)) return w } func (w *UserParametersAssert) HasIntParameterValue(parameterName sdk.UserParameter, expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(parameterName, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(parameterName, expected)) return w } func (w *UserParametersAssert) HasStringParameterValue(parameterName sdk.UserParameter, expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(parameterName, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(parameterName, expected)) return w } func (w *UserParametersAssert) HasDefaultParameterValue(parameterName sdk.UserParameter) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterDefaultValueSet(parameterName)) + w.assertions = append(w.assertions, SnowflakeParameterDefaultValueSet(parameterName)) return w } func (w *UserParametersAssert) HasDefaultParameterValueOnLevel(parameterName sdk.UserParameter, parameterType sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) + w.assertions = append(w.assertions, SnowflakeParameterDefaultValueOnLevelSet(parameterName, parameterType)) return w } @@ -196,585 +196,585 @@ func (w *UserParametersAssert) HasAllDefaultsExplicit() *UserParametersAssert { // value checks func (w *UserParametersAssert) HasEnableUnredactedQuerySyntaxError(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) return w } func (w *UserParametersAssert) HasNetworkPolicy(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterNetworkPolicy, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterNetworkPolicy, expected)) return w } func (w *UserParametersAssert) HasPreventUnloadToInternalStages(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) return w } func (w *UserParametersAssert) HasAbortDetachedQuery(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterAbortDetachedQuery, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterAbortDetachedQuery, expected)) return w } func (w *UserParametersAssert) HasAutocommit(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterAutocommit, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterAutocommit, expected)) return w } func (w *UserParametersAssert) HasBinaryInputFormat(expected sdk.BinaryInputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryInputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryInputFormat, expected)) return w } func (w *UserParametersAssert) HasBinaryOutputFormat(expected sdk.BinaryOutputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryOutputFormat, expected)) return w } func (w *UserParametersAssert) HasClientMemoryLimit(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterClientMemoryLimit, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterClientMemoryLimit, expected)) return w } func (w *UserParametersAssert) HasClientMetadataRequestUseConnectionCtx(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) return w } func (w *UserParametersAssert) HasClientPrefetchThreads(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterClientPrefetchThreads, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterClientPrefetchThreads, expected)) return w } func (w *UserParametersAssert) HasClientResultChunkSize(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterClientResultChunkSize, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterClientResultChunkSize, expected)) return w } func (w *UserParametersAssert) HasClientResultColumnCaseInsensitive(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) return w } func (w *UserParametersAssert) HasClientSessionKeepAlive(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterClientSessionKeepAlive, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterClientSessionKeepAlive, expected)) return w } func (w *UserParametersAssert) HasClientSessionKeepAliveHeartbeatFrequency(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) return w } func (w *UserParametersAssert) HasClientTimestampTypeMapping(expected sdk.ClientTimestampTypeMapping) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterClientTimestampTypeMapping, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterClientTimestampTypeMapping, expected)) return w } func (w *UserParametersAssert) HasDateInputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterDateInputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterDateInputFormat, expected)) return w } func (w *UserParametersAssert) HasDateOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterDateOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterDateOutputFormat, expected)) return w } func (w *UserParametersAssert) HasEnableUnloadPhysicalTypeOptimization(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) return w } func (w *UserParametersAssert) HasErrorOnNondeterministicMerge(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) return w } func (w *UserParametersAssert) HasErrorOnNondeterministicUpdate(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) return w } func (w *UserParametersAssert) HasGeographyOutputFormat(expected sdk.GeographyOutputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeographyOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeographyOutputFormat, expected)) return w } func (w *UserParametersAssert) HasGeometryOutputFormat(expected sdk.GeometryOutputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeometryOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeometryOutputFormat, expected)) return w } func (w *UserParametersAssert) HasJdbcTreatDecimalAsInt(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) return w } func (w *UserParametersAssert) HasJdbcTreatTimestampNtzAsUtc(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) return w } func (w *UserParametersAssert) HasJdbcUseSessionTimezone(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) return w } func (w *UserParametersAssert) HasJsonIndent(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterJsonIndent, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterJsonIndent, expected)) return w } func (w *UserParametersAssert) HasLockTimeout(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterLockTimeout, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterLockTimeout, expected)) return w } func (w *UserParametersAssert) HasLogLevel(expected sdk.LogLevel) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterLogLevel, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterLogLevel, expected)) return w } func (w *UserParametersAssert) HasMultiStatementCount(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterMultiStatementCount, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterMultiStatementCount, expected)) return w } func (w *UserParametersAssert) HasNoorderSequenceAsDefault(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) return w } func (w *UserParametersAssert) HasOdbcTreatDecimalAsInt(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) return w } func (w *UserParametersAssert) HasQueryTag(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterQueryTag, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterQueryTag, expected)) return w } func (w *UserParametersAssert) HasQuotedIdentifiersIgnoreCase(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) return w } func (w *UserParametersAssert) HasRowsPerResultset(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterRowsPerResultset, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterRowsPerResultset, expected)) return w } func (w *UserParametersAssert) HasS3StageVpceDnsName(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterS3StageVpceDnsName, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterS3StageVpceDnsName, expected)) return w } func (w *UserParametersAssert) HasSearchPath(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterSearchPath, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterSearchPath, expected)) return w } func (w *UserParametersAssert) HasSimulatedDataSharingConsumer(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) return w } func (w *UserParametersAssert) HasStatementQueuedTimeoutInSeconds(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) return w } func (w *UserParametersAssert) HasStatementTimeoutInSeconds(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) return w } func (w *UserParametersAssert) HasStrictJsonOutput(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterStrictJsonOutput, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterStrictJsonOutput, expected)) return w } func (w *UserParametersAssert) HasTimestampDayIsAlways24h(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) return w } func (w *UserParametersAssert) HasTimestampInputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampInputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampInputFormat, expected)) return w } func (w *UserParametersAssert) HasTimestampLtzOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTimestampNtzOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTimestampOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTimestampTypeMapping(expected sdk.TimestampTypeMapping) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTimestampTypeMapping, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTimestampTypeMapping, expected)) return w } func (w *UserParametersAssert) HasTimestampTzOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimestampTzOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampTzOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTimezone(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimezone, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimezone, expected)) return w } func (w *UserParametersAssert) HasTimeInputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimeInputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimeInputFormat, expected)) return w } func (w *UserParametersAssert) HasTimeOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterTimeOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimeOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTraceLevel(expected sdk.TraceLevel) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTraceLevel, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTraceLevel, expected)) return w } func (w *UserParametersAssert) HasTransactionAbortOnError(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterTransactionAbortOnError, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterTransactionAbortOnError, expected)) return w } func (w *UserParametersAssert) HasTransactionDefaultIsolationLevel(expected sdk.TransactionDefaultIsolationLevel) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) + w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) return w } func (w *UserParametersAssert) HasTwoDigitCenturyStart(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterTwoDigitCenturyStart, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterTwoDigitCenturyStart, expected)) return w } // lowercase for ignore in snowflake by default but uppercase for FAIL func (w *UserParametersAssert) HasUnsupportedDdlAction(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterValueSet(sdk.UserParameterUnsupportedDdlAction, expected)) + w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterUnsupportedDdlAction, expected)) return w } func (w *UserParametersAssert) HasUseCachedResult(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterBoolValueSet(sdk.UserParameterUseCachedResult, expected)) + w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterUseCachedResult, expected)) return w } func (w *UserParametersAssert) HasWeekOfYearPolicy(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterWeekOfYearPolicy, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterWeekOfYearPolicy, expected)) return w } func (w *UserParametersAssert) HasWeekStart(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterIntValueSet(sdk.UserParameterWeekStart, expected)) + w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterWeekStart, expected)) return w } // level checks func (w *UserParametersAssert) HasEnableUnredactedQuerySyntaxErrorLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) return w } func (w *UserParametersAssert) HasNetworkPolicyLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterNetworkPolicy, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterNetworkPolicy, expected)) return w } func (w *UserParametersAssert) HasPreventUnloadToInternalStagesLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) return w } func (w *UserParametersAssert) HasAbortDetachedQueryLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterAbortDetachedQuery, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterAbortDetachedQuery, expected)) return w } func (w *UserParametersAssert) HasAutocommitLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterAutocommit, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterAutocommit, expected)) return w } func (w *UserParametersAssert) HasBinaryInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterBinaryInputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterBinaryInputFormat, expected)) return w } func (w *UserParametersAssert) HasBinaryOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterBinaryOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterBinaryOutputFormat, expected)) return w } func (w *UserParametersAssert) HasClientMemoryLimitLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientMemoryLimit, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientMemoryLimit, expected)) return w } func (w *UserParametersAssert) HasClientMetadataRequestUseConnectionCtxLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) return w } func (w *UserParametersAssert) HasClientPrefetchThreadsLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientPrefetchThreads, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientPrefetchThreads, expected)) return w } func (w *UserParametersAssert) HasClientResultChunkSizeLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientResultChunkSize, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientResultChunkSize, expected)) return w } func (w *UserParametersAssert) HasClientResultColumnCaseInsensitiveLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) return w } func (w *UserParametersAssert) HasClientSessionKeepAliveLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAlive, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAlive, expected)) return w } func (w *UserParametersAssert) HasClientSessionKeepAliveHeartbeatFrequencyLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) return w } func (w *UserParametersAssert) HasClientTimestampTypeMappingLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterClientTimestampTypeMapping, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientTimestampTypeMapping, expected)) return w } func (w *UserParametersAssert) HasDateInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterDateInputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterDateInputFormat, expected)) return w } func (w *UserParametersAssert) HasDateOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterDateOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterDateOutputFormat, expected)) return w } func (w *UserParametersAssert) HasEnableUnloadPhysicalTypeOptimizationLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) return w } func (w *UserParametersAssert) HasErrorOnNondeterministicMergeLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) return w } func (w *UserParametersAssert) HasErrorOnNondeterministicUpdateLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) return w } func (w *UserParametersAssert) HasGeographyOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterGeographyOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterGeographyOutputFormat, expected)) return w } func (w *UserParametersAssert) HasGeometryOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterGeometryOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterGeometryOutputFormat, expected)) return w } func (w *UserParametersAssert) HasJdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) return w } func (w *UserParametersAssert) HasJdbcTreatTimestampNtzAsUtcLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) return w } func (w *UserParametersAssert) HasJdbcUseSessionTimezoneLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) return w } func (w *UserParametersAssert) HasJsonIndentLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterJsonIndent, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterJsonIndent, expected)) return w } func (w *UserParametersAssert) HasLockTimeoutLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterLockTimeout, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterLockTimeout, expected)) return w } func (w *UserParametersAssert) HasLogLevelLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterLogLevel, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterLogLevel, expected)) return w } func (w *UserParametersAssert) HasMultiStatementCountLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterMultiStatementCount, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterMultiStatementCount, expected)) return w } func (w *UserParametersAssert) HasNoorderSequenceAsDefaultLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) return w } func (w *UserParametersAssert) HasOdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) return w } func (w *UserParametersAssert) HasQueryTagLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterQueryTag, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterQueryTag, expected)) return w } func (w *UserParametersAssert) HasQuotedIdentifiersIgnoreCaseLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) return w } func (w *UserParametersAssert) HasRowsPerResultsetLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterRowsPerResultset, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterRowsPerResultset, expected)) return w } func (w *UserParametersAssert) HasS3StageVpceDnsNameLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterS3StageVpceDnsName, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterS3StageVpceDnsName, expected)) return w } func (w *UserParametersAssert) HasSearchPathLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterSearchPath, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterSearchPath, expected)) return w } func (w *UserParametersAssert) HasSimulatedDataSharingConsumerLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) return w } func (w *UserParametersAssert) HasStatementQueuedTimeoutInSecondsLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) return w } func (w *UserParametersAssert) HasStatementTimeoutInSecondsLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) return w } func (w *UserParametersAssert) HasStrictJsonOutputLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterStrictJsonOutput, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterStrictJsonOutput, expected)) return w } func (w *UserParametersAssert) HasTimestampDayIsAlways24hLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) return w } func (w *UserParametersAssert) HasTimestampInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampInputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampInputFormat, expected)) return w } func (w *UserParametersAssert) HasTimestampLtzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTimestampNtzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTimestampOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTimestampTypeMappingLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampTypeMapping, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampTypeMapping, expected)) return w } func (w *UserParametersAssert) HasTimestampTzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimestampTzOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampTzOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTimezoneLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimezone, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimezone, expected)) return w } func (w *UserParametersAssert) HasTimeInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimeInputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimeInputFormat, expected)) return w } func (w *UserParametersAssert) HasTimeOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTimeOutputFormat, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimeOutputFormat, expected)) return w } func (w *UserParametersAssert) HasTraceLevelLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTraceLevel, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTraceLevel, expected)) return w } func (w *UserParametersAssert) HasTransactionAbortOnErrorLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTransactionAbortOnError, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTransactionAbortOnError, expected)) return w } func (w *UserParametersAssert) HasTransactionDefaultIsolationLevelLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) return w } func (w *UserParametersAssert) HasTwoDigitCenturyStartLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterTwoDigitCenturyStart, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTwoDigitCenturyStart, expected)) return w } func (w *UserParametersAssert) HasUnsupportedDdlActionLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterUnsupportedDdlAction, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterUnsupportedDdlAction, expected)) return w } func (w *UserParametersAssert) HasUseCachedResultLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterUseCachedResult, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterUseCachedResult, expected)) return w } func (w *UserParametersAssert) HasWeekOfYearPolicyLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterWeekOfYearPolicy, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterWeekOfYearPolicy, expected)) return w } func (w *UserParametersAssert) HasWeekStartLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, snowflakeParameterLevelSet(sdk.UserParameterWeekStart, expected)) + w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterWeekStart, expected)) return w } From 22af4ff6cd29e7083f942b87aadae9ef5a329209 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 23:19:42 +0200 Subject: [PATCH 42/62] Add aggregated generic checks --- .../objectparametersassert/gen/commons.go | 1 + .../objectparametersassert/gen/main/main.go | 6 ++-- .../objectparametersassert/gen/model.go | 23 ++++++++++++--- .../objectparametersassert/gen/templates.go | 11 +++++++- .../templates/aggregated_generic_checks.tmpl | 28 +++++++++++++++++++ .../gen/templates/generic_checks.tmpl | 9 +++--- pkg/internal/gencommons/template_commons.go | 13 +++++++++ 7 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go index 404200addb..1df4ab3f8b 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go @@ -17,4 +17,5 @@ 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 index 5153344edc..eb6a077b76 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -33,9 +33,9 @@ var allObjectsParameters = []gen.SnowflakeObjectParameters{ IdType: "sdk.AccountObjectIdentifier", Level: sdk.ParameterTypeUser, Parameters: []gen.SnowflakeParameter{ - {string(sdk.UserParameterEnableUnredactedQuerySyntaxError), "bool", "false"}, - {string(sdk.UserParameterNetworkPolicy), "string", ""}, - {string(sdk.UserParameterPreventUnloadToInternalStages), "bool", "false"}, + {string(sdk.UserParameterEnableUnredactedQuerySyntaxError), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterNetworkPolicy), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterPreventUnloadToInternalStages), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, }, }, } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go index 9e72b60e0c..cff4256fc6 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -11,20 +11,35 @@ type PreambleModel struct { } type SnowflakeObjectParametersAssertionsModel struct { - Name string - IdType string + Name string + IdType string + Parameters []ParameterAssertionModel PreambleModel } +type ParameterAssertionModel struct { + Name string + DefaultLevel string +} + func (m SnowflakeObjectParametersAssertionsModel) SomeFunc() { return } func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjectParameters) SnowflakeObjectParametersAssertionsModel { + parameters := make([]ParameterAssertionModel, len(snowflakeObjectParameters.Parameters)) + for idx, p := range snowflakeObjectParameters.Parameters { + parameters[idx] = ParameterAssertionModel{ + Name: p.ParameterName, + DefaultLevel: p.DefaultLevel, + } + } + packageWithGenerateDirective := os.Getenv("GOPACKAGE") return SnowflakeObjectParametersAssertionsModel{ - Name: snowflakeObjectParameters.ObjectName(), - IdType: snowflakeObjectParameters.IdType, + Name: snowflakeObjectParameters.ObjectName(), + IdType: snowflakeObjectParameters.IdType, + Parameters: parameters, PreambleModel: PreambleModel{ PackageName: packageWithGenerateDirective, AdditionalStandardImports: []string{}, diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go index a2361c52cf..e5529a7868 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -24,5 +24,14 @@ var ( gencommons.FirstLetter, )).Parse(genericChecksTemplateContent) - AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, GenericChecksTemplate} + //go:embed templates/aggregated_generic_checks.tmpl + aggregatedGenericChecksTemplateContent string + AggregatedGenericChecksTemplate, _ = template.New("genericChecksTemplateContent").Funcs(gencommons.BuildTemplateFuncMap( + gencommons.FirstLetterLowercase, + gencommons.FirstLetter, + gencommons.SnakeCaseToCamel, + gencommons.IsLastItem, + )).Parse(aggregatedGenericChecksTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, GenericChecksTemplate, AggregatedGenericChecksTemplate} ) 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..4644df5435 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl @@ -0,0 +1,28 @@ +{{- /*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 }}Explicit(){{ if not (IsLastItem $index $parametersCount) }}.{{ end }} +{{- end }} +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl index 143bc7e6de..61b5a04905 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl @@ -1,9 +1,10 @@ {{- /*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 }} +{{- $assertName := .Name | printf "%sParametersAssert" -}} +{{- $sdkParameterName := .Name | printf "sdk.%sParameter" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $assertVar := FirstLetter $nameLowerCase -}} + ////////////////////////////// // Generic parameter checks // ////////////////////////////// diff --git a/pkg/internal/gencommons/template_commons.go b/pkg/internal/gencommons/template_commons.go index 8f8fde25ab..639306cdc7 100644 --- a/pkg/internal/gencommons/template_commons.go +++ b/pkg/internal/gencommons/template_commons.go @@ -28,6 +28,19 @@ 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 { var allFuncs = make(map[string]any) for _, f := range funcs { From 66b183125f2381274ff7d89dbb97f795326401b6 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 23:47:33 +0200 Subject: [PATCH 43/62] Add value checks --- .../objectparametersassert/gen/model.go | 28 ++++++++++++++++--- .../objectparametersassert/gen/templates.go | 12 ++++++-- .../templates/aggregated_generic_checks.tmpl | 3 +- .../gen/templates/generic_checks.tmpl | 3 +- .../gen/templates/value_checks.tmpl | 17 +++++++++++ 5 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/value_checks.tmpl diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go index cff4256fc6..93259c2633 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -2,6 +2,7 @@ package gen import ( "os" + "strings" ) // TODO: extract to commons? @@ -18,8 +19,10 @@ type SnowflakeObjectParametersAssertionsModel struct { } type ParameterAssertionModel struct { - Name string - DefaultLevel string + Name string + Type string + DefaultLevel string + AssertionCreator string } func (m SnowflakeObjectParametersAssertionsModel) SomeFunc() { @@ -29,9 +32,26 @@ func (m SnowflakeObjectParametersAssertionsModel) SomeFunc() { func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjectParameters) SnowflakeObjectParametersAssertionsModel { parameters := make([]ParameterAssertionModel, len(snowflakeObjectParameters.Parameters)) for idx, p := range snowflakeObjectParameters.Parameters { + // TODO: 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" + default: + assertionCreator = "SnowflakeParameterValueSet" + } + parameters[idx] = ParameterAssertionModel{ - Name: p.ParameterName, - DefaultLevel: p.DefaultLevel, + Name: p.ParameterName, + Type: p.ParameterType, + DefaultLevel: p.DefaultLevel, + AssertionCreator: assertionCreator, } } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go index e5529a7868..a708add968 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -26,12 +26,20 @@ var ( //go:embed templates/aggregated_generic_checks.tmpl aggregatedGenericChecksTemplateContent string - AggregatedGenericChecksTemplate, _ = template.New("genericChecksTemplateContent").Funcs(gencommons.BuildTemplateFuncMap( + AggregatedGenericChecksTemplate, _ = template.New("aggregatedGenericChecksTemplateContent").Funcs(gencommons.BuildTemplateFuncMap( gencommons.FirstLetterLowercase, gencommons.FirstLetter, gencommons.SnakeCaseToCamel, gencommons.IsLastItem, )).Parse(aggregatedGenericChecksTemplateContent) - AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, GenericChecksTemplate, AggregatedGenericChecksTemplate} + //go:embed templates/value_checks.tmpl + valueChecksTemplateContent string + ValueChecksTemplate, _ = template.New("valueChecksTemplateContent").Funcs(gencommons.BuildTemplateFuncMap( + gencommons.FirstLetterLowercase, + gencommons.FirstLetter, + gencommons.SnakeCaseToCamel, + )).Parse(valueChecksTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, GenericChecksTemplate, AggregatedGenericChecksTemplate, ValueChecksTemplate} ) 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 index 4644df5435..0d9589ed87 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl @@ -4,8 +4,7 @@ {{- $sdkParameterName := .Name | printf "sdk.%sParameter" -}} {{- $nameLowerCase := FirstLetterLowercase .Name -}} {{- $assertVar := FirstLetter $nameLowerCase -}} -{{- $parametersCount := len .Parameters -}} - +{{- $parametersCount := len .Parameters }} /////////////////////////////// // Aggregated generic checks // /////////////////////////////// diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl index 61b5a04905..a756e04a15 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl @@ -3,8 +3,7 @@ {{- $assertName := .Name | printf "%sParametersAssert" -}} {{- $sdkParameterName := .Name | printf "sdk.%sParameter" -}} {{- $nameLowerCase := FirstLetterLowercase .Name -}} -{{- $assertVar := FirstLetter $nameLowerCase -}} - +{{- $assertVar := FirstLetter $nameLowerCase }} ////////////////////////////// // Generic parameter checks // ////////////////////////////// diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/value_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/value_checks.tmpl new file mode 100644 index 0000000000..38a08202f2 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/value_checks.tmpl @@ -0,0 +1,17 @@ +{{- /*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 }} From 043e9bf1d4a3308f20eb92778cf5a61e547d63ec Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 21 Jul 2024 23:59:53 +0200 Subject: [PATCH 44/62] Add all other specific object parameter checks --- .../objectparametersassert/gen/model.go | 9 ++++ .../objectparametersassert/gen/templates.go | 14 ++--- .../gen/templates/preamble.tmpl | 1 - .../gen/templates/specific_checks.tmpl | 51 +++++++++++++++++++ .../gen/templates/value_checks.tmpl | 17 ------- 5 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl delete mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/value_checks.tmpl diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go index 93259c2633..0517c32f8d 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -1,6 +1,7 @@ package gen import ( + "fmt" "os" "strings" ) @@ -21,6 +22,7 @@ type SnowflakeObjectParametersAssertionsModel struct { type ParameterAssertionModel struct { Name string Type string + DefaultValue string DefaultLevel string AssertionCreator string } @@ -47,9 +49,16 @@ func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjec assertionCreator = "SnowflakeParameterValueSet" } + var 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, } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go index a708add968..634ef5f66d 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -19,27 +19,27 @@ var ( //go:embed templates/generic_checks.tmpl genericChecksTemplateContent string - GenericChecksTemplate, _ = template.New("genericChecksTemplateContent").Funcs(gencommons.BuildTemplateFuncMap( + GenericChecksTemplate, _ = template.New("genericChecksTemplate").Funcs(gencommons.BuildTemplateFuncMap( gencommons.FirstLetterLowercase, gencommons.FirstLetter, )).Parse(genericChecksTemplateContent) //go:embed templates/aggregated_generic_checks.tmpl aggregatedGenericChecksTemplateContent string - AggregatedGenericChecksTemplate, _ = template.New("aggregatedGenericChecksTemplateContent").Funcs(gencommons.BuildTemplateFuncMap( + AggregatedGenericChecksTemplate, _ = template.New("aggregatedGenericChecksTemplate").Funcs(gencommons.BuildTemplateFuncMap( gencommons.FirstLetterLowercase, gencommons.FirstLetter, gencommons.SnakeCaseToCamel, gencommons.IsLastItem, )).Parse(aggregatedGenericChecksTemplateContent) - //go:embed templates/value_checks.tmpl - valueChecksTemplateContent string - ValueChecksTemplate, _ = template.New("valueChecksTemplateContent").Funcs(gencommons.BuildTemplateFuncMap( + //go:embed templates/specific_checks.tmpl + specificChecksTemplateContent string + SpecificChecksTemplate, _ = template.New("specificChecksTemplate").Funcs(gencommons.BuildTemplateFuncMap( gencommons.FirstLetterLowercase, gencommons.FirstLetter, gencommons.SnakeCaseToCamel, - )).Parse(valueChecksTemplateContent) + )).Parse(specificChecksTemplateContent) - AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, GenericChecksTemplate, AggregatedGenericChecksTemplate, ValueChecksTemplate} + AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, GenericChecksTemplate, AggregatedGenericChecksTemplate, SpecificChecksTemplate} ) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl index ad9984ca87..f03ab70821 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl @@ -5,7 +5,6 @@ package {{ .PackageName }} import ( -"strings" "testing" {{- range .AdditionalStandardImports }} "{{- . }}" 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..74ee0e7f46 --- /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 }}() *{{ $assertName }} { + return {{ $assertVar }}.HasDefaultParameterValue({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}) + } + +{{ end -}} + +///////////////////////////////////////////// +// Parameter explicit default value checks // +///////////////////////////////////////////// + +{{ range .Parameters -}} + func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}Explicit() *{{ $assertName }} { + return {{ $assertVar }}.Has{{ SnakeCaseToCamel .Name }}({{ .DefaultValue }}) + } + +{{ end }} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/value_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/value_checks.tmpl deleted file mode 100644 index 38a08202f2..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/value_checks.tmpl +++ /dev/null @@ -1,17 +0,0 @@ -{{- /*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 }} From d450052ce0e9efdacd2b34e49a7a3c908313819f Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 00:02:12 +0200 Subject: [PATCH 45/62] Clean up templates a bit --- .../assert/objectassert/gen/templates.go | 14 +++++++------- .../assert/objectparametersassert/gen/templates.go | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go index ded37c9292..f73f0342e2 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go @@ -14,19 +14,19 @@ var ( PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) //go:embed templates/definition.tmpl - snowflakeObjectAssertionsDefinitionTemplateContent string - SnowflakeObjectAssertionsDefinitionTemplate, _ = template.New("snowflakeObjectAssertionsDefinitionTemplate").Funcs(gencommons.BuildTemplateFuncMap( + definitionTemplateContent string + DefinitionTemplate, _ = template.New("definitionTemplate").Funcs(gencommons.BuildTemplateFuncMap( gencommons.FirstLetterLowercase, - )).Parse(snowflakeObjectAssertionsDefinitionTemplateContent) + )).Parse(definitionTemplateContent) //go:embed templates/assertions.tmpl - snowflakeObjectAssertionsTemplateContent string - SnowflakeObjectAssertionsTemplate, _ = template.New("snowflakeObjectAssertionsTemplate").Funcs(gencommons.BuildTemplateFuncMap( + assertionsTemplateContent string + AssertionsTemplate, _ = template.New("assertionsTemplate").Funcs(gencommons.BuildTemplateFuncMap( gencommons.FirstLetterLowercase, gencommons.FirstLetter, gencommons.TypeWithoutPointer, gencommons.CamelToWords, - )).Parse(snowflakeObjectAssertionsTemplateContent) + )).Parse(assertionsTemplateContent) - AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, SnowflakeObjectAssertionsTemplate} + AllTemplates = []*template.Template{PreambleTemplate, DefinitionTemplate, AssertionsTemplate} ) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go index 634ef5f66d..3386e815fd 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -14,8 +14,8 @@ var ( PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) //go:embed templates/definition.tmpl - snowflakeObjectAssertionsDefinitionTemplateContent string - SnowflakeObjectAssertionsDefinitionTemplate, _ = template.New("snowflakeObjectAssertionsDefinitionTemplate").Parse(snowflakeObjectAssertionsDefinitionTemplateContent) + definitionTemplateContent string + DefinitionTemplate, _ = template.New("definitionTemplate").Parse(definitionTemplateContent) //go:embed templates/generic_checks.tmpl genericChecksTemplateContent string @@ -41,5 +41,5 @@ var ( gencommons.SnakeCaseToCamel, )).Parse(specificChecksTemplateContent) - AllTemplates = []*template.Template{PreambleTemplate, SnowflakeObjectAssertionsDefinitionTemplate, GenericChecksTemplate, AggregatedGenericChecksTemplate, SpecificChecksTemplate} + AllTemplates = []*template.Template{PreambleTemplate, DefinitionTemplate, GenericChecksTemplate, AggregatedGenericChecksTemplate, SpecificChecksTemplate} ) From 8e2d2387371d2cd733f412c3a025e638ccc0fa05 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 00:20:39 +0200 Subject: [PATCH 46/62] Add all user parameters --- .../objectparametersassert/gen/main/main.go | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index eb6a077b76..3f7863d5f5 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -36,6 +36,61 @@ var allObjectsParameters = []gen.SnowflakeObjectParameters{ {string(sdk.UserParameterEnableUnredactedQuerySyntaxError), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, {string(sdk.UserParameterNetworkPolicy), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, {string(sdk.UserParameterPreventUnloadToInternalStages), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterAbortDetachedQuery), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterAutocommit), "bool", "true", "sdk.ParameterTypeAccount"}, + {string(sdk.UserParameterBinaryInputFormat), "sdk.BinaryInputFormat", "sdk.BinaryInputFormatHex", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterBinaryOutputFormat), "sdk.BinaryOutputFormat", "sdk.BinaryOutputFormatHex", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterClientMemoryLimit), "int", "1536", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterClientMetadataRequestUseConnectionCtx), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterClientPrefetchThreads), "int", "4", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterClientResultChunkSize), "int", "160", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterClientResultColumnCaseInsensitive), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterClientSessionKeepAlive), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency), "int", "3600", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterClientTimestampTypeMapping), "sdk.ClientTimestampTypeMapping", "sdk.ClientTimestampTypeMappingLtz", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterDateInputFormat), "string", "AUTO", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterDateOutputFormat), "string", "YYYY-MM-DD", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterEnableUnloadPhysicalTypeOptimization), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterErrorOnNondeterministicMerge), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterErrorOnNondeterministicUpdate), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterGeographyOutputFormat), "sdk.GeographyOutputFormat", "sdk.GeographyOutputFormatGeoJSON", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterGeometryOutputFormat), "sdk.GeometryOutputFormat", "sdk.GeometryOutputFormatGeoJSON", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterJdbcTreatDecimalAsInt), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterJdbcTreatTimestampNtzAsUtc), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterJdbcUseSessionTimezone), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterJsonIndent), "int", "2", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterLockTimeout), "int", "43200", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterLogLevel), "sdk.LogLevel", "sdk.LogLevelOff", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterMultiStatementCount), "int", "1", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterNoorderSequenceAsDefault), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterOdbcTreatDecimalAsInt), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterQueryTag), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterQuotedIdentifiersIgnoreCase), "bool", "false", "sdk.ParameterTypeAccount"}, + {string(sdk.UserParameterRowsPerResultset), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterS3StageVpceDnsName), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterSearchPath), "string", "$current, $public", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterSimulatedDataSharingConsumer), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterStatementQueuedTimeoutInSeconds), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterStatementTimeoutInSeconds), "int", "172800", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterStrictJsonOutput), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimestampDayIsAlways24h), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimestampInputFormat), "string", "AUTO", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimestampLtzOutputFormat), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimestampNtzOutputFormat), "string", "YYYY-MM-DD HH24:MI:SS.FF3", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimestampOutputFormat), "string", "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimestampTypeMapping), "sdk.TimestampTypeMapping", "sdk.TimestampTypeMappingNtz", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimestampTzOutputFormat), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimezone), "string", "America/Los_Angeles", "sdk.ParameterTypeAccount"}, + {string(sdk.UserParameterTimeInputFormat), "string", "AUTO", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTimeOutputFormat), "string", "HH24:MI:SS", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTraceLevel), "sdk.TraceLevel", "sdk.TraceLevelOff", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTransactionAbortOnError), "bool", "false", "sdk.ParameterTypeAccount"}, + {string(sdk.UserParameterTransactionDefaultIsolationLevel), "sdk.TransactionDefaultIsolationLevel", "sdk.TransactionDefaultIsolationLevelReadCommitted", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterTwoDigitCenturyStart), "int", "1970", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterUnsupportedDdlAction), "sdk.UnsupportedDDLAction", "sdk.UnsupportedDDLActionIgnore", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterUseCachedResult), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterWeekOfYearPolicy), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.UserParameterWeekStart), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, }, }, } From 839b2db62ced211ad4e4ee21e5590ae6d4782259 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 00:28:45 +0200 Subject: [PATCH 47/62] Change names --- .../gen/templates/aggregated_generic_checks.tmpl | 2 +- .../objectparametersassert/gen/templates/specific_checks.tmpl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 index 0d9589ed87..e291c13ccf 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl @@ -22,6 +22,6 @@ return {{ $assertVar }}. func ({{ $assertVar }} *{{ $assertName }}) HasAllDefaultsExplicit() *{{ $assertName }} { return {{ $assertVar }}. {{- range $index, $item := .Parameters }} - HasDefault{{ SnakeCaseToCamel .Name }}Explicit(){{ if not (IsLastItem $index $parametersCount) }}.{{ end }} + HasDefault{{ SnakeCaseToCamel .Name }}ValueExplicit(){{ if not (IsLastItem $index $parametersCount) }}.{{ end }} {{- end }} } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl index 74ee0e7f46..152d5c9cc6 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl @@ -33,7 +33,7 @@ //////////////////////////////////// {{ range .Parameters -}} - func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}() *{{ $assertName }} { + func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}Value() *{{ $assertName }} { return {{ $assertVar }}.HasDefaultParameterValue({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}) } @@ -44,7 +44,7 @@ ///////////////////////////////////////////// {{ range .Parameters -}} - func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}Explicit() *{{ $assertName }} { + func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}ValueExplicit() *{{ $assertName }} { return {{ $assertVar }}.Has{{ SnakeCaseToCamel .Name }}({{ .DefaultValue }}) } From 0d768e91424c93829ee847d32eaa94c34b862d6f Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 13:31:41 +0200 Subject: [PATCH 48/62] Update comment --- pkg/schemas/gen/main/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 58ccc9f106..46a9b653ec 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -69,6 +69,7 @@ func printUniqueTypes(allStructs []gencommons.StructDetails) { } // TODO: describe filtering: make generate-show-output-schemas SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES="sdk.Warehouse,sdk.User" +// TODO: move this filter to commons and consider extracting this as a command line param func filterByNameFromEnv(o gencommons.StructDetails) bool { allowedObjectNamesString := os.Getenv("SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES") if allowedObjectNamesString == "" { From 351797fc2cee7297eb360206463aa2aa2cafa0db Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 13:37:41 +0200 Subject: [PATCH 49/62] Generate snowflake object assertion for warehouse and user --- .../assert/objectassert/user_snowflake_gen.go | 318 +++++ .../objectassert/warehouse_snowflake_gen.go | 329 +++++ .../objectparametersassert/gen/main/main.go | 10 + .../user_parameters_snowflake_gen.go | 1250 +++++++++++++++++ .../warehouse_parameters_snowflake_gen.go | 150 ++ pkg/sdk/parameters.go | 8 + 6 files changed, 2065 insertions(+) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go create mode 100644 pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/warehouse_parameters_snowflake_gen.go diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go new file mode 100644 index 0000000000..f1a32c1eed --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go @@ -0,0 +1,318 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package testgen + +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 UserAssert struct { + *assert.SnowflakeObjectAssert[sdk.User, sdk.AccountObjectIdentifier] +} + +func User(t *testing.T, id sdk.AccountObjectIdentifier) *UserAssert { + t.Helper() + return &UserAssert{ + assert.NewSnowflakeObjectAssertWithProvider(sdk.ObjectTypeUser, id, acc.TestClient().User.Show), + } +} + +func UserFromObject(t *testing.T, user *sdk.User) *UserAssert { + t.Helper() + return &UserAssert{ + assert.NewSnowflakeObjectAssertWithObject(sdk.ObjectTypeUser, user.ID(), user), + } +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 authn duo: %v; got: %v", expected, o.ExtAuthnDuo) + } + return nil + }) + return u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} + +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 u +} 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..cdc714ce73 --- /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 testgen + +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 != expected { + return fmt.Errorf("expected resource monitor: %v; got: %v", expected, o.ResourceMonitor) + } + 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/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index 3f7863d5f5..f1aac5d98f 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -93,4 +93,14 @@ var allObjectsParameters = []gen.SnowflakeObjectParameters{ {string(sdk.UserParameterWeekStart), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, }, }, + { + Name: "Warehouse", + IdType: "sdk.AccountObjectIdentifier", + Level: sdk.ParameterTypeWarehouse, + Parameters: []gen.SnowflakeParameter{ + {string(sdk.WarehouseParameterMaxConcurrencyLevel), "int", "8", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, + {string(sdk.WarehouseParameterStatementTimeoutInSeconds), "int", "172800", "sdk.ParameterTypeSnowflakeDefault"}, + }, + }, } 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..1beba56a9a --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go @@ -0,0 +1,1250 @@ +// 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 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.ParameterTypeAccount). + 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.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/sdk/parameters.go b/pkg/sdk/parameters.go index f68b217251..0ce924025b 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 From 202d92afc9f06f0fb65e3e65e8062e1ff23d7548 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 13:47:48 +0200 Subject: [PATCH 50/62] Fix the package and use generated user assertions --- .../assert/objectassert/generate.go | 2 +- .../{ => objectassert}/user_snowflake_ext.go | 18 +- .../assert/objectassert/user_snowflake_gen.go | 2 +- .../objectassert/warehouse_snowflake_gen.go | 2 +- .../bettertestspoc/assert/user_snowflake.go | 315 ------------------ pkg/sdk/testint/users_integration_test.go | 30 +- 6 files changed, 28 insertions(+), 341 deletions(-) rename pkg/acceptance/bettertestspoc/assert/{ => objectassert}/user_snowflake_ext.go (81%) delete mode 100644 pkg/acceptance/bettertestspoc/assert/user_snowflake.go diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go b/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go index d801701e5f..25a8acb1c1 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/generate.go @@ -1,3 +1,3 @@ -package testgen +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/objectassert/user_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go index f1a32c1eed..d3875a169b 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go @@ -1,6 +1,6 @@ // Code generated by sdk-to-schema generator; DO NOT EDIT. -package testgen +package objectassert import ( "fmt" diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go index cdc714ce73..b67f320636 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go @@ -1,6 +1,6 @@ // Code generated by sdk-to-schema generator; DO NOT EDIT. -package testgen +package objectassert import ( "fmt" diff --git a/pkg/acceptance/bettertestspoc/assert/user_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_snowflake.go deleted file mode 100644 index 30e30bd5b7..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/user_snowflake.go +++ /dev/null @@ -1,315 +0,0 @@ -package assert - -import ( - "fmt" - "testing" - "time" - - acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" -) - -type UserAssert struct { - *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), - } -} - -func UserFromObject(t *testing.T, user *sdk.User) *UserAssert { - t.Helper() - return &UserAssert{ - 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 { - t.Helper() - if o.Name != expected { - return fmt.Errorf("expected name: %v; got: %v", expected, o.Name) - } - return nil - }) - return w -} - -func (w *UserAssert) HasCreatedOn(expected time.Time) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasLoginName(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasDisplayName(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasFirstName(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasLastName(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasEmail(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasMinsToUnlock(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasDaysToExpiry(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasComment(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasDisabled(expected bool) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasMustChangePassword(expected bool) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasSnowflakeLock(expected bool) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasDefaultWarehouse(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasDefaultNamespace(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasDefaultRole(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasDefaultSecondaryRoles(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasExtAuthnDuo(expected bool) *UserAssert { - w.assertions = append(w.assertions, 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 nil - }) - return w -} - -func (w *UserAssert) HasExtAuthnUid(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasMinsToBypassMfa(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasOwner(expected string) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasLastSuccessLogin(expected time.Time) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasExpiresAtTime(expected time.Time) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasLockedUntilTime(expected time.Time) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasHasPassword(expected bool) *UserAssert { - w.assertions = append(w.assertions, 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 -} - -func (w *UserAssert) HasHasRsaPublicKey(expected bool) *UserAssert { - w.assertions = append(w.assertions, 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 -} diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index 4e4cad2a5f..324dd08487 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -4,8 +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/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,7 +49,7 @@ func TestInt_Users(t *testing.T) { t.Cleanup(networkPolicyCleanup) assertParametersSet := func(t *testing.T, id sdk.AccountObjectIdentifier) { - objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). + assertions.AssertThatObject(t, objectparametersassert.UserParameters(t, id). HasEnableUnredactedQuerySyntaxError(true). HasNetworkPolicy(networkPolicy.ID().Name()). HasPreventUnloadToInternalStages(true). @@ -152,7 +154,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)). @@ -199,7 +201,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)), @@ -224,7 +226,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()), @@ -273,7 +275,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 @@ -362,7 +364,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), ) }) @@ -381,7 +383,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), ) }) @@ -422,7 +424,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). @@ -528,7 +530,7 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). + assertions.AssertThatObject(t, assertions.UserParameters(t, id). HasAllDefaults(). HasAllDefaultsExplicit(), ) @@ -557,7 +559,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()), @@ -592,7 +594,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 @@ -649,7 +651,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()), @@ -817,7 +819,7 @@ func TestInt_Users(t *testing.T) { err = client.Users.Alter(ctx, id, alterOpts) require.NoError(t, err) - objectAssert.AssertThatObject(t, objectAssert.UserParameters(t, id). + assertions.AssertThatObject(t, assertions.UserParameters(t, id). HasAllDefaults(). HasAllDefaultsExplicit(), ) From 341001d7ad95af83097bab89256189e1cf401244 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 13:58:14 +0200 Subject: [PATCH 51/62] Add a quick workaround for user param --- .../assert/objectparametersassert/gen/commons.go | 9 +++++---- .../assert/objectparametersassert/gen/main/main.go | 5 ++++- .../assert/objectparametersassert/gen/model.go | 2 +- .../user_parameters_snowflake_gen.go | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go index 1df4ab3f8b..982f6daf90 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go @@ -3,10 +3,11 @@ package gen import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" type SnowflakeObjectParameters struct { - Name string - IdType string - Level sdk.ParameterType - Parameters []SnowflakeParameter + Name string + IdType string + Level sdk.ParameterType + AdditionalImports []string + Parameters []SnowflakeParameter } func (p SnowflakeObjectParameters) ObjectName() string { diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index f1aac5d98f..6cbbf1bd59 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -87,11 +87,14 @@ var allObjectsParameters = []gen.SnowflakeObjectParameters{ {string(sdk.UserParameterTransactionAbortOnError), "bool", "false", "sdk.ParameterTypeAccount"}, {string(sdk.UserParameterTransactionDefaultIsolationLevel), "sdk.TransactionDefaultIsolationLevel", "sdk.TransactionDefaultIsolationLevelReadCommitted", "sdk.ParameterTypeSnowflakeDefault"}, {string(sdk.UserParameterTwoDigitCenturyStart), "int", "1970", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterUnsupportedDdlAction), "sdk.UnsupportedDDLAction", "sdk.UnsupportedDDLActionIgnore", "sdk.ParameterTypeSnowflakeDefault"}, + // TODO: quick workaround for now: lowercase for ignore in snowflake by default but uppercase for FAIL + {string(sdk.UserParameterUnsupportedDdlAction), "sdk.UnsupportedDDLAction", "sdk.UnsupportedDDLAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore)))", "sdk.ParameterTypeSnowflakeDefault"}, {string(sdk.UserParameterUseCachedResult), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, {string(sdk.UserParameterWeekOfYearPolicy), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, {string(sdk.UserParameterWeekStart), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, }, + // for the quickfix above + AdditionalImports: []string{"strings"}, }, { Name: "Warehouse", diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go index 0517c32f8d..e3d5c54d33 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -71,7 +71,7 @@ func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjec Parameters: parameters, PreambleModel: PreambleModel{ PackageName: packageWithGenerateDirective, - AdditionalStandardImports: []string{}, + AdditionalStandardImports: snowflakeObjectParameters.AdditionalImports, }, } } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go index 1beba56a9a..b79c3eb1e5 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go @@ -3,6 +3,7 @@ package objectparametersassert import ( + "strings" "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" @@ -1234,7 +1235,7 @@ func (u *UserParametersAssert) HasDefaultTwoDigitCenturyStartValueExplicit() *Us } func (u *UserParametersAssert) HasDefaultUnsupportedDdlActionValueExplicit() *UserParametersAssert { - return u.HasUnsupportedDdlAction(sdk.UnsupportedDDLActionIgnore) + return u.HasUnsupportedDdlAction(sdk.UnsupportedDDLAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore)))) } func (u *UserParametersAssert) HasDefaultUseCachedResultValueExplicit() *UserParametersAssert { From 38b77ed7ad2d134597170fb5693e2d7c5f6f8aa8 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 14:00:01 +0200 Subject: [PATCH 52/62] Remove manually created user parameters --- .../assert/user_parameters_snowflake.go | 1248 ----------------- pkg/sdk/testint/users_integration_test.go | 6 +- 2 files changed, 3 insertions(+), 1251 deletions(-) delete mode 100644 pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go diff --git a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go b/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go deleted file mode 100644 index 1692145c97..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/user_parameters_snowflake.go +++ /dev/null @@ -1,1248 +0,0 @@ -package assert - -import ( - "strings" - "testing" - - acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" -) - -// TODO: make assertions naming consistent (resource paramaters vs snowflake parameters) -type UserParametersAssert struct { - *SnowflakeParametersAssert[sdk.AccountObjectIdentifier] -} - -func UserParameters(t *testing.T, id sdk.AccountObjectIdentifier) *UserParametersAssert { - t.Helper() - return &UserParametersAssert{ - NewSnowflakeParametersAssertWithProvider(id, sdk.ObjectTypeUser, acc.TestClient().Parameter.ShowUserParameters), - } -} - -func UserParametersPrefetched(t *testing.T, id sdk.AccountObjectIdentifier, parameters []*sdk.Parameter) *UserParametersAssert { - t.Helper() - return &UserParametersAssert{ - NewSnowflakeParametersAssertWithParameters(id, sdk.ObjectTypeUser, parameters), - } -} - -// TODO: try to move this section to SnowflakeParametersAssert to not copy it for every object; persist the type-safe assertions -////////////////////////////// -// Generic parameter checks // -////////////////////////////// - -func (w *UserParametersAssert) HasBoolParameterValue(parameterName sdk.UserParameter, expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(parameterName, expected)) - return w -} - -func (w *UserParametersAssert) HasIntParameterValue(parameterName sdk.UserParameter, expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(parameterName, expected)) - return w -} - -func (w *UserParametersAssert) HasStringParameterValue(parameterName sdk.UserParameter, expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(parameterName, expected)) - return w -} - -func (w *UserParametersAssert) HasDefaultParameterValue(parameterName sdk.UserParameter) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterDefaultValueSet(parameterName)) - return w -} - -func (w *UserParametersAssert) HasDefaultParameterValueOnLevel(parameterName sdk.UserParameter, parameterType sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, 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 *UserParametersAssert) HasAllDefaults() *UserParametersAssert { - return w. - 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.ParameterTypeAccount). - 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 (w *UserParametersAssert) HasAllDefaultsExplicit() *UserParametersAssert { - return w. - 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() -} - -/////////////////////////////// -// Specific parameter checks // -/////////////////////////////// - -// value checks - -func (w *UserParametersAssert) HasEnableUnredactedQuerySyntaxError(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) - return w -} - -func (w *UserParametersAssert) HasNetworkPolicy(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterNetworkPolicy, expected)) - return w -} - -func (w *UserParametersAssert) HasPreventUnloadToInternalStages(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) - return w -} - -func (w *UserParametersAssert) HasAbortDetachedQuery(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterAbortDetachedQuery, expected)) - return w -} - -func (w *UserParametersAssert) HasAutocommit(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterAutocommit, expected)) - return w -} - -func (w *UserParametersAssert) HasBinaryInputFormat(expected sdk.BinaryInputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryInputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasBinaryOutputFormat(expected sdk.BinaryOutputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterBinaryOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasClientMemoryLimit(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterClientMemoryLimit, expected)) - return w -} - -func (w *UserParametersAssert) HasClientMetadataRequestUseConnectionCtx(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) - return w -} - -func (w *UserParametersAssert) HasClientPrefetchThreads(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterClientPrefetchThreads, expected)) - return w -} - -func (w *UserParametersAssert) HasClientResultChunkSize(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterClientResultChunkSize, expected)) - return w -} - -func (w *UserParametersAssert) HasClientResultColumnCaseInsensitive(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) - return w -} - -func (w *UserParametersAssert) HasClientSessionKeepAlive(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterClientSessionKeepAlive, expected)) - return w -} - -func (w *UserParametersAssert) HasClientSessionKeepAliveHeartbeatFrequency(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) - return w -} - -func (w *UserParametersAssert) HasClientTimestampTypeMapping(expected sdk.ClientTimestampTypeMapping) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterClientTimestampTypeMapping, expected)) - return w -} - -func (w *UserParametersAssert) HasDateInputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterDateInputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasDateOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterDateOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasEnableUnloadPhysicalTypeOptimization(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) - return w -} - -func (w *UserParametersAssert) HasErrorOnNondeterministicMerge(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) - return w -} - -func (w *UserParametersAssert) HasErrorOnNondeterministicUpdate(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) - return w -} - -func (w *UserParametersAssert) HasGeographyOutputFormat(expected sdk.GeographyOutputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeographyOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasGeometryOutputFormat(expected sdk.GeometryOutputFormat) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterGeometryOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasJdbcTreatDecimalAsInt(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) - return w -} - -func (w *UserParametersAssert) HasJdbcTreatTimestampNtzAsUtc(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) - return w -} - -func (w *UserParametersAssert) HasJdbcUseSessionTimezone(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) - return w -} - -func (w *UserParametersAssert) HasJsonIndent(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterJsonIndent, expected)) - return w -} - -func (w *UserParametersAssert) HasLockTimeout(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterLockTimeout, expected)) - return w -} - -func (w *UserParametersAssert) HasLogLevel(expected sdk.LogLevel) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterLogLevel, expected)) - return w -} - -func (w *UserParametersAssert) HasMultiStatementCount(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterMultiStatementCount, expected)) - return w -} - -func (w *UserParametersAssert) HasNoorderSequenceAsDefault(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) - return w -} - -func (w *UserParametersAssert) HasOdbcTreatDecimalAsInt(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) - return w -} - -func (w *UserParametersAssert) HasQueryTag(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterQueryTag, expected)) - return w -} - -func (w *UserParametersAssert) HasQuotedIdentifiersIgnoreCase(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) - return w -} - -func (w *UserParametersAssert) HasRowsPerResultset(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterRowsPerResultset, expected)) - return w -} - -func (w *UserParametersAssert) HasS3StageVpceDnsName(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterS3StageVpceDnsName, expected)) - return w -} - -func (w *UserParametersAssert) HasSearchPath(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterSearchPath, expected)) - return w -} - -func (w *UserParametersAssert) HasSimulatedDataSharingConsumer(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) - return w -} - -func (w *UserParametersAssert) HasStatementQueuedTimeoutInSeconds(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) - return w -} - -func (w *UserParametersAssert) HasStatementTimeoutInSeconds(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) - return w -} - -func (w *UserParametersAssert) HasStrictJsonOutput(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterStrictJsonOutput, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampDayIsAlways24h(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampInputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampInputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampLtzOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampNtzOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampTypeMapping(expected sdk.TimestampTypeMapping) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTimestampTypeMapping, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampTzOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimestampTzOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimezone(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimezone, expected)) - return w -} - -func (w *UserParametersAssert) HasTimeInputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimeInputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimeOutputFormat(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterTimeOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTraceLevel(expected sdk.TraceLevel) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTraceLevel, expected)) - return w -} - -func (w *UserParametersAssert) HasTransactionAbortOnError(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterTransactionAbortOnError, expected)) - return w -} - -func (w *UserParametersAssert) HasTransactionDefaultIsolationLevel(expected sdk.TransactionDefaultIsolationLevel) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterStringUnderlyingValueSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) - return w -} - -func (w *UserParametersAssert) HasTwoDigitCenturyStart(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterTwoDigitCenturyStart, expected)) - return w -} - -// lowercase for ignore in snowflake by default but uppercase for FAIL -func (w *UserParametersAssert) HasUnsupportedDdlAction(expected string) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterValueSet(sdk.UserParameterUnsupportedDdlAction, expected)) - return w -} - -func (w *UserParametersAssert) HasUseCachedResult(expected bool) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterBoolValueSet(sdk.UserParameterUseCachedResult, expected)) - return w -} - -func (w *UserParametersAssert) HasWeekOfYearPolicy(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterWeekOfYearPolicy, expected)) - return w -} - -func (w *UserParametersAssert) HasWeekStart(expected int) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterIntValueSet(sdk.UserParameterWeekStart, expected)) - return w -} - -// level checks - -func (w *UserParametersAssert) HasEnableUnredactedQuerySyntaxErrorLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) - return w -} - -func (w *UserParametersAssert) HasNetworkPolicyLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterNetworkPolicy, expected)) - return w -} - -func (w *UserParametersAssert) HasPreventUnloadToInternalStagesLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) - return w -} - -func (w *UserParametersAssert) HasAbortDetachedQueryLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterAbortDetachedQuery, expected)) - return w -} - -func (w *UserParametersAssert) HasAutocommitLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterAutocommit, expected)) - return w -} - -func (w *UserParametersAssert) HasBinaryInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterBinaryInputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasBinaryOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterBinaryOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasClientMemoryLimitLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientMemoryLimit, expected)) - return w -} - -func (w *UserParametersAssert) HasClientMetadataRequestUseConnectionCtxLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) - return w -} - -func (w *UserParametersAssert) HasClientPrefetchThreadsLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientPrefetchThreads, expected)) - return w -} - -func (w *UserParametersAssert) HasClientResultChunkSizeLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientResultChunkSize, expected)) - return w -} - -func (w *UserParametersAssert) HasClientResultColumnCaseInsensitiveLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) - return w -} - -func (w *UserParametersAssert) HasClientSessionKeepAliveLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAlive, expected)) - return w -} - -func (w *UserParametersAssert) HasClientSessionKeepAliveHeartbeatFrequencyLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) - return w -} - -func (w *UserParametersAssert) HasClientTimestampTypeMappingLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterClientTimestampTypeMapping, expected)) - return w -} - -func (w *UserParametersAssert) HasDateInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterDateInputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasDateOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterDateOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasEnableUnloadPhysicalTypeOptimizationLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) - return w -} - -func (w *UserParametersAssert) HasErrorOnNondeterministicMergeLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) - return w -} - -func (w *UserParametersAssert) HasErrorOnNondeterministicUpdateLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) - return w -} - -func (w *UserParametersAssert) HasGeographyOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterGeographyOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasGeometryOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterGeometryOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasJdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) - return w -} - -func (w *UserParametersAssert) HasJdbcTreatTimestampNtzAsUtcLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) - return w -} - -func (w *UserParametersAssert) HasJdbcUseSessionTimezoneLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) - return w -} - -func (w *UserParametersAssert) HasJsonIndentLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterJsonIndent, expected)) - return w -} - -func (w *UserParametersAssert) HasLockTimeoutLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterLockTimeout, expected)) - return w -} - -func (w *UserParametersAssert) HasLogLevelLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterLogLevel, expected)) - return w -} - -func (w *UserParametersAssert) HasMultiStatementCountLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterMultiStatementCount, expected)) - return w -} - -func (w *UserParametersAssert) HasNoorderSequenceAsDefaultLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) - return w -} - -func (w *UserParametersAssert) HasOdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) - return w -} - -func (w *UserParametersAssert) HasQueryTagLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterQueryTag, expected)) - return w -} - -func (w *UserParametersAssert) HasQuotedIdentifiersIgnoreCaseLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) - return w -} - -func (w *UserParametersAssert) HasRowsPerResultsetLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterRowsPerResultset, expected)) - return w -} - -func (w *UserParametersAssert) HasS3StageVpceDnsNameLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterS3StageVpceDnsName, expected)) - return w -} - -func (w *UserParametersAssert) HasSearchPathLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterSearchPath, expected)) - return w -} - -func (w *UserParametersAssert) HasSimulatedDataSharingConsumerLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) - return w -} - -func (w *UserParametersAssert) HasStatementQueuedTimeoutInSecondsLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) - return w -} - -func (w *UserParametersAssert) HasStatementTimeoutInSecondsLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) - return w -} - -func (w *UserParametersAssert) HasStrictJsonOutputLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterStrictJsonOutput, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampDayIsAlways24hLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampInputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampLtzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampNtzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampTypeMappingLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampTypeMapping, expected)) - return w -} - -func (w *UserParametersAssert) HasTimestampTzOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimestampTzOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimezoneLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimezone, expected)) - return w -} - -func (w *UserParametersAssert) HasTimeInputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimeInputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTimeOutputFormatLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTimeOutputFormat, expected)) - return w -} - -func (w *UserParametersAssert) HasTraceLevelLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTraceLevel, expected)) - return w -} - -func (w *UserParametersAssert) HasTransactionAbortOnErrorLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTransactionAbortOnError, expected)) - return w -} - -func (w *UserParametersAssert) HasTransactionDefaultIsolationLevelLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) - return w -} - -func (w *UserParametersAssert) HasTwoDigitCenturyStartLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterTwoDigitCenturyStart, expected)) - return w -} - -func (w *UserParametersAssert) HasUnsupportedDdlActionLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterUnsupportedDdlAction, expected)) - return w -} - -func (w *UserParametersAssert) HasUseCachedResultLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterUseCachedResult, expected)) - return w -} - -func (w *UserParametersAssert) HasWeekOfYearPolicyLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterWeekOfYearPolicy, expected)) - return w -} - -func (w *UserParametersAssert) HasWeekStartLevel(expected sdk.ParameterType) *UserParametersAssert { - w.assertions = append(w.assertions, SnowflakeParameterLevelSet(sdk.UserParameterWeekStart, expected)) - return w -} - -// default checks - -func (w *UserParametersAssert) HasDefaultEnableUnredactedQuerySyntaxErrorValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterEnableUnredactedQuerySyntaxError) -} - -func (w *UserParametersAssert) HasDefaultNetworkPolicyValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterNetworkPolicy) -} - -func (w *UserParametersAssert) HasDefaultPreventUnloadToInternalStagesValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterPreventUnloadToInternalStages) -} - -func (w *UserParametersAssert) HasDefaultAbortDetachedQueryValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterAbortDetachedQuery) -} - -func (w *UserParametersAssert) HasDefaultAutocommitValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterAutocommit) -} - -func (w *UserParametersAssert) HasDefaultBinaryInputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterBinaryInputFormat) -} - -func (w *UserParametersAssert) HasDefaultBinaryOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterBinaryOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultClientMemoryLimitValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterClientMemoryLimit) -} - -func (w *UserParametersAssert) HasDefaultClientMetadataRequestUseConnectionCtxValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterClientMetadataRequestUseConnectionCtx) -} - -func (w *UserParametersAssert) HasDefaultClientPrefetchThreadsValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterClientPrefetchThreads) -} - -func (w *UserParametersAssert) HasDefaultClientResultChunkSizeValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterClientResultChunkSize) -} - -func (w *UserParametersAssert) HasDefaultClientResultColumnCaseInsensitiveValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterClientResultColumnCaseInsensitive) -} - -func (w *UserParametersAssert) HasDefaultClientSessionKeepAliveValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterClientSessionKeepAlive) -} - -func (w *UserParametersAssert) HasDefaultClientSessionKeepAliveHeartbeatFrequencyValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency) -} - -func (w *UserParametersAssert) HasDefaultClientTimestampTypeMappingValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterClientTimestampTypeMapping) -} - -func (w *UserParametersAssert) HasDefaultDateInputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterDateInputFormat) -} - -func (w *UserParametersAssert) HasDefaultDateOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterDateOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultEnableUnloadPhysicalTypeOptimizationValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterEnableUnloadPhysicalTypeOptimization) -} - -func (w *UserParametersAssert) HasDefaultErrorOnNondeterministicMergeValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterErrorOnNondeterministicMerge) -} - -func (w *UserParametersAssert) HasDefaultErrorOnNondeterministicUpdateValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterErrorOnNondeterministicUpdate) -} - -func (w *UserParametersAssert) HasDefaultGeographyOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterGeographyOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultGeometryOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterGeometryOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultJdbcTreatDecimalAsIntValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterJdbcTreatDecimalAsInt) -} - -func (w *UserParametersAssert) HasDefaultJdbcTreatTimestampNtzAsUtcValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterJdbcTreatTimestampNtzAsUtc) -} - -func (w *UserParametersAssert) HasDefaultJdbcUseSessionTimezoneValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterJdbcUseSessionTimezone) -} - -func (w *UserParametersAssert) HasDefaultJsonIndentValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterJsonIndent) -} - -func (w *UserParametersAssert) HasDefaultLockTimeoutValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterLockTimeout) -} - -func (w *UserParametersAssert) HasDefaultLogLevelValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterLogLevel) -} - -func (w *UserParametersAssert) HasDefaultMultiStatementCountValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterMultiStatementCount) -} - -func (w *UserParametersAssert) HasDefaultNoorderSequenceAsDefaultValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterNoorderSequenceAsDefault) -} - -func (w *UserParametersAssert) HasDefaultOdbcTreatDecimalAsIntValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterOdbcTreatDecimalAsInt) -} - -func (w *UserParametersAssert) HasDefaultQueryTagValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterQueryTag) -} - -func (w *UserParametersAssert) HasDefaultQuotedIdentifiersIgnoreCaseValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterQuotedIdentifiersIgnoreCase) -} - -func (w *UserParametersAssert) HasDefaultRowsPerResultsetValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterRowsPerResultset) -} - -func (w *UserParametersAssert) HasDefaultS3StageVpceDnsNameValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterS3StageVpceDnsName) -} - -func (w *UserParametersAssert) HasDefaultSearchPathValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterSearchPath) -} - -func (w *UserParametersAssert) HasDefaultSimulatedDataSharingConsumerValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterSimulatedDataSharingConsumer) -} - -func (w *UserParametersAssert) HasDefaultStatementQueuedTimeoutInSecondsValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterStatementQueuedTimeoutInSeconds) -} - -func (w *UserParametersAssert) HasDefaultStatementTimeoutInSecondsValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterStatementTimeoutInSeconds) -} - -func (w *UserParametersAssert) HasDefaultStrictJsonOutputValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterStrictJsonOutput) -} - -func (w *UserParametersAssert) HasDefaultTimestampDayIsAlways24hValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimestampDayIsAlways24h) -} - -func (w *UserParametersAssert) HasDefaultTimestampInputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimestampInputFormat) -} - -func (w *UserParametersAssert) HasDefaultTimestampLtzOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimestampLtzOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultTimestampNtzOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimestampNtzOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultTimestampOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimestampOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultTimestampTypeMappingValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimestampTypeMapping) -} - -func (w *UserParametersAssert) HasDefaultTimestampTzOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimestampTzOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultTimezoneValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimezone) -} - -func (w *UserParametersAssert) HasDefaultTimeInputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimeInputFormat) -} - -func (w *UserParametersAssert) HasDefaultTimeOutputFormatValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTimeOutputFormat) -} - -func (w *UserParametersAssert) HasDefaultTraceLevelValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTraceLevel) -} - -func (w *UserParametersAssert) HasDefaultTransactionAbortOnErrorValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTransactionAbortOnError) -} - -func (w *UserParametersAssert) HasDefaultTransactionDefaultIsolationLevelValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTransactionDefaultIsolationLevel) -} - -func (w *UserParametersAssert) HasDefaultTwoDigitCenturyStartValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterTwoDigitCenturyStart) -} - -func (w *UserParametersAssert) HasDefaultUnsupportedDdlActionValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterUnsupportedDdlAction) -} - -func (w *UserParametersAssert) HasDefaultUseCachedResultValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterUseCachedResult) -} - -func (w *UserParametersAssert) HasDefaultWeekOfYearPolicyValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterWeekOfYearPolicy) -} - -func (w *UserParametersAssert) HasDefaultWeekStartValue() *UserParametersAssert { - return w.HasDefaultParameterValue(sdk.UserParameterWeekStart) -} - -// default checks explicit - -func (w *UserParametersAssert) HasDefaultEnableUnredactedQuerySyntaxErrorValueExplicit() *UserParametersAssert { - return w.HasEnableUnredactedQuerySyntaxError(false) -} - -func (w *UserParametersAssert) HasDefaultNetworkPolicyValueExplicit() *UserParametersAssert { - return w.HasNetworkPolicy("") -} - -func (w *UserParametersAssert) HasDefaultPreventUnloadToInternalStagesValueExplicit() *UserParametersAssert { - return w.HasPreventUnloadToInternalStages(false) -} - -func (w *UserParametersAssert) HasDefaultAbortDetachedQueryValueExplicit() *UserParametersAssert { - return w.HasAbortDetachedQuery(false) -} - -func (w *UserParametersAssert) HasDefaultAutocommitValueExplicit() *UserParametersAssert { - return w.HasAutocommit(true) -} - -func (w *UserParametersAssert) HasDefaultBinaryInputFormatValueExplicit() *UserParametersAssert { - return w.HasBinaryInputFormat(sdk.BinaryInputFormatHex) -} - -func (w *UserParametersAssert) HasDefaultBinaryOutputFormatValueExplicit() *UserParametersAssert { - return w.HasBinaryOutputFormat(sdk.BinaryOutputFormatHex) -} - -func (w *UserParametersAssert) HasDefaultClientMemoryLimitValueExplicit() *UserParametersAssert { - return w.HasClientMemoryLimit(1536) -} - -func (w *UserParametersAssert) HasDefaultClientMetadataRequestUseConnectionCtxValueExplicit() *UserParametersAssert { - return w.HasClientMetadataRequestUseConnectionCtx(false) -} - -func (w *UserParametersAssert) HasDefaultClientPrefetchThreadsValueExplicit() *UserParametersAssert { - return w.HasClientPrefetchThreads(4) -} - -func (w *UserParametersAssert) HasDefaultClientResultChunkSizeValueExplicit() *UserParametersAssert { - return w.HasClientResultChunkSize(160) -} - -func (w *UserParametersAssert) HasDefaultClientResultColumnCaseInsensitiveValueExplicit() *UserParametersAssert { - return w.HasClientResultColumnCaseInsensitive(false) -} - -func (w *UserParametersAssert) HasDefaultClientSessionKeepAliveValueExplicit() *UserParametersAssert { - return w.HasClientSessionKeepAlive(false) -} - -func (w *UserParametersAssert) HasDefaultClientSessionKeepAliveHeartbeatFrequencyValueExplicit() *UserParametersAssert { - return w.HasClientSessionKeepAliveHeartbeatFrequency(3600) -} - -func (w *UserParametersAssert) HasDefaultClientTimestampTypeMappingValueExplicit() *UserParametersAssert { - return w.HasClientTimestampTypeMapping(sdk.ClientTimestampTypeMappingLtz) -} - -func (w *UserParametersAssert) HasDefaultDateInputFormatValueExplicit() *UserParametersAssert { - return w.HasDateInputFormat("AUTO") -} - -func (w *UserParametersAssert) HasDefaultDateOutputFormatValueExplicit() *UserParametersAssert { - return w.HasDateOutputFormat("YYYY-MM-DD") -} - -func (w *UserParametersAssert) HasDefaultEnableUnloadPhysicalTypeOptimizationValueExplicit() *UserParametersAssert { - return w.HasEnableUnloadPhysicalTypeOptimization(true) -} - -func (w *UserParametersAssert) HasDefaultErrorOnNondeterministicMergeValueExplicit() *UserParametersAssert { - return w.HasErrorOnNondeterministicMerge(true) -} - -func (w *UserParametersAssert) HasDefaultErrorOnNondeterministicUpdateValueExplicit() *UserParametersAssert { - return w.HasErrorOnNondeterministicUpdate(false) -} - -func (w *UserParametersAssert) HasDefaultGeographyOutputFormatValueExplicit() *UserParametersAssert { - return w.HasGeographyOutputFormat(sdk.GeographyOutputFormatGeoJSON) -} - -func (w *UserParametersAssert) HasDefaultGeometryOutputFormatValueExplicit() *UserParametersAssert { - return w.HasGeometryOutputFormat(sdk.GeometryOutputFormatGeoJSON) -} - -func (w *UserParametersAssert) HasDefaultJdbcTreatDecimalAsIntValueExplicit() *UserParametersAssert { - return w.HasJdbcTreatDecimalAsInt(true) -} - -func (w *UserParametersAssert) HasDefaultJdbcTreatTimestampNtzAsUtcValueExplicit() *UserParametersAssert { - return w.HasJdbcTreatTimestampNtzAsUtc(false) -} - -func (w *UserParametersAssert) HasDefaultJdbcUseSessionTimezoneValueExplicit() *UserParametersAssert { - return w.HasJdbcUseSessionTimezone(true) -} - -func (w *UserParametersAssert) HasDefaultJsonIndentValueExplicit() *UserParametersAssert { - return w.HasJsonIndent(2) -} - -func (w *UserParametersAssert) HasDefaultLockTimeoutValueExplicit() *UserParametersAssert { - return w.HasLockTimeout(43200) -} - -func (w *UserParametersAssert) HasDefaultLogLevelValueExplicit() *UserParametersAssert { - return w.HasLogLevel(sdk.LogLevelOff) -} - -func (w *UserParametersAssert) HasDefaultMultiStatementCountValueExplicit() *UserParametersAssert { - return w.HasMultiStatementCount(1) -} - -func (w *UserParametersAssert) HasDefaultNoorderSequenceAsDefaultValueExplicit() *UserParametersAssert { - return w.HasNoorderSequenceAsDefault(true) -} - -func (w *UserParametersAssert) HasDefaultOdbcTreatDecimalAsIntValueExplicit() *UserParametersAssert { - return w.HasOdbcTreatDecimalAsInt(false) -} - -func (w *UserParametersAssert) HasDefaultQueryTagValueExplicit() *UserParametersAssert { - return w.HasQueryTag("") -} - -func (w *UserParametersAssert) HasDefaultQuotedIdentifiersIgnoreCaseValueExplicit() *UserParametersAssert { - return w.HasQuotedIdentifiersIgnoreCase(false) -} - -func (w *UserParametersAssert) HasDefaultRowsPerResultsetValueExplicit() *UserParametersAssert { - return w.HasRowsPerResultset(0) -} - -func (w *UserParametersAssert) HasDefaultS3StageVpceDnsNameValueExplicit() *UserParametersAssert { - return w.HasS3StageVpceDnsName("") -} - -func (w *UserParametersAssert) HasDefaultSearchPathValueExplicit() *UserParametersAssert { - return w.HasSearchPath("$current, $public") -} - -func (w *UserParametersAssert) HasDefaultSimulatedDataSharingConsumerValueExplicit() *UserParametersAssert { - return w.HasSimulatedDataSharingConsumer("") -} - -func (w *UserParametersAssert) HasDefaultStatementQueuedTimeoutInSecondsValueExplicit() *UserParametersAssert { - return w.HasStatementQueuedTimeoutInSeconds(0) -} - -func (w *UserParametersAssert) HasDefaultStatementTimeoutInSecondsValueExplicit() *UserParametersAssert { - return w.HasStatementTimeoutInSeconds(172800) -} - -func (w *UserParametersAssert) HasDefaultStrictJsonOutputValueExplicit() *UserParametersAssert { - return w.HasStrictJsonOutput(false) -} - -func (w *UserParametersAssert) HasDefaultTimestampDayIsAlways24hValueExplicit() *UserParametersAssert { - return w.HasTimestampDayIsAlways24h(false) -} - -func (w *UserParametersAssert) HasDefaultTimestampInputFormatValueExplicit() *UserParametersAssert { - return w.HasTimestampInputFormat("AUTO") -} - -func (w *UserParametersAssert) HasDefaultTimestampLtzOutputFormatValueExplicit() *UserParametersAssert { - return w.HasTimestampLtzOutputFormat("") -} - -func (w *UserParametersAssert) HasDefaultTimestampNtzOutputFormatValueExplicit() *UserParametersAssert { - return w.HasTimestampNtzOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3") -} - -func (w *UserParametersAssert) HasDefaultTimestampOutputFormatValueExplicit() *UserParametersAssert { - return w.HasTimestampOutputFormat("YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM") -} - -func (w *UserParametersAssert) HasDefaultTimestampTypeMappingValueExplicit() *UserParametersAssert { - return w.HasTimestampTypeMapping(sdk.TimestampTypeMappingNtz) -} - -func (w *UserParametersAssert) HasDefaultTimestampTzOutputFormatValueExplicit() *UserParametersAssert { - return w.HasTimestampTzOutputFormat("") -} - -func (w *UserParametersAssert) HasDefaultTimezoneValueExplicit() *UserParametersAssert { - return w.HasTimezone("America/Los_Angeles") -} - -func (w *UserParametersAssert) HasDefaultTimeInputFormatValueExplicit() *UserParametersAssert { - return w.HasTimeInputFormat("AUTO") -} - -func (w *UserParametersAssert) HasDefaultTimeOutputFormatValueExplicit() *UserParametersAssert { - return w.HasTimeOutputFormat("HH24:MI:SS") -} - -func (w *UserParametersAssert) HasDefaultTraceLevelValueExplicit() *UserParametersAssert { - return w.HasTraceLevel(sdk.TraceLevelOff) -} - -func (w *UserParametersAssert) HasDefaultTransactionAbortOnErrorValueExplicit() *UserParametersAssert { - return w.HasTransactionAbortOnError(false) -} - -func (w *UserParametersAssert) HasDefaultTransactionDefaultIsolationLevelValueExplicit() *UserParametersAssert { - return w.HasTransactionDefaultIsolationLevel(sdk.TransactionDefaultIsolationLevelReadCommitted) -} - -func (w *UserParametersAssert) HasDefaultTwoDigitCenturyStartValueExplicit() *UserParametersAssert { - return w.HasTwoDigitCenturyStart(1970) -} - -// lowercase for ignore in snowflake by default but uppercase for FAIL -func (w *UserParametersAssert) HasDefaultUnsupportedDdlActionValueExplicit() *UserParametersAssert { - return w.HasUnsupportedDdlAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore))) -} - -func (w *UserParametersAssert) HasDefaultUseCachedResultValueExplicit() *UserParametersAssert { - return w.HasUseCachedResult(true) -} - -func (w *UserParametersAssert) HasDefaultWeekOfYearPolicyValueExplicit() *UserParametersAssert { - return w.HasWeekOfYearPolicy(0) -} - -func (w *UserParametersAssert) HasDefaultWeekStartValueExplicit() *UserParametersAssert { - return w.HasWeekStart(0) -} diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index 324dd08487..e0a8d92ed4 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -104,7 +104,7 @@ func TestInt_Users(t *testing.T) { HasTransactionAbortOnError(true). HasTransactionDefaultIsolationLevel(sdk.TransactionDefaultIsolationLevelReadCommitted). HasTwoDigitCenturyStart(1980). - HasUnsupportedDdlAction(string(sdk.UnsupportedDDLActionFail)). + HasUnsupportedDdlAction(sdk.UnsupportedDDLActionFail). HasUseCachedResult(false). HasWeekOfYearPolicy(1). HasWeekStart(1). @@ -530,7 +530,7 @@ func TestInt_Users(t *testing.T) { require.NoError(t, err) t.Cleanup(testClientHelper().User.DropUserFunc(t, id)) - assertions.AssertThatObject(t, assertions.UserParameters(t, id). + assertions.AssertThatObject(t, objectparametersassert.UserParameters(t, id). HasAllDefaults(). HasAllDefaultsExplicit(), ) @@ -819,7 +819,7 @@ func TestInt_Users(t *testing.T) { err = client.Users.Alter(ctx, id, alterOpts) require.NoError(t, err) - assertions.AssertThatObject(t, assertions.UserParameters(t, id). + assertions.AssertThatObject(t, objectparametersassert.UserParameters(t, id). HasAllDefaults(). HasAllDefaultsExplicit(), ) From f3c55f25e3da177dd102433441887d7f11361c49 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 14:15:08 +0200 Subject: [PATCH 53/62] Remove manually created warehouse object assertions --- .../assert/objectassert/gen/model.go | 11 ++ .../assert/objectassert/gen/templates.go | 1 + .../gen/templates/assertions.tmpl | 4 +- .../warehouse_snowflake_ext.go | 4 +- .../objectassert/warehouse_snowflake_gen.go | 4 +- .../assert/warehouse_snowflake.go | 171 ------------------ pkg/resources/warehouse_acceptance_test.go | 5 +- .../testint/warehouses_integration_test.go | 7 +- 8 files changed, 25 insertions(+), 182 deletions(-) rename pkg/acceptance/bettertestspoc/assert/{ => objectassert}/warehouse_snowflake_ext.go (79%) delete mode 100644 pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go index ca8618e9d2..9413f57597 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go @@ -30,6 +30,7 @@ type SnowflakeObjectFieldAssertion struct { Name string ConcreteType string IsOriginalTypePointer bool + Mapper gencommons.Mapper } func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeObjectAssertionsModel { @@ -64,9 +65,19 @@ func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeO } func MapToSnowflakeObjectFieldAssertion(field gencommons.Field) SnowflakeObjectFieldAssertion { + concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") + + // TODO: handle other mappings if needed + var mapper = gencommons.Identity + switch concreteTypeWithoutPtr { + case "sdk.AccountObjectIdentifier": + mapper = gencommons.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 index f73f0342e2..cf4c1fec6d 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go @@ -26,6 +26,7 @@ var ( gencommons.FirstLetter, gencommons.TypeWithoutPointer, gencommons.CamelToWords, + gencommons.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 index dd8e63b8c3..02f16fe624 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl @@ -13,8 +13,8 @@ return fmt.Errorf("expected {{ CamelToWords .Name }} to have value; got: nil") } {{ end -}} - if {{ if .IsOriginalTypePointer }}*{{ end }}o.{{ .Name }} != expected { - return fmt.Errorf("expected {{ CamelToWords .Name }}: %v; got: %v", expected, {{ if .IsOriginalTypePointer }}*{{ end }}o.{{ .Name }}) + 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 }) 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 index b67f320636..d90d75bb8b 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go @@ -298,8 +298,8 @@ func (w *WarehouseAssert) HasQueryAccelerationMaxScaleFactor(expected int) *Ware func (w *WarehouseAssert) HasResourceMonitor(expected sdk.AccountObjectIdentifier) *WarehouseAssert { w.AddAssertion(func(t *testing.T, o *sdk.Warehouse) error { t.Helper() - if o.ResourceMonitor != expected { - return fmt.Errorf("expected resource monitor: %v; got: %v", expected, o.ResourceMonitor) + if o.ResourceMonitor.Name() != expected.Name() { + return fmt.Errorf("expected resource monitor: %v; got: %v", expected.Name(), o.ResourceMonitor.Name()) } return nil }) diff --git a/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go b/pkg/acceptance/bettertestspoc/assert/warehouse_snowflake.go deleted file mode 100644 index 0fc601b563..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.AddAssertion(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/resources/warehouse_acceptance_test.go b/pkg/resources/warehouse_acceptance_test.go index 5536a39c5e..1666d60a36 100644 --- a/pkg/resources/warehouse_acceptance_test.go +++ b/pkg/resources/warehouse_acceptance_test.go @@ -11,6 +11,7 @@ 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/config" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/importchecks" @@ -96,7 +97,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). @@ -144,7 +145,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). 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). From 9646487f8c2b3e27e665183a027269f13e7eb791 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 14:30:45 +0200 Subject: [PATCH 54/62] Update readme --- pkg/acceptance/bettertestspoc/README.md | 73 ++++++++++--------------- 1 file changed, 28 insertions(+), 45 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/README.md b/pkg/acceptance/bettertestspoc/README.md index 68b698ea0c..72ff94443b 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). From 8c81ebbed60b038686dd41dcc764bfdd42a4493b Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 15:04:27 +0200 Subject: [PATCH 55/62] Add README to the generator commons --- pkg/internal/gencommons/README.md | 61 +++++++++++++++++++++ pkg/internal/gencommons/generator.go | 13 ++--- pkg/internal/gencommons/template_commons.go | 3 + pkg/internal/gencommons/util.go | 1 + pkg/schemas/gen/README.md | 9 ++- pkg/schemas/gen/main/main.go | 1 - 6 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 pkg/internal/gencommons/README.md diff --git a/pkg/internal/gencommons/README.md b/pkg/internal/gencommons/README.md new file mode 100644 index 0000000000..2f5f021921 --- /dev/null +++ b/pkg/internal/gencommons/README.md @@ -0,0 +1,61 @@ +## 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 +- `mapper_commons.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` +5By default, generator support the following command line flags (invokable with e.g. `make generate-show-output-schemas SF_TF_GENERATOR_ARGS='--dry-run additional-logs'`) + - `--dry-run` allowing to print the generated content to the command line instead of saving it to files + - `--additional-logs` 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`) diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index e5b623ad4d..b31aad8493 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -12,23 +12,21 @@ import ( "text/template" ) -// TODO: describe +// TODO [SNOW-1501905]: describe type ObjectNameProvider interface { ObjectName() string } -// TODO: describe -// TODO: use -// TODO: better func +// TODO [SNOW-1501905]: describe +// TODO [SNOW-1501905]: better func type GenerationModel interface { SomeFunc() } -// TODO: add erorrs to any of these functions? type Generator[T ObjectNameProvider, M GenerationModel] struct { objectsProvider func() []T modelProvider func(T) M - // TODO: add filename to model? + // TODO [SNOW-1501905]: consider adding filename to model? filenameProvider func(T, M) string templates []*template.Template @@ -64,7 +62,6 @@ func (g *Generator[T, _]) Run() error { file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) - // TODO: describe running with build flags: make generate-show-output-schemas SF_TF_GENERATOR_ARGS='--dry-run additional-logs' var additionalLogs = flag.Bool("additional-logs", false, "print additional object debug logs") var dryRun = flag.Bool("dry-run", false, "generate to std out instead of saving") flag.Parse() @@ -109,7 +106,7 @@ func (g *Generator[T, _]) Run() error { return nil } -// TODO: temporary hacky solution to allow easy passing multiple args from the make command +// TODO [SNOW-1501905]: temporary hacky solution to allow easy passing multiple args from the make command func preprocessArgs() { rest := os.Args[1:] newArgs := make([]string, 0) diff --git a/pkg/internal/gencommons/template_commons.go b/pkg/internal/gencommons/template_commons.go index 639306cdc7..9dfa838d5e 100644 --- a/pkg/internal/gencommons/template_commons.go +++ b/pkg/internal/gencommons/template_commons.go @@ -7,6 +7,9 @@ import ( "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:] } diff --git a/pkg/internal/gencommons/util.go b/pkg/internal/gencommons/util.go index 701604b281..7919818c7c 100644 --- a/pkg/internal/gencommons/util.go +++ b/pkg/internal/gencommons/util.go @@ -44,6 +44,7 @@ func ColumnOutput(columnWidth int, columns ...string) 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 { diff --git a/pkg/schemas/gen/README.md b/pkg/schemas/gen/README.md index 591dca2ecd..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,12 +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.: - (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 -- test the generator part and improve error handling (TODOs in [generator.go](./generator.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/main/main.go b/pkg/schemas/gen/main/main.go index 46a9b653ec..1ba24711c5 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -68,7 +68,6 @@ func printUniqueTypes(allStructs []gencommons.StructDetails) { } } -// TODO: describe filtering: make generate-show-output-schemas SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES="sdk.Warehouse,sdk.User" // TODO: move this filter to commons and consider extracting this as a command line param func filterByNameFromEnv(o gencommons.StructDetails) bool { allowedObjectNamesString := os.Getenv("SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES") From 7f7d4faa05450a93733883c59179143db32bdf8f Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 15:56:42 +0200 Subject: [PATCH 56/62] Run make pre-push --- .../assert/objectassert/gen/model.go | 8 ++- .../objectparametersassert/gen/model.go | 3 +- .../assert/snowflake_parameters_assertions.go | 5 -- pkg/internal/gencommons/generator.go | 4 +- pkg/internal/gencommons/template_commons.go | 2 +- pkg/schemas/gen/model.go | 1 - pkg/schemas/gen/schema_field_mapper_test.go | 54 +++++++++---------- pkg/sdk/testint/users_integration_test.go | 1 + 8 files changed, 35 insertions(+), 43 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go index 9413f57597..56a3018879 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go @@ -23,7 +23,6 @@ type SnowflakeObjectAssertionsModel struct { } func (m SnowflakeObjectAssertionsModel) SomeFunc() { - return } type SnowflakeObjectFieldAssertion struct { @@ -45,7 +44,7 @@ func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeO } } additionalImports := make([]string, 0) - for k, _ := range imports { + for k := range imports { if !slices.Contains([]string{"sdk"}, k) { additionalImports = append(additionalImports, k) } @@ -68,9 +67,8 @@ func MapToSnowflakeObjectFieldAssertion(field gencommons.Field) SnowflakeObjectF concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") // TODO: handle other mappings if needed - var mapper = gencommons.Identity - switch concreteTypeWithoutPtr { - case "sdk.AccountObjectIdentifier": + mapper := gencommons.Identity + if concreteTypeWithoutPtr == "sdk.AccountObjectIdentifier" { mapper = gencommons.Name } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go index e3d5c54d33..2be13acbd7 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -28,7 +28,6 @@ type ParameterAssertionModel struct { } func (m SnowflakeObjectParametersAssertionsModel) SomeFunc() { - return } func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjectParameters) SnowflakeObjectParametersAssertionsModel { @@ -49,7 +48,7 @@ func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjec assertionCreator = "SnowflakeParameterValueSet" } - var defaultValue = p.DefaultValue + 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) diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index db4b71d462..f05b1105f1 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -83,11 +83,6 @@ func SnowflakeParameterValueSet[T ~string](parameterName T, expected string) Sno return SnowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: expected} } -// TODO: can we just replace all above with this one? -func snowflakeParameterValueSetGeneric[T ~string, U bool | int | ~string](parameterName T, expected U) SnowflakeParameterAssertion { - return SnowflakeParameterAssertion{parameterName: string(parameterName), expectedValue: fmt.Sprintf("%s", expected)} -} - func SnowflakeParameterDefaultValueSet[T ~string](parameterName T) SnowflakeParameterAssertion { return SnowflakeParameterAssertion{parameterName: string(parameterName), assertionType: snowflakeParameterAssertionTypeDefaultValue} } diff --git a/pkg/internal/gencommons/generator.go b/pkg/internal/gencommons/generator.go index b31aad8493..5c8364fe74 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/gencommons/generator.go @@ -62,8 +62,8 @@ func (g *Generator[T, _]) Run() error { file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) - var additionalLogs = flag.Bool("additional-logs", false, "print additional object debug logs") - var dryRun = flag.Bool("dry-run", false, "generate to std out instead of saving") + additionalLogs := flag.Bool("additional-logs", false, "print additional object debug logs") + dryRun := flag.Bool("dry-run", false, "generate to std out instead of saving") flag.Parse() objects := g.objectsProvider() diff --git a/pkg/internal/gencommons/template_commons.go b/pkg/internal/gencommons/template_commons.go index 9dfa838d5e..b4ff71e787 100644 --- a/pkg/internal/gencommons/template_commons.go +++ b/pkg/internal/gencommons/template_commons.go @@ -45,7 +45,7 @@ func IsLastItem(itemIdx int, collectionLength int) bool { } func BuildTemplateFuncMap(funcs ...any) template.FuncMap { - var allFuncs = make(map[string]any) + allFuncs := make(map[string]any) for _, f := range funcs { allFuncs[getFunctionName(f)] = f } diff --git a/pkg/schemas/gen/model.go b/pkg/schemas/gen/model.go index 813a158a84..4a4849dc10 100644 --- a/pkg/schemas/gen/model.go +++ b/pkg/schemas/gen/model.go @@ -13,7 +13,6 @@ type ShowResultSchemaModel struct { } func (m ShowResultSchemaModel) SomeFunc() { - return } func ModelFromStructDetails(sdkStruct gencommons.StructDetails) ShowResultSchemaModel { diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go index 3581005fec..6f0b197e85 100644 --- a/pkg/schemas/gen/schema_field_mapper_test.go +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -22,111 +22,111 @@ func Test_MapToSchemaField(t *testing.T) { expected expectedValues }{ { - field: gencommons.Field{"unexportedString", "string", "string"}, + field: gencommons.Field{Name: "unexportedString", ConcreteType: "string", UnderlyingType: "string"}, expected: expectedValues{"unexported_string", schema.TypeString, false, gencommons.Identity}, }, { - field: gencommons.Field{"unexportedInt", "int", "int"}, + field: gencommons.Field{Name: "unexportedInt", ConcreteType: "int", UnderlyingType: "int"}, expected: expectedValues{"unexported_int", schema.TypeInt, false, gencommons.Identity}, }, { - field: gencommons.Field{"unexportedBool", "bool", "bool"}, + field: gencommons.Field{Name: "unexportedBool", ConcreteType: "bool", UnderlyingType: "bool"}, expected: expectedValues{"unexported_bool", schema.TypeBool, false, gencommons.Identity}, }, { - field: gencommons.Field{"unexportedFloat64", "float64", "float64"}, + field: gencommons.Field{Name: "unexportedFloat64", ConcreteType: "float64", UnderlyingType: "float64"}, expected: expectedValues{"unexported_float64", schema.TypeFloat, false, gencommons.Identity}, }, { - field: gencommons.Field{"unexportedStringPtr", "*string", "*string"}, + field: gencommons.Field{Name: "unexportedStringPtr", ConcreteType: "*string", UnderlyingType: "*string"}, expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, gencommons.Identity}, }, { - field: gencommons.Field{"unexportedIntPtr", "*int", "*int"}, + field: gencommons.Field{Name: "unexportedIntPtr", ConcreteType: "*int", UnderlyingType: "*int"}, expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, gencommons.Identity}, }, { - field: gencommons.Field{"unexportedBoolPtr", "*bool", "*bool"}, + field: gencommons.Field{Name: "unexportedBoolPtr", ConcreteType: "*bool", UnderlyingType: "*bool"}, expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, gencommons.Identity}, }, { - field: gencommons.Field{"unexportedFloat64Ptr", "*float64", "*float64"}, + field: gencommons.Field{Name: "unexportedFloat64Ptr", ConcreteType: "*float64", UnderlyingType: "*float64"}, expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, gencommons.Identity}, }, { - field: gencommons.Field{"unexportedTime", "time.Time", "struct"}, + field: gencommons.Field{Name: "unexportedTime", ConcreteType: "time.Time", UnderlyingType: "struct"}, expected: expectedValues{"unexported_time", schema.TypeString, false, gencommons.ToString}, }, { - field: gencommons.Field{"unexportedTimePtr", "*time.Time", "*struct"}, + field: gencommons.Field{Name: "unexportedTimePtr", ConcreteType: "*time.Time", UnderlyingType: "*struct"}, expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, gencommons.ToString}, }, { - field: gencommons.Field{"unexportedStringEnum", "sdk.WarehouseType", "string"}, + field: gencommons.Field{Name: "unexportedStringEnum", ConcreteType: "sdk.WarehouseType", UnderlyingType: "string"}, expected: expectedValues{"unexported_string_enum", schema.TypeString, false, gencommons.CastToString}, }, { - field: gencommons.Field{"unexportedStringEnumPtr", "*sdk.WarehouseType", "*string"}, + field: gencommons.Field{Name: "unexportedStringEnumPtr", ConcreteType: "*sdk.WarehouseType", UnderlyingType: "*string"}, expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, gencommons.CastToString}, }, { - field: gencommons.Field{"unexportedIntEnum", "sdk.ResourceMonitorLevel", "int"}, + field: gencommons.Field{Name: "unexportedIntEnum", ConcreteType: "sdk.ResourceMonitorLevel", UnderlyingType: "int"}, expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, gencommons.CastToInt}, }, { - field: gencommons.Field{"unexportedIntEnumPtr", "*sdk.ResourceMonitorLevel", "*int"}, + field: gencommons.Field{Name: "unexportedIntEnumPtr", ConcreteType: "*sdk.ResourceMonitorLevel", UnderlyingType: "*int"}, expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, gencommons.CastToInt}, }, { - field: gencommons.Field{"unexportedAccountIdentifier", "sdk.AccountIdentifier", "struct"}, + field: gencommons.Field{Name: "unexportedAccountIdentifier", ConcreteType: "sdk.AccountIdentifier", UnderlyingType: "struct"}, expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedExternalObjectIdentifier", "sdk.ExternalObjectIdentifier", "struct"}, + field: gencommons.Field{Name: "unexportedExternalObjectIdentifier", ConcreteType: "sdk.ExternalObjectIdentifier", UnderlyingType: "struct"}, expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedAccountObjectIdentifier", "sdk.AccountObjectIdentifier", "struct"}, + field: gencommons.Field{Name: "unexportedAccountObjectIdentifier", ConcreteType: "sdk.AccountObjectIdentifier", UnderlyingType: "struct"}, expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, gencommons.Name}, }, { - field: gencommons.Field{"unexportedDatabaseObjectIdentifier", "sdk.DatabaseObjectIdentifier", "struct"}, + field: gencommons.Field{Name: "unexportedDatabaseObjectIdentifier", ConcreteType: "sdk.DatabaseObjectIdentifier", UnderlyingType: "struct"}, expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedSchemaObjectIdentifier", "sdk.SchemaObjectIdentifier", "struct"}, + field: gencommons.Field{Name: "unexportedSchemaObjectIdentifier", ConcreteType: "sdk.SchemaObjectIdentifier", UnderlyingType: "struct"}, expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedTableColumnIdentifier", "sdk.TableColumnIdentifier", "struct"}, + field: gencommons.Field{Name: "unexportedTableColumnIdentifier", ConcreteType: "sdk.TableColumnIdentifier", UnderlyingType: "struct"}, expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedAccountIdentifierPtr", "*sdk.AccountIdentifier", "*struct"}, + field: gencommons.Field{Name: "unexportedAccountIdentifierPtr", ConcreteType: "*sdk.AccountIdentifier", UnderlyingType: "*struct"}, expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedExternalObjectIdentifierPtr", "*sdk.ExternalObjectIdentifier", "*struct"}, + field: gencommons.Field{Name: "unexportedExternalObjectIdentifierPtr", ConcreteType: "*sdk.ExternalObjectIdentifier", UnderlyingType: "*struct"}, expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedAccountObjectIdentifierPtr", "*sdk.AccountObjectIdentifier", "*struct"}, + field: gencommons.Field{Name: "unexportedAccountObjectIdentifierPtr", ConcreteType: "*sdk.AccountObjectIdentifier", UnderlyingType: "*struct"}, expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, gencommons.Name}, }, { - field: gencommons.Field{"unexportedDatabaseObjectIdentifierPtr", "*sdk.DatabaseObjectIdentifier", "*struct"}, + field: gencommons.Field{Name: "unexportedDatabaseObjectIdentifierPtr", ConcreteType: "*sdk.DatabaseObjectIdentifier", UnderlyingType: "*struct"}, expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedSchemaObjectIdentifierPtr", "*sdk.SchemaObjectIdentifier", "*struct"}, + field: gencommons.Field{Name: "unexportedSchemaObjectIdentifierPtr", ConcreteType: "*sdk.SchemaObjectIdentifier", UnderlyingType: "*struct"}, expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedTableColumnIdentifierPtr", "*sdk.TableColumnIdentifier", "*struct"}, + field: gencommons.Field{Name: "unexportedTableColumnIdentifierPtr", ConcreteType: "*sdk.TableColumnIdentifier", UnderlyingType: "*struct"}, expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, }, { - field: gencommons.Field{"unexportedInterface", "sdk.ObjectIdentifier", "interface"}, + field: gencommons.Field{Name: "unexportedInterface", ConcreteType: "sdk.ObjectIdentifier", UnderlyingType: "interface"}, expected: expectedValues{"unexported_interface", schema.TypeString, false, gencommons.FullyQualifiedName}, }, } diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index e0a8d92ed4..0c99018e25 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -49,6 +49,7 @@ func TestInt_Users(t *testing.T) { t.Cleanup(networkPolicyCleanup) assertParametersSet := func(t *testing.T, id sdk.AccountObjectIdentifier) { + t.Helper() assertions.AssertThatObject(t, objectparametersassert.UserParameters(t, id). HasEnableUnredactedQuerySyntaxError(true). HasNetworkPolicy(networkPolicy.ID().Name()). From bd561e9b8d5c73f3e72ff194f0a7bb8afc74319e Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 16:03:20 +0200 Subject: [PATCH 57/62] Add explicit field names --- .../objectparametersassert/gen/main/main.go | 122 +++++++++--------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index 6cbbf1bd59..a284924305 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -33,65 +33,65 @@ var allObjectsParameters = []gen.SnowflakeObjectParameters{ IdType: "sdk.AccountObjectIdentifier", Level: sdk.ParameterTypeUser, Parameters: []gen.SnowflakeParameter{ - {string(sdk.UserParameterEnableUnredactedQuerySyntaxError), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterNetworkPolicy), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterPreventUnloadToInternalStages), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterAbortDetachedQuery), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterAutocommit), "bool", "true", "sdk.ParameterTypeAccount"}, - {string(sdk.UserParameterBinaryInputFormat), "sdk.BinaryInputFormat", "sdk.BinaryInputFormatHex", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterBinaryOutputFormat), "sdk.BinaryOutputFormat", "sdk.BinaryOutputFormatHex", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterClientMemoryLimit), "int", "1536", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterClientMetadataRequestUseConnectionCtx), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterClientPrefetchThreads), "int", "4", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterClientResultChunkSize), "int", "160", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterClientResultColumnCaseInsensitive), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterClientSessionKeepAlive), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency), "int", "3600", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterClientTimestampTypeMapping), "sdk.ClientTimestampTypeMapping", "sdk.ClientTimestampTypeMappingLtz", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterDateInputFormat), "string", "AUTO", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterDateOutputFormat), "string", "YYYY-MM-DD", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterEnableUnloadPhysicalTypeOptimization), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterErrorOnNondeterministicMerge), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterErrorOnNondeterministicUpdate), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterGeographyOutputFormat), "sdk.GeographyOutputFormat", "sdk.GeographyOutputFormatGeoJSON", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterGeometryOutputFormat), "sdk.GeometryOutputFormat", "sdk.GeometryOutputFormatGeoJSON", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterJdbcTreatDecimalAsInt), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterJdbcTreatTimestampNtzAsUtc), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterJdbcUseSessionTimezone), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterJsonIndent), "int", "2", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterLockTimeout), "int", "43200", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterLogLevel), "sdk.LogLevel", "sdk.LogLevelOff", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterMultiStatementCount), "int", "1", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterNoorderSequenceAsDefault), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterOdbcTreatDecimalAsInt), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterQueryTag), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterQuotedIdentifiersIgnoreCase), "bool", "false", "sdk.ParameterTypeAccount"}, - {string(sdk.UserParameterRowsPerResultset), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterS3StageVpceDnsName), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterSearchPath), "string", "$current, $public", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterSimulatedDataSharingConsumer), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterStatementQueuedTimeoutInSeconds), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterStatementTimeoutInSeconds), "int", "172800", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterStrictJsonOutput), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimestampDayIsAlways24h), "bool", "false", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimestampInputFormat), "string", "AUTO", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimestampLtzOutputFormat), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimestampNtzOutputFormat), "string", "YYYY-MM-DD HH24:MI:SS.FF3", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimestampOutputFormat), "string", "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimestampTypeMapping), "sdk.TimestampTypeMapping", "sdk.TimestampTypeMappingNtz", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimestampTzOutputFormat), "string", "", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimezone), "string", "America/Los_Angeles", "sdk.ParameterTypeAccount"}, - {string(sdk.UserParameterTimeInputFormat), "string", "AUTO", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTimeOutputFormat), "string", "HH24:MI:SS", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTraceLevel), "sdk.TraceLevel", "sdk.TraceLevelOff", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTransactionAbortOnError), "bool", "false", "sdk.ParameterTypeAccount"}, - {string(sdk.UserParameterTransactionDefaultIsolationLevel), "sdk.TransactionDefaultIsolationLevel", "sdk.TransactionDefaultIsolationLevelReadCommitted", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterTwoDigitCenturyStart), "int", "1970", "sdk.ParameterTypeSnowflakeDefault"}, + {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.ParameterTypeAccount"}, + {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 - {string(sdk.UserParameterUnsupportedDdlAction), "sdk.UnsupportedDDLAction", "sdk.UnsupportedDDLAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore)))", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterUseCachedResult), "bool", "true", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterWeekOfYearPolicy), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.UserParameterWeekStart), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, + {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"}, @@ -101,9 +101,9 @@ var allObjectsParameters = []gen.SnowflakeObjectParameters{ IdType: "sdk.AccountObjectIdentifier", Level: sdk.ParameterTypeWarehouse, Parameters: []gen.SnowflakeParameter{ - {string(sdk.WarehouseParameterMaxConcurrencyLevel), "int", "8", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds), "int", "0", "sdk.ParameterTypeSnowflakeDefault"}, - {string(sdk.WarehouseParameterStatementTimeoutInSeconds), "int", "172800", "sdk.ParameterTypeSnowflakeDefault"}, + {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"}, }, }, } From edfddf2b5a0fdd6286e4328ee7f7be99043b3856 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 16:03:52 +0200 Subject: [PATCH 58/62] Use the generated assertions in warehouse acceptance tests --- .../assert/snowflake_parameters_assertions.go | 20 +++++++++++++++++++ pkg/resources/warehouse_acceptance_test.go | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index f05b1105f1..afd6ff816e 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -8,6 +8,8 @@ import ( "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" ) @@ -95,6 +97,24 @@ func SnowflakeParameterLevelSet[T ~string](parameterName T, parameterType sdk.Pa 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) { diff --git a/pkg/resources/warehouse_acceptance_test.go b/pkg/resources/warehouse_acceptance_test.go index 1666d60a36..6a045646bc 100644 --- a/pkg/resources/warehouse_acceptance_test.go +++ b/pkg/resources/warehouse_acceptance_test.go @@ -12,6 +12,7 @@ import ( "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" @@ -111,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())), ), @@ -159,6 +163,9 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { HasComment(comment). HasEnableQueryAcceleration(false). HasQueryAccelerationMaxScaleFactor(8), + objectparametersassert.WarehouseParameters(t, warehouseId). + HasAllDefaults(). + HasAllDefaultsExplicit(), ), }, // RENAME From 3015e4b2c5cd1b1d74bcad5e0acb3626af0ff272 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 22 Jul 2024 16:23:11 +0200 Subject: [PATCH 59/62] Update readme and TODOs --- pkg/acceptance/bettertestspoc/README.md | 4 ++++ .../bettertestspoc/assert/objectassert/gen/model.go | 4 ++-- .../assert/objectparametersassert/gen/main/main.go | 2 +- .../bettertestspoc/assert/objectparametersassert/gen/model.go | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/README.md b/pkg/acceptance/bettertestspoc/README.md index 72ff94443b..3ec94ca7f7 100644 --- a/pkg/acceptance/bettertestspoc/README.md +++ b/pkg/acceptance/bettertestspoc/README.md @@ -451,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/model.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go index 56a3018879..d6b896e9c1 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go @@ -8,7 +8,7 @@ import ( "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" ) -// TODO: extract to commons? +// TODO [SNOW-1501905]: extract to commons? type PreambleModel struct { PackageName string AdditionalStandardImports []string @@ -66,7 +66,7 @@ func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeO func MapToSnowflakeObjectFieldAssertion(field gencommons.Field) SnowflakeObjectFieldAssertion { concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") - // TODO: handle other mappings if needed + // TODO [SNOW-1501905]: handle other mappings if needed mapper := gencommons.Identity if concreteTypeWithoutPtr == "sdk.AccountObjectIdentifier" { mapper = gencommons.Name diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index a284924305..1a0afb9518 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -26,7 +26,7 @@ func getFilename(_ gen.SnowflakeObjectParameters, model gen.SnowflakeObjectParam return gencommons.ToSnakeCase(model.Name) + "_parameters_snowflake" + "_gen.go" } -// TODO: use SDK definition after parameters rework (+ preprocessing here) +// TODO [SNOW-1501905]: use SDK definition after parameters rework (+ preprocessing here) var allObjectsParameters = []gen.SnowflakeObjectParameters{ { Name: "User", diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go index 2be13acbd7..7607e798c1 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -6,7 +6,7 @@ import ( "strings" ) -// TODO: extract to commons? +// TODO [SNOW-1501905]: extract to commons? type PreambleModel struct { PackageName string AdditionalStandardImports []string @@ -33,7 +33,7 @@ func (m SnowflakeObjectParametersAssertionsModel) SomeFunc() { func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjectParameters) SnowflakeObjectParametersAssertionsModel { parameters := make([]ParameterAssertionModel, len(snowflakeObjectParameters.Parameters)) for idx, p := range snowflakeObjectParameters.Parameters { - // TODO: get a runtime name for the assertion creator + // TODO [SNOW-1501905]: get a runtime name for the assertion creator var assertionCreator string switch { case p.ParameterType == "bool": From b3582700d3ebf9a49082e703fda4754716979b5f Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jul 2024 08:21:08 +0200 Subject: [PATCH 60/62] Fix the tests --- .../assert/objectparametersassert/gen/main/main.go | 2 +- .../objectparametersassert/user_parameters_snowflake_gen.go | 2 +- pkg/internal/gencommons/struct_details_extractor_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index 1a0afb9518..dc4b99f437 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -80,7 +80,7 @@ var allObjectsParameters = []gen.SnowflakeObjectParameters{ {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.ParameterTypeAccount"}, + {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"}, diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go index b79c3eb1e5..a8e1727714 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go @@ -115,7 +115,7 @@ func (u *UserParametersAssert) HasAllDefaults() *UserParametersAssert { HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampOutputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampTypeMapping, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTimestampTzOutputFormat, sdk.ParameterTypeSnowflakeDefault). - HasDefaultParameterValueOnLevel(sdk.UserParameterTimezone, sdk.ParameterTypeAccount). + HasDefaultParameterValueOnLevel(sdk.UserParameterTimezone, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTimeInputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTimeOutputFormat, sdk.ParameterTypeSnowflakeDefault). HasDefaultParameterValueOnLevel(sdk.UserParameterTraceLevel, sdk.ParameterTypeSnowflakeDefault). diff --git a/pkg/internal/gencommons/struct_details_extractor_test.go b/pkg/internal/gencommons/struct_details_extractor_test.go index 84a7159762..c70c2314a7 100644 --- a/pkg/internal/gencommons/struct_details_extractor_test.go +++ b/pkg/internal/gencommons/struct_details_extractor_test.go @@ -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") From cef6917b6b32c75861078ad79c5434c97cb27792 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jul 2024 09:45:41 +0200 Subject: [PATCH 61/62] Run acceptance tests regardless of the integration tests result --- .github/workflows/tests.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 007af12b92..f994b9b86d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,7 +44,7 @@ jobs: run: mkdir $HOME/.snowflake && echo "${{ secrets.SNOWFLAKE_CONFIG_FILE }}" > $HOME/.snowflake/config - run: make test - if: steps.create_config.conclusion == 'success' + if: ${{ !cancelled() && steps.create_config.conclusion == 'success' }} env: SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT: ${{ secrets.SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT }} TEST_SF_TF_AWS_EXTERNAL_BUCKET_URL: ${{ secrets.TEST_SF_TF_AWS_EXTERNAL_BUCKET_URL }} @@ -57,14 +57,15 @@ jobs: TEST_SF_TF_GCS_EXTERNAL_BUCKET_URL: ${{ secrets.TEST_SF_TF_GCS_EXTERNAL_BUCKET_URL }} - name: Setup Terraform - if: steps.create_config.conclusion == 'success' + if: ${{ !cancelled() && steps.create_config.conclusion == 'success' }} uses: hashicorp/setup-terraform@v3 + id: setup_terraform with: terraform_version: 1.7.4 terraform_wrapper: false - run: make test-acceptance - if: steps.create_config.conclusion == 'success' + if: ${{ !cancelled() && steps.setup_terraform.conclusion == 'success' }} env: SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT: ${{ secrets.SNOWFLAKE_BUSINESS_CRITICAL_ACCOUNT }} TEST_SF_TF_AWS_EXTERNAL_BUCKET_URL: ${{ secrets.TEST_SF_TF_AWS_EXTERNAL_BUCKET_URL }} From 6e2b0343fb3ec471d1b019ffda5b9788965c5384 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jul 2024 10:32:59 +0200 Subject: [PATCH 62/62] Fix after review --- .../assert/objectassert/gen/main/main.go | 16 +-- .../assert/objectassert/gen/model.go | 12 +- .../assert/objectassert/gen/templates.go | 18 +-- .../gen/templates/assertions.tmpl | 26 ++-- .../gen/templates/definition.tmpl | 18 +-- .../objectassert/gen/templates/preamble.tmpl | 16 +-- .../objectparametersassert/gen/main/main.go | 6 +- .../objectparametersassert/gen/model.go | 1 + .../objectparametersassert/gen/templates.go | 26 ++-- .../templates/aggregated_generic_checks.tmpl | 16 +-- .../gen/templates/definition.tmpl | 18 +-- .../gen/templates/generic_checks.tmpl | 20 +-- .../gen/templates/preamble.tmpl | 14 +-- .../gen/templates/specific_checks.tmpl | 12 +- .../assert/snowflake_parameters_assertions.go | 2 +- .../{gencommons => genhelpers}/README.md | 7 +- .../{gencommons => genhelpers}/generator.go | 7 +- .../mappers.go} | 2 +- .../sdk_object_details.go | 2 +- .../struct_details_extractor.go | 2 +- .../struct_details_extractor_test.go | 2 +- .../template_commons.go | 2 +- .../{gencommons => genhelpers}/util.go | 2 +- .../{gencommons => genhelpers}/util_test.go | 2 +- pkg/schemas/gen/main/main.go | 21 ++-- pkg/schemas/gen/model.go | 4 +- pkg/schemas/gen/schema_field_mapper.go | 30 ++--- pkg/schemas/gen/schema_field_mapper_test.go | 116 +++++++++--------- pkg/schemas/gen/templates.go | 8 +- pkg/sdk/poc/main.go | 3 +- 30 files changed, 215 insertions(+), 216 deletions(-) rename pkg/internal/{gencommons => genhelpers}/README.md (90%) rename pkg/internal/{gencommons => genhelpers}/generator.go (96%) rename pkg/internal/{gencommons/mapper_commons.go => genhelpers/mappers.go} (96%) rename pkg/internal/{gencommons => genhelpers}/sdk_object_details.go (89%) rename pkg/internal/{gencommons => genhelpers}/struct_details_extractor.go (98%) rename pkg/internal/{gencommons => genhelpers}/struct_details_extractor_test.go (99%) rename pkg/internal/{gencommons => genhelpers}/template_commons.go (98%) rename pkg/internal/{gencommons => genhelpers}/util.go (99%) rename pkg/internal/{gencommons => genhelpers}/util_test.go (99%) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go index 01c031cde2..a9635a1bc7 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go @@ -4,12 +4,12 @@ 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/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" ) func main() { - gencommons.NewGenerator( + genhelpers.NewGenerator( getSdkObjectDetails, gen.ModelFromSdkObjectDetails, getFilename, @@ -24,11 +24,11 @@ type SdkObjectDef struct { objectStruct any } -func getSdkObjectDetails() []gencommons.SdkObjectDetails { - allSdkObjectsDetails := make([]gencommons.SdkObjectDetails, len(allStructs)) +func getSdkObjectDetails() []genhelpers.SdkObjectDetails { + allSdkObjectsDetails := make([]genhelpers.SdkObjectDetails, len(allStructs)) for idx, d := range allStructs { - structDetails := gencommons.ExtractStructDetails(d.objectStruct) - allSdkObjectsDetails[idx] = gencommons.SdkObjectDetails{ + structDetails := genhelpers.ExtractStructDetails(d.objectStruct) + allSdkObjectsDetails[idx] = genhelpers.SdkObjectDetails{ IdType: d.idType, ObjectType: d.objectType, StructDetails: structDetails, @@ -37,8 +37,8 @@ func getSdkObjectDetails() []gencommons.SdkObjectDetails { return allSdkObjectsDetails } -func getFilename(_ gencommons.SdkObjectDetails, model gen.SnowflakeObjectAssertionsModel) string { - return gencommons.ToSnakeCase(model.Name) + "_snowflake" + "_gen.go" +func getFilename(_ genhelpers.SdkObjectDetails, model gen.SnowflakeObjectAssertionsModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_snowflake" + "_gen.go" } var allStructs = []SdkObjectDef{ diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go index d6b896e9c1..a4de0d2846 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go @@ -5,7 +5,7 @@ import ( "slices" "strings" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" ) // TODO [SNOW-1501905]: extract to commons? @@ -29,10 +29,10 @@ type SnowflakeObjectFieldAssertion struct { Name string ConcreteType string IsOriginalTypePointer bool - Mapper gencommons.Mapper + Mapper genhelpers.Mapper } -func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeObjectAssertionsModel { +func ModelFromSdkObjectDetails(sdkObject genhelpers.SdkObjectDetails) SnowflakeObjectAssertionsModel { name, _ := strings.CutPrefix(sdkObject.Name, "sdk.") fields := make([]SnowflakeObjectFieldAssertion, len(sdkObject.Fields)) imports := make(map[string]struct{}) @@ -63,13 +63,13 @@ func ModelFromSdkObjectDetails(sdkObject gencommons.SdkObjectDetails) SnowflakeO } } -func MapToSnowflakeObjectFieldAssertion(field gencommons.Field) SnowflakeObjectFieldAssertion { +func MapToSnowflakeObjectFieldAssertion(field genhelpers.Field) SnowflakeObjectFieldAssertion { concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") // TODO [SNOW-1501905]: handle other mappings if needed - mapper := gencommons.Identity + mapper := genhelpers.Identity if concreteTypeWithoutPtr == "sdk.AccountObjectIdentifier" { - mapper = gencommons.Name + mapper = genhelpers.Name } return SnowflakeObjectFieldAssertion{ diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go index cf4c1fec6d..3309a84da8 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates.go @@ -5,7 +5,7 @@ import ( _ "embed" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" ) var ( @@ -15,18 +15,18 @@ var ( //go:embed templates/definition.tmpl definitionTemplateContent string - DefinitionTemplate, _ = template.New("definitionTemplate").Funcs(gencommons.BuildTemplateFuncMap( - gencommons.FirstLetterLowercase, + DefinitionTemplate, _ = template.New("definitionTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, )).Parse(definitionTemplateContent) //go:embed templates/assertions.tmpl assertionsTemplateContent string - AssertionsTemplate, _ = template.New("assertionsTemplate").Funcs(gencommons.BuildTemplateFuncMap( - gencommons.FirstLetterLowercase, - gencommons.FirstLetter, - gencommons.TypeWithoutPointer, - gencommons.CamelToWords, - gencommons.RunMapper, + 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 index 02f16fe624..d36caddcea 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/assertions.tmpl @@ -6,18 +6,18 @@ {{ $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 }} + {{ $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 index 9ed6b410d1..511a00cb46 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/definition.tmpl @@ -3,19 +3,19 @@ {{ $assertName := .Name | printf "%sAssert" }} {{ $nameLowerCase := FirstLetterLowercase .Name }} type {{ $assertName }} struct { -*assert.SnowflakeObjectAssert[{{ .SdkType }}, {{ .IdType }}] + *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), -} + 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 }}), -} + 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 index 6f604544ec..ac7011d57e 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl @@ -5,14 +5,14 @@ package {{ .PackageName }} import ( -"fmt" -"testing" -{{- range .AdditionalStandardImports }} -"{{- . }}" -{{- end }} + "fmt" + "testing" + {{- range .AdditionalStandardImports }} + "{{- . }}" + {{- end }} -acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + 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" + "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/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index dc4b99f437..b7073aeebb 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -4,12 +4,12 @@ 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/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" ) func main() { - gencommons.NewGenerator( + genhelpers.NewGenerator( getAllSnowflakeObjectParameters, gen.ModelFromSnowflakeObjectParameters, getFilename, @@ -23,7 +23,7 @@ func getAllSnowflakeObjectParameters() []gen.SnowflakeObjectParameters { } func getFilename(_ gen.SnowflakeObjectParameters, model gen.SnowflakeObjectParametersAssertionsModel) string { - return gencommons.ToSnakeCase(model.Name) + "_parameters_snowflake" + "_gen.go" + return genhelpers.ToSnakeCase(model.Name) + "_parameters_snowflake" + "_gen.go" } // TODO [SNOW-1501905]: use SDK definition after parameters rework (+ preprocessing here) diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go index 7607e798c1..a6053a4686 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/model.go @@ -44,6 +44,7 @@ func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters SnowflakeObjec assertionCreator = "SnowflakeParameterValueSet" case strings.HasPrefix(p.ParameterType, "sdk."): assertionCreator = "SnowflakeParameterStringUnderlyingValueSet" + // TODO [SNOW-1501905]: handle other types if needed default: assertionCreator = "SnowflakeParameterValueSet" } diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go index 3386e815fd..195ba47362 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates.go @@ -5,7 +5,7 @@ import ( _ "embed" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" ) var ( @@ -19,26 +19,26 @@ var ( //go:embed templates/generic_checks.tmpl genericChecksTemplateContent string - GenericChecksTemplate, _ = template.New("genericChecksTemplate").Funcs(gencommons.BuildTemplateFuncMap( - gencommons.FirstLetterLowercase, - gencommons.FirstLetter, + 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(gencommons.BuildTemplateFuncMap( - gencommons.FirstLetterLowercase, - gencommons.FirstLetter, - gencommons.SnakeCaseToCamel, - gencommons.IsLastItem, + 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(gencommons.BuildTemplateFuncMap( - gencommons.FirstLetterLowercase, - gencommons.FirstLetter, - gencommons.SnakeCaseToCamel, + 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 index e291c13ccf..4dded2f186 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/aggregated_generic_checks.tmpl @@ -13,15 +13,15 @@ // - 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 }} + 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 }} + 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 index a29e74c701..41f421bc19 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/definition.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/definition.tmpl @@ -2,19 +2,19 @@ {{ $assertName := .Name | printf "%sParametersAssert" }} type {{ $assertName }} struct { -*assert.SnowflakeParametersAssert[{{ .IdType }}] + *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), -} + 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), -} + 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 index a756e04a15..4fd4a771c4 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/generic_checks.tmpl @@ -9,26 +9,26 @@ ////////////////////////////// func ({{ $assertVar }} *{{ $assertName }}) HasBoolParameterValue(parameterName {{ $sdkParameterName }}, expected bool) *{{ $assertName }} { -{{ $assertVar }}.AddAssertion(assert.SnowflakeParameterBoolValueSet(parameterName, expected)) -return {{ $assertVar }} + {{ $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 }} + {{ $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 }} + {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterValueSet(parameterName, expected)) + return {{ $assertVar }} } func ({{ $assertVar }} *{{ $assertName }}) HasDefaultParameterValue(parameterName {{ $sdkParameterName }}) *{{ $assertName }} { -{{ $assertVar }}.AddAssertion(assert.SnowflakeParameterDefaultValueSet(parameterName)) -return {{ $assertVar }} + {{ $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 }} + {{ $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 index f03ab70821..4e8c6394a8 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl @@ -5,13 +5,13 @@ package {{ .PackageName }} import ( -"testing" -{{- range .AdditionalStandardImports }} -"{{- . }}" -{{- end }} + "testing" + {{- range .AdditionalStandardImports }} + "{{- . }}" + {{- end }} -acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + 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" + "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 index 152d5c9cc6..187c9e147d 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/specific_checks.tmpl @@ -10,8 +10,8 @@ {{ range .Parameters -}} func ({{ $assertVar }} *{{ $assertName }}) Has{{ SnakeCaseToCamel .Name }}(expected {{ .Type }}) *{{ $assertName }} { - {{ $assertVar }}.AddAssertion(assert.{{ .AssertionCreator }}({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}, expected)) - return {{ $assertVar }} + {{ $assertVar }}.AddAssertion(assert.{{ .AssertionCreator }}({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}, expected)) + return {{ $assertVar }} } {{ end -}} @@ -22,8 +22,8 @@ {{ range .Parameters -}} func ({{ $assertVar }} *{{ $assertName }}) Has{{ SnakeCaseToCamel .Name }}Level(expected sdk.ParameterType) *{{ $assertName }} { - {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterLevelSet({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}, expected)) - return {{ $assertVar }} + {{ $assertVar }}.AddAssertion(assert.SnowflakeParameterLevelSet({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}, expected)) + return {{ $assertVar }} } {{ end -}} @@ -34,7 +34,7 @@ {{ range .Parameters -}} func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}Value() *{{ $assertName }} { - return {{ $assertVar }}.HasDefaultParameterValue({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}) + return {{ $assertVar }}.HasDefaultParameterValue({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}) } {{ end -}} @@ -45,7 +45,7 @@ {{ range .Parameters -}} func ({{ $assertVar }} *{{ $assertName }}) HasDefault{{ SnakeCaseToCamel .Name }}ValueExplicit() *{{ $assertName }} { - return {{ $assertVar }}.Has{{ SnakeCaseToCamel .Name }}({{ .DefaultValue }}) + return {{ $assertVar }}.Has{{ SnakeCaseToCamel .Name }}({{ .DefaultValue }}) } {{ end }} diff --git a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go index afd6ff816e..665e449efe 100644 --- a/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/snowflake_parameters_assertions.go @@ -30,7 +30,7 @@ type SnowflakeParametersAssert[I sdk.ObjectIdentifier] struct { type snowflakeParameterAssertionType int const ( - snowflakeParameterAssertionTypeExpectedValue = iota + snowflakeParameterAssertionTypeExpectedValue snowflakeParameterAssertionType = iota snowflakeParameterAssertionTypeDefaultValue snowflakeParameterAssertionTypeDefaultValueOnLevel snowflakeParameterAssertionTypeLevel diff --git a/pkg/internal/gencommons/README.md b/pkg/internal/genhelpers/README.md similarity index 90% rename from pkg/internal/gencommons/README.md rename to pkg/internal/genhelpers/README.md index 2f5f021921..fc5c59672f 100644 --- a/pkg/internal/gencommons/README.md +++ b/pkg/internal/genhelpers/README.md @@ -6,7 +6,7 @@ Because we generate a bunch of code in the project, and we tend to copy-paste si The main building blocks of this package are: - `generator.go` defining `Generator[T ObjectNameProvider, M GenerationModel] struct` allowing to create new generators -- `mapper_commons.go` defining mappers that can be reused in the generated objects +- `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 @@ -35,9 +35,9 @@ To create a new generator: 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` -5By default, generator support the following command line flags (invokable with e.g. `make generate-show-output-schemas SF_TF_GENERATOR_ARGS='--dry-run additional-logs'`) +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 - - `--additional-logs` allowing to see the all the additional debug logs + - `--verbose` allowing to see the all the additional debug logs ### Next steps @@ -59,3 +59,4 @@ Implementation improvements: - 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/gencommons/generator.go b/pkg/internal/genhelpers/generator.go similarity index 96% rename from pkg/internal/gencommons/generator.go rename to pkg/internal/genhelpers/generator.go index 5c8364fe74..c3c4848290 100644 --- a/pkg/internal/gencommons/generator.go +++ b/pkg/internal/genhelpers/generator.go @@ -1,4 +1,4 @@ -package gencommons +package genhelpers import ( "bytes" @@ -62,7 +62,7 @@ func (g *Generator[T, _]) Run() error { file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) - additionalLogs := flag.Bool("additional-logs", false, "print additional object debug logs") + 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() @@ -109,8 +109,7 @@ func (g *Generator[T, _]) Run() error { // TODO [SNOW-1501905]: temporary hacky solution to allow easy passing multiple args from the make command func preprocessArgs() { rest := os.Args[1:] - newArgs := make([]string, 0) - newArgs = append(newArgs, os.Args[0]) + newArgs := []string{os.Args[0]} for _, a := range rest { newArgs = append(newArgs, strings.Split(a, " ")...) } diff --git a/pkg/internal/gencommons/mapper_commons.go b/pkg/internal/genhelpers/mappers.go similarity index 96% rename from pkg/internal/gencommons/mapper_commons.go rename to pkg/internal/genhelpers/mappers.go index a1a3d53d89..53f86e5521 100644 --- a/pkg/internal/gencommons/mapper_commons.go +++ b/pkg/internal/genhelpers/mappers.go @@ -1,4 +1,4 @@ -package gencommons +package genhelpers import "fmt" diff --git a/pkg/internal/gencommons/sdk_object_details.go b/pkg/internal/genhelpers/sdk_object_details.go similarity index 89% rename from pkg/internal/gencommons/sdk_object_details.go rename to pkg/internal/genhelpers/sdk_object_details.go index 1d43745004..5b2c879a38 100644 --- a/pkg/internal/gencommons/sdk_object_details.go +++ b/pkg/internal/genhelpers/sdk_object_details.go @@ -1,4 +1,4 @@ -package gencommons +package genhelpers import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" diff --git a/pkg/internal/gencommons/struct_details_extractor.go b/pkg/internal/genhelpers/struct_details_extractor.go similarity index 98% rename from pkg/internal/gencommons/struct_details_extractor.go rename to pkg/internal/genhelpers/struct_details_extractor.go index 50ac34d6cc..34ddf34ca7 100644 --- a/pkg/internal/gencommons/struct_details_extractor.go +++ b/pkg/internal/genhelpers/struct_details_extractor.go @@ -1,4 +1,4 @@ -package gencommons +package genhelpers import ( "reflect" diff --git a/pkg/internal/gencommons/struct_details_extractor_test.go b/pkg/internal/genhelpers/struct_details_extractor_test.go similarity index 99% rename from pkg/internal/gencommons/struct_details_extractor_test.go rename to pkg/internal/genhelpers/struct_details_extractor_test.go index c70c2314a7..b79c02cdca 100644 --- a/pkg/internal/gencommons/struct_details_extractor_test.go +++ b/pkg/internal/genhelpers/struct_details_extractor_test.go @@ -1,4 +1,4 @@ -package gencommons +package genhelpers import ( "testing" diff --git a/pkg/internal/gencommons/template_commons.go b/pkg/internal/genhelpers/template_commons.go similarity index 98% rename from pkg/internal/gencommons/template_commons.go rename to pkg/internal/genhelpers/template_commons.go index b4ff71e787..1480f1357f 100644 --- a/pkg/internal/gencommons/template_commons.go +++ b/pkg/internal/genhelpers/template_commons.go @@ -1,4 +1,4 @@ -package gencommons +package genhelpers import ( "reflect" diff --git a/pkg/internal/gencommons/util.go b/pkg/internal/genhelpers/util.go similarity index 99% rename from pkg/internal/gencommons/util.go rename to pkg/internal/genhelpers/util.go index 7919818c7c..65f402c1a9 100644 --- a/pkg/internal/gencommons/util.go +++ b/pkg/internal/genhelpers/util.go @@ -1,4 +1,4 @@ -package gencommons +package genhelpers import ( "bytes" diff --git a/pkg/internal/gencommons/util_test.go b/pkg/internal/genhelpers/util_test.go similarity index 99% rename from pkg/internal/gencommons/util_test.go rename to pkg/internal/genhelpers/util_test.go index 0c3720f2ed..fac58d7d21 100644 --- a/pkg/internal/gencommons/util_test.go +++ b/pkg/internal/genhelpers/util_test.go @@ -1,4 +1,4 @@ -package gencommons +package genhelpers import ( "fmt" diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 1ba24711c5..8f7978aa54 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -8,13 +8,12 @@ import ( "slices" "strings" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" "golang.org/x/exp/maps" ) func main() { - gencommons.NewGenerator( + genhelpers.NewGenerator( getStructDetails, gen.ModelFromStructDetails, getFilename, @@ -26,32 +25,32 @@ func main() { RunAndHandleOsReturn() } -func getStructDetails() []gencommons.StructDetails { +func getStructDetails() []genhelpers.StructDetails { allObjects := append(gen.SdkShowResultStructs, gen.AdditionalStructs...) - allStructsDetails := make([]gencommons.StructDetails, len(allObjects)) + allStructsDetails := make([]genhelpers.StructDetails, len(allObjects)) for idx, s := range allObjects { - allStructsDetails[idx] = gencommons.ExtractStructDetails(s) + allStructsDetails[idx] = genhelpers.ExtractStructDetails(s) } return allStructsDetails } -func getFilename(_ gencommons.StructDetails, model gen.ShowResultSchemaModel) string { - return gencommons.ToSnakeCase(model.Name) + "_gen.go" +func getFilename(_ genhelpers.StructDetails, model gen.ShowResultSchemaModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_gen.go" } -func printAllStructsFields(allStructs []gencommons.StructDetails) { +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(gencommons.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) + fmt.Println(genhelpers.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) } fmt.Println() } } -func printUniqueTypes(allStructs []gencommons.StructDetails) { +func printUniqueTypes(allStructs []genhelpers.StructDetails) { uniqueTypes := make(map[string]bool) for _, s := range allStructs { for _, f := range s.Fields { @@ -69,7 +68,7 @@ func printUniqueTypes(allStructs []gencommons.StructDetails) { } // TODO: move this filter to commons and consider extracting this as a command line param -func filterByNameFromEnv(o gencommons.StructDetails) bool { +func filterByNameFromEnv(o genhelpers.StructDetails) bool { allowedObjectNamesString := os.Getenv("SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES") if allowedObjectNamesString == "" { return true diff --git a/pkg/schemas/gen/model.go b/pkg/schemas/gen/model.go index 4a4849dc10..0a9d318380 100644 --- a/pkg/schemas/gen/model.go +++ b/pkg/schemas/gen/model.go @@ -3,7 +3,7 @@ package gen import ( "strings" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" ) type ShowResultSchemaModel struct { @@ -15,7 +15,7 @@ type ShowResultSchemaModel struct { func (m ShowResultSchemaModel) SomeFunc() { } -func ModelFromStructDetails(sdkStruct gencommons.StructDetails) ShowResultSchemaModel { +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 88c815ba51..be0d21af7d 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -3,7 +3,7 @@ package gen import ( "strings" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -12,44 +12,44 @@ type SchemaField struct { SchemaType schema.ValueType OriginalName string IsOriginalTypePointer bool - Mapper gencommons.Mapper + Mapper genhelpers.Mapper } // 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 gencommons.Field) SchemaField { +func MapToSchemaField(field genhelpers.Field) SchemaField { isPointer := field.IsPointer() concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") - name := gencommons.ToSnakeCase(field.Name) + name := genhelpers.ToSnakeCase(field.Name) switch concreteTypeWithoutPtr { case "string": - return SchemaField{name, schema.TypeString, field.Name, isPointer, gencommons.Identity} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.Identity} case "int": - return SchemaField{name, schema.TypeInt, field.Name, isPointer, gencommons.Identity} + return SchemaField{name, schema.TypeInt, field.Name, isPointer, genhelpers.Identity} case "float64": - return SchemaField{name, schema.TypeFloat, field.Name, isPointer, gencommons.Identity} + return SchemaField{name, schema.TypeFloat, field.Name, isPointer, genhelpers.Identity} case "bool": - return SchemaField{name, schema.TypeBool, field.Name, isPointer, gencommons.Identity} + return SchemaField{name, schema.TypeBool, field.Name, isPointer, genhelpers.Identity} case "time.Time": - return SchemaField{name, schema.TypeString, field.Name, isPointer, gencommons.ToString} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.ToString} case "sdk.AccountObjectIdentifier": - return SchemaField{name, schema.TypeString, field.Name, isPointer, gencommons.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, gencommons.FullyQualifiedName} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.FullyQualifiedName} case "sdk.ObjectIdentifier": - return SchemaField{name, schema.TypeString, field.Name, isPointer, gencommons.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, gencommons.CastToString} + return SchemaField{name, schema.TypeString, field.Name, isPointer, genhelpers.CastToString} case isSdkDeclaredObject && underlyingTypeWithoutPtr == "int": - return SchemaField{name, schema.TypeInt, field.Name, isPointer, gencommons.CastToInt} + return SchemaField{name, schema.TypeInt, field.Name, isPointer, genhelpers.CastToInt} } - return SchemaField{name, schema.TypeInvalid, field.Name, isPointer, gencommons.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 6f0b197e85..ec256154b9 100644 --- a/pkg/schemas/gen/schema_field_mapper_test.go +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" ) @@ -14,124 +14,124 @@ func Test_MapToSchemaField(t *testing.T) { name string schemaType schema.ValueType isPointer bool - mapper gencommons.Mapper + mapper genhelpers.Mapper } testCases := []struct { - field gencommons.Field + field genhelpers.Field expected expectedValues }{ { - field: gencommons.Field{Name: "unexportedString", ConcreteType: "string", UnderlyingType: "string"}, - expected: expectedValues{"unexported_string", schema.TypeString, false, gencommons.Identity}, + field: genhelpers.Field{Name: "unexportedString", ConcreteType: "string", UnderlyingType: "string"}, + expected: expectedValues{"unexported_string", schema.TypeString, false, genhelpers.Identity}, }, { - field: gencommons.Field{Name: "unexportedInt", ConcreteType: "int", UnderlyingType: "int"}, - expected: expectedValues{"unexported_int", schema.TypeInt, false, gencommons.Identity}, + field: genhelpers.Field{Name: "unexportedInt", ConcreteType: "int", UnderlyingType: "int"}, + expected: expectedValues{"unexported_int", schema.TypeInt, false, genhelpers.Identity}, }, { - field: gencommons.Field{Name: "unexportedBool", ConcreteType: "bool", UnderlyingType: "bool"}, - expected: expectedValues{"unexported_bool", schema.TypeBool, false, gencommons.Identity}, + field: genhelpers.Field{Name: "unexportedBool", ConcreteType: "bool", UnderlyingType: "bool"}, + expected: expectedValues{"unexported_bool", schema.TypeBool, false, genhelpers.Identity}, }, { - field: gencommons.Field{Name: "unexportedFloat64", ConcreteType: "float64", UnderlyingType: "float64"}, - expected: expectedValues{"unexported_float64", schema.TypeFloat, false, gencommons.Identity}, + field: genhelpers.Field{Name: "unexportedFloat64", ConcreteType: "float64", UnderlyingType: "float64"}, + expected: expectedValues{"unexported_float64", schema.TypeFloat, false, genhelpers.Identity}, }, { - field: gencommons.Field{Name: "unexportedStringPtr", ConcreteType: "*string", UnderlyingType: "*string"}, - expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, gencommons.Identity}, + field: genhelpers.Field{Name: "unexportedStringPtr", ConcreteType: "*string", UnderlyingType: "*string"}, + expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, genhelpers.Identity}, }, { - field: gencommons.Field{Name: "unexportedIntPtr", ConcreteType: "*int", UnderlyingType: "*int"}, - expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, gencommons.Identity}, + field: genhelpers.Field{Name: "unexportedIntPtr", ConcreteType: "*int", UnderlyingType: "*int"}, + expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, genhelpers.Identity}, }, { - field: gencommons.Field{Name: "unexportedBoolPtr", ConcreteType: "*bool", UnderlyingType: "*bool"}, - expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, gencommons.Identity}, + field: genhelpers.Field{Name: "unexportedBoolPtr", ConcreteType: "*bool", UnderlyingType: "*bool"}, + expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, genhelpers.Identity}, }, { - field: gencommons.Field{Name: "unexportedFloat64Ptr", ConcreteType: "*float64", UnderlyingType: "*float64"}, - expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, gencommons.Identity}, + field: genhelpers.Field{Name: "unexportedFloat64Ptr", ConcreteType: "*float64", UnderlyingType: "*float64"}, + expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, genhelpers.Identity}, }, { - field: gencommons.Field{Name: "unexportedTime", ConcreteType: "time.Time", UnderlyingType: "struct"}, - expected: expectedValues{"unexported_time", schema.TypeString, false, gencommons.ToString}, + field: genhelpers.Field{Name: "unexportedTime", ConcreteType: "time.Time", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_time", schema.TypeString, false, genhelpers.ToString}, }, { - field: gencommons.Field{Name: "unexportedTimePtr", ConcreteType: "*time.Time", UnderlyingType: "*struct"}, - expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, gencommons.ToString}, + field: genhelpers.Field{Name: "unexportedTimePtr", ConcreteType: "*time.Time", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, genhelpers.ToString}, }, { - field: gencommons.Field{Name: "unexportedStringEnum", ConcreteType: "sdk.WarehouseType", UnderlyingType: "string"}, - expected: expectedValues{"unexported_string_enum", schema.TypeString, false, gencommons.CastToString}, + field: genhelpers.Field{Name: "unexportedStringEnum", ConcreteType: "sdk.WarehouseType", UnderlyingType: "string"}, + expected: expectedValues{"unexported_string_enum", schema.TypeString, false, genhelpers.CastToString}, }, { - field: gencommons.Field{Name: "unexportedStringEnumPtr", ConcreteType: "*sdk.WarehouseType", UnderlyingType: "*string"}, - expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, gencommons.CastToString}, + field: genhelpers.Field{Name: "unexportedStringEnumPtr", ConcreteType: "*sdk.WarehouseType", UnderlyingType: "*string"}, + expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, genhelpers.CastToString}, }, { - field: gencommons.Field{Name: "unexportedIntEnum", ConcreteType: "sdk.ResourceMonitorLevel", UnderlyingType: "int"}, - expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, gencommons.CastToInt}, + field: genhelpers.Field{Name: "unexportedIntEnum", ConcreteType: "sdk.ResourceMonitorLevel", UnderlyingType: "int"}, + expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, genhelpers.CastToInt}, }, { - field: gencommons.Field{Name: "unexportedIntEnumPtr", ConcreteType: "*sdk.ResourceMonitorLevel", UnderlyingType: "*int"}, - expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, gencommons.CastToInt}, + field: genhelpers.Field{Name: "unexportedIntEnumPtr", ConcreteType: "*sdk.ResourceMonitorLevel", UnderlyingType: "*int"}, + expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, genhelpers.CastToInt}, }, { - field: gencommons.Field{Name: "unexportedAccountIdentifier", ConcreteType: "sdk.AccountIdentifier", UnderlyingType: "struct"}, - expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedAccountIdentifier", ConcreteType: "sdk.AccountIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedExternalObjectIdentifier", ConcreteType: "sdk.ExternalObjectIdentifier", UnderlyingType: "struct"}, - expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedExternalObjectIdentifier", ConcreteType: "sdk.ExternalObjectIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedAccountObjectIdentifier", ConcreteType: "sdk.AccountObjectIdentifier", UnderlyingType: "struct"}, - expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, gencommons.Name}, + field: genhelpers.Field{Name: "unexportedAccountObjectIdentifier", ConcreteType: "sdk.AccountObjectIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, genhelpers.Name}, }, { - field: gencommons.Field{Name: "unexportedDatabaseObjectIdentifier", ConcreteType: "sdk.DatabaseObjectIdentifier", UnderlyingType: "struct"}, - expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedDatabaseObjectIdentifier", ConcreteType: "sdk.DatabaseObjectIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedSchemaObjectIdentifier", ConcreteType: "sdk.SchemaObjectIdentifier", UnderlyingType: "struct"}, - expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedSchemaObjectIdentifier", ConcreteType: "sdk.SchemaObjectIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedTableColumnIdentifier", ConcreteType: "sdk.TableColumnIdentifier", UnderlyingType: "struct"}, - expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedTableColumnIdentifier", ConcreteType: "sdk.TableColumnIdentifier", UnderlyingType: "struct"}, + expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedAccountIdentifierPtr", ConcreteType: "*sdk.AccountIdentifier", UnderlyingType: "*struct"}, - expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedAccountIdentifierPtr", ConcreteType: "*sdk.AccountIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedExternalObjectIdentifierPtr", ConcreteType: "*sdk.ExternalObjectIdentifier", UnderlyingType: "*struct"}, - expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedExternalObjectIdentifierPtr", ConcreteType: "*sdk.ExternalObjectIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedAccountObjectIdentifierPtr", ConcreteType: "*sdk.AccountObjectIdentifier", UnderlyingType: "*struct"}, - expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, gencommons.Name}, + field: genhelpers.Field{Name: "unexportedAccountObjectIdentifierPtr", ConcreteType: "*sdk.AccountObjectIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, genhelpers.Name}, }, { - field: gencommons.Field{Name: "unexportedDatabaseObjectIdentifierPtr", ConcreteType: "*sdk.DatabaseObjectIdentifier", UnderlyingType: "*struct"}, - expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedDatabaseObjectIdentifierPtr", ConcreteType: "*sdk.DatabaseObjectIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedSchemaObjectIdentifierPtr", ConcreteType: "*sdk.SchemaObjectIdentifier", UnderlyingType: "*struct"}, - expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedSchemaObjectIdentifierPtr", ConcreteType: "*sdk.SchemaObjectIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedTableColumnIdentifierPtr", ConcreteType: "*sdk.TableColumnIdentifier", UnderlyingType: "*struct"}, - expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, gencommons.FullyQualifiedName}, + field: genhelpers.Field{Name: "unexportedTableColumnIdentifierPtr", ConcreteType: "*sdk.TableColumnIdentifier", UnderlyingType: "*struct"}, + expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, genhelpers.FullyQualifiedName}, }, { - field: gencommons.Field{Name: "unexportedInterface", ConcreteType: "sdk.ObjectIdentifier", UnderlyingType: "interface"}, - expected: expectedValues{"unexported_interface", schema.TypeString, false, gencommons.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 gencommons.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 e9a8105fbe..071ef8b630 100644 --- a/pkg/schemas/gen/templates.go +++ b/pkg/schemas/gen/templates.go @@ -5,7 +5,7 @@ import ( _ "embed" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" ) var ( @@ -19,9 +19,9 @@ var ( //go:embed templates/to_schema_mapper.tmpl toSchemaMapperTemplateContent string - ToSchemaMapperTemplate, _ = template.New("toSchemaMapperTemplate").Funcs(gencommons.BuildTemplateFuncMap( - gencommons.FirstLetterLowercase, - gencommons.RunMapper, + ToSchemaMapperTemplate, _ = template.New("toSchemaMapperTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.RunMapper, )).Parse(toSchemaMapperTemplateContent) AllTemplates = []*template.Template{PreambleTemplate, SchemaTemplate, ToSchemaMapperTemplate} diff --git a/pkg/sdk/poc/main.go b/pkg/sdk/poc/main.go index 5f89d414f3..ed5b340deb 100644 --- a/pkg/sdk/poc/main.go +++ b/pkg/sdk/poc/main.go @@ -10,7 +10,6 @@ import ( "os" "strings" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/gencommons" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/example" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator" @@ -104,7 +103,7 @@ 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) - if err := gencommons.WriteCodeToFile(&buffer, fileName); err != nil { + if err := genhelpers.WriteCodeToFile(&buffer, fileName); err != nil { log.Panicln(err) } }