From f715e8a990b72b62f87e526f7b30a7b6e9db5f19 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Thu, 25 Jul 2024 12:51:14 +0200 Subject: [PATCH] feat: Introduce assertions generators part2 (#2956) Continuation to https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/2952. Main features: - missing generators (4) added - definitions of generateable objects extracted to allow an easier reuse - common extractor for schemas added --- Makefile | 28 + pkg/acceptance/bettertestspoc/README.md | 526 ++++++--------- .../assert/objectassert/gen/main/main.go | 35 +- .../assert/objectassert/gen/model.go | 14 +- .../assert/objectassert/gen/sdk_object_def.go | 38 ++ .../objectassert/gen/templates/preamble.tmpl | 2 +- .../assert/objectassert/user_snowflake_gen.go | 2 +- .../objectassert/warehouse_snowflake_gen.go | 2 +- .../objectparametersassert/gen/commons.go | 22 - .../objectparametersassert/gen/main/main.go | 89 +-- .../gen/object_parameters_def.go | 108 +++ .../gen/templates/preamble.tmpl | 2 +- .../user_parameters_snowflake_gen.go | 2 +- .../warehouse_parameters_snowflake_gen.go | 2 +- .../assert/resource_assertions.go | 62 +- .../assert/resourceassert/gen/main/main.go | 22 + .../assert/resourceassert/gen/model.go | 52 ++ .../resourceassert/gen/resource_schema_def.go | 32 + .../assert/resourceassert/gen/templates.go | 29 + .../gen/templates/assertions.tmpl | 28 + .../gen/templates/definition.tmpl | 22 + .../gen/templates/preamble.tmpl | 14 + .../assert/resourceassert/generate.go | 3 + .../resourceassert/user_resource_gen.go | 207 ++++++ .../warehouse_resource_ext.go | 26 +- .../resourceassert/warehouse_resource_gen.go | 197 ++++++ .../resourceparametersassert/gen/main/main.go | 24 + .../resourceparametersassert/gen/model.go | 64 ++ .../resourceparametersassert/gen/templates.go | 32 + .../gen/templates/definition.tmpl | 28 + .../gen/templates/preamble.tmpl | 15 + .../gen/templates/specific_checks.tmpl | 29 + .../resourceparametersassert/generate.go | 3 + .../user_resource_parameters_gen.go | 622 ++++++++++++++++++ .../warehouse_parameters_ext.go | 19 + .../warehouse_resource_parameters_gen.go | 72 ++ .../resourceshowoutputassert/gen/main/main.go | 24 + .../resourceshowoutputassert/gen/model.go | 85 +++ .../resourceshowoutputassert/gen/templates.go | 33 + .../gen/templates/assertions.tmpl | 16 + .../gen/templates/definition.tmpl | 28 + .../gen/templates/preamble.tmpl | 18 + .../resourceshowoutputassert/generate.go | 3 + .../user_show_output_gen.go | 172 +++++ .../warehouse_show_output_gen.go | 177 +++++ .../assert/warehouse_parameters.go | 60 -- .../assert/warehouse_parameters_ext.go | 19 - .../assert/warehouse_resource.go | 185 ------ .../assert/warehouse_show_output.go | 85 --- .../bettertestspoc/config/config.go | 26 +- .../config/model/gen/main/main.go | 22 + .../bettertestspoc/config/model/gen/model.go | 75 +++ .../config/model/gen/templates.go | 33 + .../config/model/gen/templates/builders.tmpl | 34 + .../model/gen/templates/definition.tmpl | 45 ++ .../config/model/gen/templates/preamble.tmpl | 16 + .../bettertestspoc/config/model/generate.go | 3 + .../config/model/user_model_gen.go | 228 +++++++ .../config/model/warehouse_model_ext.go | 19 + .../config/model/warehouse_model_gen.go | 220 +++++++ .../bettertestspoc/config/warehouse_model.go | 221 ------- .../config/warehouse_model_ext.go | 8 - .../resource_schema_details_extractor.go | 46 ++ .../genhelpers/struct_details_extractor.go | 19 + .../struct_details_extractor_test.go | 2 +- pkg/internal/genhelpers/template_commons.go | 4 + pkg/resources/warehouse_acceptance_test.go | 70 +- 67 files changed, 3331 insertions(+), 1139 deletions(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/objectassert/gen/sdk_object_def.go delete mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go create mode 100644 pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/object_parameters_def.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/gen/main/main.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/gen/model.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/assertions.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/definition.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/preamble.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/generate.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/user_resource_gen.go rename pkg/acceptance/bettertestspoc/assert/{ => resourceassert}/warehouse_resource_ext.go (51%) create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/warehouse_resource_gen.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/main/main.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/model.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/definition.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/preamble.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/specific_checks.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/generate.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/user_resource_parameters_gen.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/warehouse_parameters_ext.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceparametersassert/warehouse_resource_parameters_gen.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/main/main.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/model.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/assertions.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/definition.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/preamble.tmpl create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/generate.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/user_show_output_gen.go create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/warehouse_show_output_gen.go delete mode 100644 pkg/acceptance/bettertestspoc/assert/warehouse_parameters.go delete mode 100644 pkg/acceptance/bettertestspoc/assert/warehouse_parameters_ext.go delete mode 100644 pkg/acceptance/bettertestspoc/assert/warehouse_resource.go delete mode 100644 pkg/acceptance/bettertestspoc/assert/warehouse_show_output.go create mode 100644 pkg/acceptance/bettertestspoc/config/model/gen/main/main.go create mode 100644 pkg/acceptance/bettertestspoc/config/model/gen/model.go create mode 100644 pkg/acceptance/bettertestspoc/config/model/gen/templates.go create mode 100644 pkg/acceptance/bettertestspoc/config/model/gen/templates/builders.tmpl create mode 100644 pkg/acceptance/bettertestspoc/config/model/gen/templates/definition.tmpl create mode 100644 pkg/acceptance/bettertestspoc/config/model/gen/templates/preamble.tmpl create mode 100644 pkg/acceptance/bettertestspoc/config/model/generate.go create mode 100644 pkg/acceptance/bettertestspoc/config/model/user_model_gen.go create mode 100644 pkg/acceptance/bettertestspoc/config/model/warehouse_model_ext.go create mode 100644 pkg/acceptance/bettertestspoc/config/model/warehouse_model_gen.go delete mode 100644 pkg/acceptance/bettertestspoc/config/warehouse_model.go delete mode 100644 pkg/acceptance/bettertestspoc/config/warehouse_model_ext.go create mode 100644 pkg/internal/genhelpers/resource_schema_details_extractor.go diff --git a/Makefile b/Makefile index 1e0504f5bd..de4149be2e 100644 --- a/Makefile +++ b/Makefile @@ -135,4 +135,32 @@ generate-snowflake-object-parameters-assertions: ## Generate snowflake object pa clean-snowflake-object-parameters-assertions: ## Clean snowflake object parameters assertions rm -f ./pkg/acceptance/bettertestspoc/assert/objectparametersassert/*_gen.go +generate-resource-assertions: ## Generate resource assertions + go generate ./pkg/acceptance/bettertestspoc/assert/resourceassert/generate.go + +clean-resource-assertions: ## Clean resource assertions + rm -f ./pkg/acceptance/bettertestspoc/assert/resourceassert/*_gen.go + +generate-resource-parameters-assertions: ## Generate resource parameters assertions + go generate ./pkg/acceptance/bettertestspoc/assert/resourceparametersassert/generate.go + +clean-resource-parameters-assertions: ## Clean resource parameters assertions + rm -f ./pkg/acceptance/bettertestspoc/assert/resourceparametersassert/*_gen.go + +generate-resource-show-output-assertions: ## Generate resource parameters assertions + go generate ./pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/generate.go + +clean-resource-show-output-assertions: ## Clean resource parameters assertions + rm -f ./pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/*_gen.go + +generate-resource-model-builders: ## Generate resource model builders + go generate ./pkg/acceptance/bettertestspoc/config/model/generate.go + +clean-resource-model-builder: ## Clean resource model builders + rm -f ./pkg/acceptance/bettertestspoc/config/model/*_gen.go + +clean-all-assertions-and-config-models: clean-snowflake-object-assertions clean-snowflake-object-parameters-assertions clean-resource-assertions clean-resource-parameters-assertions clean-resource-show-output-assertions clean-resource-model-builder ## clean all generated assertions and config models + +generate-all-assertions-and-config-models: generate-snowflake-object-assertions generate-snowflake-object-parameters-assertions generate-resource-assertions generate-resource-parameters-assertions generate-resource-show-output-assertions generate-resource-model-builders ## generate all assertions and config models + .PHONY: build-local clean-generator-poc dev-setup dev-cleanup docs docs-check fmt fmt-check fumpt help install lint lint-fix mod mod-check pre-push pre-push-check sweep test test-acceptance uninstall-tf diff --git a/pkg/acceptance/bettertestspoc/README.md b/pkg/acceptance/bettertestspoc/README.md index 3ec94ca7f7..da1038cd3f 100644 --- a/pkg/acceptance/bettertestspoc/README.md +++ b/pkg/acceptance/bettertestspoc/README.md @@ -1,28 +1,127 @@ # 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. 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) +- `assert` - all the assertions reside here. Also, the utilities to build assertions for new objects. All the current assertions are generated. The currently supported assertions are: - Snowflake object assertions (generated in subpackage `objectassert`) - Snowflake object parameters assertions (generated in subpackage `objectparametersassert`) + - resource assertions (generated in subpackage `resourceassert`) + - resource parameters assertions (generated in subpackage `resourceparametersassert`) + - show output assertions (generated in subpackage `resourceshowoutputassert`) -- `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. +- `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. The models are already generated. -## Usage +## How it works +### Adding new resource assertions +Resource assertions can be generated automatically. For object `abc` do the following: +- add object you want to generate to `allStructs` slice in the `assert/resourceassert/gen/resource_schema_def.go` +- to add custom (not generated assertions) create file `abc_resource_ext.go` in the `assert/resourceassert` package. Example would be: +```go +func (w *WarehouseResourceAssert) HasDefaultMaxConcurrencyLevel() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("max_concurrency_level", "8")) + return w +} +``` + +### Adding new resource show output assertions +Resource show output assertions can be generated automatically. For object `abc` do the following: +- add object you want to generate to `allResourceSchemaDefs` slice in the `assert/objectassert/gen/sdk_object_def.go` +- to add custom (not generated assertions) create file `abc_show_output_ext.go` in the `assert/resourceshowoutputassert` package. Example would be: +```go +func (u *UserShowOutputAssert) HasNameAndLoginName(expected string) *UserShowOutputAssert { + return u. + HasName(expected). + HasLoginName(expected) +} +``` + +### Adding new resource parameters assertions +Resource 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/object_parameters_def.go` +- to add custom (not generated assertions) create file `warehouse_resource_parameters_ext.go` in the `assert/resourceparametersassert` package. Example would be: +```go +func (w *WarehouseResourceParametersAssert) HasDefaultMaxConcurrencyLevel() *WarehouseResourceParametersAssert { + return w. + HasMaxConcurrencyLevel(8). + HasMaxConcurrencyLevelLevel("") +} +``` + +### Adding new Snowflake object assertions +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 { + t.Helper() + if !slices.Contains(expected, o.State) { + return fmt.Errorf("expected state one of: %v; got: %v", expected, string(o.State)) + } + return nil + }) + return w +} +``` + +### 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 +Resource config model builders can be generated automatically. For object `abc` do the following: +- add object you want to generate to `allResourceSchemaDefs` slice in the `assert/resourceassert/gen/resource_schema_def.go` +- to add custom (not generated) config builder methods create file `warehouse_model_ext` in the `config/model` package. Example would be: +```go +func BasicWarehouseModel( + name string, + comment string, +) *WarehouseModel { + return WarehouseWithDefaultMeta(name).WithComment(comment) +} + +func (w *WarehouseModel) WithWarehouseSizeEnum(warehouseSize sdk.WarehouseSize) *WarehouseModel { + return w.WithWarehouseSize(string(warehouseSize)) +} +``` + +### Running the generators +Each of the above assertion types/config models has its own generator and cleanup entry in our Makefile. +You can generate config models with: +```shell + make clean-resource-model-builder generate-resource-model-builder +``` + +You can use cli flags: +```shell + make clean-resource-model-builder generate-resource-model-builder SF_TF_GENERATOR_ARGS='--dry-run --verbose' +``` + +To clean/generate all from this package run +```shell + make clean-all-assertions-and-config-models generate-all-assertions-and-config-models +``` + +### Example usage in practice You can check the current example usage in `TestAcc_Warehouse_BasicFlows` and the `create: complete` inside `TestInt_Warehouses`. To see the output after invalid assertions: - add the following to the first step of `TestAcc_Warehouse_BasicFlows` ```go // bad checks below - assert.WarehouseResource(t, "snowflake_warehouse.w"). - HasType(string(sdk.WarehouseTypeSnowparkOptimized)). - HasSize(string(sdk.WarehouseSizeMedium)), - assert.WarehouseShowOutput(t, "snowflake_warehouse.w"). + resourceassert.WarehouseResource(t, "snowflake_warehouse.w"). + HasWarehouseTypeString(string(sdk.WarehouseTypeSnowparkOptimized)). + HasWarehouseSizeString(string(sdk.WarehouseSizeMedium)), + resourceshowoutputassert.WarehouseShowOutput(t, "snowflake_warehouse.w"). HasType(sdk.WarehouseTypeSnowparkOptimized), - assert.WarehouseParameters(t, "snowflake_warehouse.w"). + resourceparametersassert.WarehouseResourceParameters(t, "snowflake_warehouse.w"). HasMaxConcurrencyLevel(16). HasMaxConcurrencyLevelLevel(sdk.ParameterTypeWarehouse), objectassert.Warehouse(t, warehouseId). @@ -39,33 +138,37 @@ You can check the current example usage in `TestAcc_Warehouse_BasicFlows` and th HasComment("bad comment"). HasEnableQueryAcceleration(true). HasQueryAccelerationMaxScaleFactor(12), + objectparametersassert.WarehouseParameters(t, warehouseId). + HasMaxConcurrencyLevel(16), assert.Check(resource.TestCheckResourceAttr("snowflake_warehouse.w", "warehouse_type", string(sdk.WarehouseTypeSnowparkOptimized))), ``` it will result in: ``` - warehouse_acceptance_test.go:46: Step 1/8 error: Check failed: check 6/10 error: + warehouse_acceptance_test.go:51: Step 1/8 error: Check failed: check 7/12 error: snowflake_warehouse.w resource assertion [1/2]: failed with error: Attribute 'warehouse_type' not found snowflake_warehouse.w resource assertion [2/2]: failed with error: Attribute 'warehouse_size' not found - check 7/10 error: + check 8/12 error: snowflake_warehouse.w show_output assertion [2/2]: failed with error: Attribute 'show_output.0.type' expected "SNOWPARK-OPTIMIZED", got "STANDARD" - check 8/10 error: + check 9/12 error: snowflake_warehouse.w parameters assertion [2/3]: failed with error: Attribute 'parameters.0.max_concurrency_level.0.value' expected "16", got "8" snowflake_warehouse.w parameters assertion [3/3]: failed with error: Attribute 'parameters.0.max_concurrency_level.0.level' expected "WAREHOUSE", got "" - check 9/10 error: - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [1/13]: failed with error: expected name: bad name; got: URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7 - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [2/13]: failed with error: expected state: SUSPENDED; got: STARTED - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [3/13]: failed with error: expected type: SNOWPARK-OPTIMIZED; got: STANDARD - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [4/13]: failed with error: expected size: MEDIUM; got: XSMALL - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [5/13]: failed with error: expected max cluster count: 12; got: 1 - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [6/13]: failed with error: expected min cluster count: 13; got: 1 - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [7/13]: failed with error: expected type: ECONOMY; got: STANDARD - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [8/13]: failed with error: expected auto suspend: 123; got: 600 - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [9/13]: failed with error: expected auto resume: false; got: true - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [10/13]: failed with error: expected resource monitor: some-id; got: - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [11/13]: failed with error: expected comment: bad comment; got: From furthermore rarely cast anything those you could also whoever. - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [12/13]: failed with error: expected enable query acceleration: true; got: false - object WAREHOUSE["URVBDDAT_E7589B32_6534_1F93_DC1B_9E94FB8D27D7"] assertion [13/13]: failed with error: expected query acceleration max scale factor: 12; got: 8 - check 10/10 error: + check 10/12 error: + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [1/13]: failed with error: expected name: bad name; got: XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2 + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [2/13]: failed with error: expected state: SUSPENDED; got: STARTED + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [3/13]: failed with error: expected type: SNOWPARK-OPTIMIZED; got: STANDARD + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [4/13]: failed with error: expected size: MEDIUM; got: XSMALL + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [5/13]: failed with error: expected max cluster count: 12; got: 1 + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [6/13]: failed with error: expected min cluster count: 13; got: 1 + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [7/13]: failed with error: expected scaling policy: ECONOMY; got: STANDARD + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [8/13]: failed with error: expected auto suspend: 123; got: 600 + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [9/13]: failed with error: expected auto resume: false; got: true + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [10/13]: failed with error: expected resource monitor: some-id; got: + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [11/13]: failed with error: expected comment: bad comment; got: Who does encouraging eagerly annoying dream several their scold straightaway. + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [12/13]: failed with error: expected enable query acceleration: true; got: false + object WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"] assertion [13/13]: failed with error: expected query acceleration max scale factor: 12; got: 8 + check 11/12 error: + parameter assertion for WAREHOUSE["XHZJCKAT_35D0BCC1_7797_974E_ACAF_C622C56FA2D2"][MAX_CONCURRENCY_LEVEL][1/1] failed: expected value 16, got 8 + check 12/12 error: snowflake_warehouse.w: Attribute 'warehouse_type' not found ``` @@ -73,20 +176,20 @@ it will result in: ```go // bad checks below assert.CheckImport(importchecks.TestCheckResourceAttrInstanceState(warehouseId.Name(), "bad name", name)), - assert.ImportedWarehouseResource(t, warehouseId.Name()). - HasName("bad name"). - HasType(string(sdk.WarehouseTypeSnowparkOptimized)). - HasSize(string(sdk.WarehouseSizeMedium)). - HasMaxClusterCount("2"). - HasMinClusterCount("3"). - HasScalingPolicy(string(sdk.ScalingPolicyEconomy)). - HasAutoSuspend("123"). - HasAutoResume("false"). - HasResourceMonitor("abc"). - HasComment("bad comment"). - HasEnableQueryAcceleration("true"). - HasQueryAccelerationMaxScaleFactor("16"), - assert.ImportedWarehouseParameters(t, warehouseId.Name()). + resourceassert.ImportedWarehouseResource(t, warehouseId.Name()). + HasNameString("bad name"). + HasWarehouseTypeString(string(sdk.WarehouseTypeSnowparkOptimized)). + HasWarehouseSizeString(string(sdk.WarehouseSizeMedium)). + HasMaxClusterCountString("2"). + HasMinClusterCountString("3"). + HasScalingPolicyString(string(sdk.ScalingPolicyEconomy)). + HasAutoSuspendString("123"). + HasAutoResumeString("false"). + HasResourceMonitorString("abc"). + HasCommentString("bad comment"). + HasEnableQueryAccelerationString("true"). + HasQueryAccelerationMaxScaleFactorString("16"), + resourceparametersassert.ImportedWarehouseResourceParameters(t, warehouseId.Name()). HasMaxConcurrencyLevel(1). HasMaxConcurrencyLevelLevel(sdk.ParameterTypeWarehouse). HasStatementQueuedTimeoutInSeconds(23). @@ -107,45 +210,49 @@ it will result in: HasComment("bad comment"). HasEnableQueryAcceleration(true). HasQueryAccelerationMaxScaleFactor(12), + objectparametersassert.WarehouseParameters(t, warehouseId). + HasMaxConcurrencyLevel(1), ``` it will result in: ``` - warehouse_acceptance_test.go:46: check 6/9 error: + warehouse_acceptance_test.go:51: check 7/11 error: attribute bad name not found in instance state - check 7/9 error: - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [1/12]: failed with error: expected: bad name, got: RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [2/12]: failed with error: expected: SNOWPARK-OPTIMIZED, got: STANDARD - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [3/12]: failed with error: expected: MEDIUM, got: XSMALL - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [4/12]: failed with error: expected: 2, got: 1 - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [5/12]: failed with error: expected: 3, got: 1 - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [6/12]: failed with error: expected: ECONOMY, got: STANDARD - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [7/12]: failed with error: expected: 123, got: 600 - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [8/12]: failed with error: expected: false, got: true - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [9/12]: failed with error: expected: abc, got: - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [10/12]: failed with error: expected: bad comment, got: School huh one here entirely mustering where crew though wealth. - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [11/12]: failed with error: expected: true, got: false - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported resource assertion [12/12]: failed with error: expected: 16, got: 8 - check 8/9 error: - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported parameters assertion [2/7]: failed with error: expected: 1, got: 8 - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported parameters assertion [3/7]: failed with error: expected: WAREHOUSE, got: - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported parameters assertion [4/7]: failed with error: expected: 23, got: 0 - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported parameters assertion [5/7]: failed with error: expected: WAREHOUSE, got: - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported parameters assertion [6/7]: failed with error: expected: 1232, got: 172800 - RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 imported parameters assertion [7/7]: failed with error: expected: WAREHOUSE, got: - check 9/9 error: - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [1/13]: failed with error: expected name: bad name; got: RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844 - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [2/13]: failed with error: expected state: SUSPENDED; got: STARTED - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [3/13]: failed with error: expected type: SNOWPARK-OPTIMIZED; got: STANDARD - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [4/13]: failed with error: expected size: MEDIUM; got: XSMALL - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [5/13]: failed with error: expected max cluster count: 12; got: 1 - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [6/13]: failed with error: expected min cluster count: 13; got: 1 - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [7/13]: failed with error: expected type: ECONOMY; got: STANDARD - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [8/13]: failed with error: expected auto suspend: 123; got: 600 - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [9/13]: failed with error: expected auto resume: false; got: true - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [10/13]: failed with error: expected resource monitor: some-id; got: - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [11/13]: failed with error: expected comment: bad comment; got: School huh one here entirely mustering where crew though wealth. - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [12/13]: failed with error: expected enable query acceleration: true; got: false - object WAREHOUSE["RQYLJJAT_04646516_1F33_50E9_CC19_D6B14E374844"] assertion [13/13]: failed with error: expected query acceleration max scale factor: 12; got: 8 + check 8/11 error: + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [1/12]: failed with error: expected: bad name, got: WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [2/12]: failed with error: expected: SNOWPARK-OPTIMIZED, got: STANDARD + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [3/12]: failed with error: expected: MEDIUM, got: XSMALL + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [4/12]: failed with error: expected: 2, got: 1 + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [5/12]: failed with error: expected: 3, got: 1 + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [6/12]: failed with error: expected: ECONOMY, got: STANDARD + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [7/12]: failed with error: expected: 123, got: 600 + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [8/12]: failed with error: expected: false, got: true + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [9/12]: failed with error: expected: abc, got: + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [10/12]: failed with error: expected: bad comment, got: Promise my huh off certain you bravery dynasty with Roman. + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [11/12]: failed with error: expected: true, got: false + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported resource assertion [12/12]: failed with error: expected: 16, got: 8 + check 9/11 error: + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported parameters assertion [2/7]: failed with error: expected: 1, got: 8 + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported parameters assertion [3/7]: failed with error: expected: WAREHOUSE, got: + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported parameters assertion [4/7]: failed with error: expected: 23, got: 0 + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported parameters assertion [5/7]: failed with error: expected: WAREHOUSE, got: + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported parameters assertion [6/7]: failed with error: expected: 1232, got: 172800 + WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 imported parameters assertion [7/7]: failed with error: expected: WAREHOUSE, got: + check 10/11 error: + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [1/13]: failed with error: expected name: bad name; got: WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65 + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [2/13]: failed with error: expected state: SUSPENDED; got: STARTED + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [3/13]: failed with error: expected type: SNOWPARK-OPTIMIZED; got: STANDARD + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [4/13]: failed with error: expected size: MEDIUM; got: XSMALL + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [5/13]: failed with error: expected max cluster count: 12; got: 1 + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [6/13]: failed with error: expected min cluster count: 13; got: 1 + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [7/13]: failed with error: expected scaling policy: ECONOMY; got: STANDARD + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [8/13]: failed with error: expected auto suspend: 123; got: 600 + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [9/13]: failed with error: expected auto resume: false; got: true + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [10/13]: failed with error: expected resource monitor: some-id; got: + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [11/13]: failed with error: expected comment: bad comment; got: Promise my huh off certain you bravery dynasty with Roman. + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [12/13]: failed with error: expected enable query acceleration: true; got: false + object WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"] assertion [13/13]: failed with error: expected query acceleration max scale factor: 12; got: 8 + check 11/11 error: + parameter assertion for WAREHOUSE["WBJKHLAT_2E52D1E6_D23D_33A0_F568_4EBDBE083B65"][MAX_CONCURRENCY_LEVEL][1/1] failed: expected value 1, got 8 ``` - add the following to the `create: complete` in `TestInt_Warehouses`: @@ -188,256 +295,14 @@ it will result in: Test: TestInt_Warehouses/create:_complete ``` -## Adding new resource assertions -For object `abc` create the following files with the described content in the `assert` package: -- `abc_resource.go` -```go -type AbcResourceAssert struct { - *ResourceAssert -} - -func AbcResource(t *testing.T, name string) *AbcResourceAssert { - t.Helper() - - return &AbcResourceAssert{ - ResourceAssert: NewResourceAssert(name, "resource"), - } -} - -func ImportedAbcResource(t *testing.T, id string) *AbcResourceAssert { - t.Helper() - - return &AbcResourceAssert{ - ResourceAssert: NewImportedResourceAssert(id, "imported resource"), - } -} -``` -Two methods for each parameter (let's say parameter name is xyz): -```go -func (w *AbcResourceAssert) HasXyz(expected string) *AbcResourceAssert { - w.assertions = append(w.assertions, valueSet("xyz", expected)) - return w -} - -func (w *AbcResourceAssert) HasNoXyz() *AbcResourceAssert { - w.assertions = append(w.assertions, valueNotSet("xyz")) - return w -} -``` - -- `abc_show_output.go` -```go -type AbcShowOutputAssert struct { - *ResourceAssert -} - -func AbcShowOutput(t *testing.T, name string) *AbcShowOutputAssert { - t.Helper() - w := AbcShowOutputAssert{ - NewResourceAssert(name, "show_output"), - } - w.assertions = append(w.assertions, valueSet("show_output.#", "1")) - return &w -} - -func ImportedAbcShowOutput(t *testing.T, id string) *AbcShowOutputAssert { - t.Helper() - w := AbcShowOutputAssert{ - NewImportedResourceAssert(id, "show_output"), - } - w.assertions = append(w.assertions, valueSet("show_output.#", "1")) - return &w -} -``` - -A method for each parameter (let's say parameter name is xyz): -```go -func (w *AbcShowOutputAssert) HasXyz(expected string) *AbcShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("xyz", string(expected))) - return w -} -``` - -- `abc_parameters.go` -```go -type AbcParametersAssert struct { - *ResourceAssert -} - -func AbcParameters(t *testing.T, name string) *AbcParametersAssert { - t.Helper() - w := AbcParametersAssert{ - NewResourceAssert(name, "parameters"), - } - w.assertions = append(w.assertions, valueSet("parameters.#", "1")) - return &w -} - -func ImportedAbcParameters(t *testing.T, id string) *AbcParametersAssert { - t.Helper() - w := AbcParametersAssert{ - NewImportedResourceAssert(id, "imported parameters"), - } - w.assertions = append(w.assertions, valueSet("parameters.#", "1")) - return &w -} -``` -Two methods for each parameter (let's say parameter name is xyz): -```go -func (w *AbcParametersAssert) HasXyz(expected int) *AbcParametersAssert { - w.assertions = append(w.assertions, parameterValueSet("xyz", strconv.Itoa(expected))) - return w -} - -func (w *AbcParametersAssert) HasXyzLevel(expected sdk.ParameterType) *AbcParametersAssert { - w.assertions = append(w.assertions, parameterLevelSet("xyz", string(expected))) - return w -} -``` -- extensions should be put in `abc_resource_ext.go`, `abc_show_output_ext.go`, or `abc_parameters_ext.go`. We can put here the named aggregations of other assertions. It allows us extendability. Later, we may choose to generate some of these methods too. Currently, the split will help when we start the generation of aforementioned methods. Current examples for extension could be: -```go -func (w *WarehouseResourceAssert) HasDefaultMaxConcurrencyLevel() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("max_concurrency_level", "8")) - return w -} - -func (w *WarehouseResourceAssert) HasDefaultStatementQueuedTimeoutInSeconds() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("statement_queued_timeout_in_seconds", "0")) - return w -} - -func (w *WarehouseResourceAssert) HasDefaultStatementTimeoutInSeconds() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("statement_timeout_in_seconds", "172800")) - return w -} - -func (w *WarehouseResourceAssert) HasAllDefault() *WarehouseResourceAssert { - return w.HasDefaultMaxConcurrencyLevel(). - HasNoType(). - HasNoSize(). - HasNoMaxClusterCount(). - HasNoMinClusterCount(). - HasNoScalingPolicy(). - HasAutoSuspend(r.IntDefaultString). - HasAutoResume(r.BooleanDefault). - HasNoInitiallySuspended(). - HasNoResourceMonitor(). - HasEnableQueryAcceleration(r.BooleanDefault). - HasQueryAccelerationMaxScaleFactor(r.IntDefaultString). - HasDefaultMaxConcurrencyLevel(). - HasDefaultStatementQueuedTimeoutInSeconds(). - HasDefaultStatementTimeoutInSeconds() -} - -func (w *WarehouseParametersAssert) HasDefaultMaxConcurrencyLevel() *WarehouseParametersAssert { - return w. - HasMaxConcurrencyLevel(8). - HasMaxConcurrencyLevelLevel("") -} - -func (w *WarehouseParametersAssert) HasDefaultStatementQueuedTimeoutInSeconds() *WarehouseParametersAssert { - return w. - HasStatementQueuedTimeoutInSeconds(0). - HasStatementQueuedTimeoutInSecondsLevel("") -} - -func (w *WarehouseParametersAssert) HasDefaultStatementTimeoutInSeconds() *WarehouseParametersAssert { - return w. - HasStatementTimeoutInSeconds(172800). - HasStatementTimeoutInSecondsLevel("") -} -``` - -## Adding new Snowflake object assertions -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 { - t.Helper() - if !slices.Contains(expected, o.State) { - return fmt.Errorf("expected state one of: %v; got: %v", expected, string(o.State)) - } - return nil - }) - return w -} -``` - -## 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` -```go -type AbcModel struct { - Xyz config.Variable `json:"xyz,omitempty"` - *resourceModelMeta -} -``` -two builders with required params only: -```go -func NewAbcModel( - resourceName string, - xyz string, -) *AbcModel { - m := &AbcModel{resourceModelMeta: meta(resourceName, resources.Abc)} - m.WithXyz(xyz) - return m -} - -func NewDefaultAbcModel( - xyz string, -) *AbcModel { - m := &AbcModel{resourceModelMeta: defaultMeta(resources.Abc)} - m.WithXyz(xyz) - return m -} -``` -Two methods for each param (with good value type and with any value type): -```go -func (m *AbcModel) WithXyz(xyz string) *AbcModel { - m.Xyz = config.StringVariable(xyz) - return m -} - -func (m *AbcModel) WithXyzValue(value config.Variable) *AbcModel { - m.Xyz = value - return m -} -``` - -- `abc_model_ext.go` - for the easier separation later (when we start generating the models for each object). Example would be: -```go -func BasicWarehouseModel( - name string, - comment string, -) *WarehouseModel { - return NewDefaultWarehouseModel(name).WithComment(comment) -} -``` - ## Known limitations/planned improvements -- 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). -- Support additional methods for references in models (TODO left). -- Support depends_on in models (TODO left). -- Add a convenience function to concatenate multiple models (TODO left). -- Add function to support using `ConfigFile:` in the acceptance tests. +- Consider a better implementation for the model conversion to config (TODO left in `config/config.go`). +- Support additional methods for references in models (TODO left in `config/config.go`). +- Support depends_on in models (TODO left in `config/config.go`). +- Add a convenience function to concatenate multiple models (TODO left in `config/config.go`). +- Add function to support using `ConfigFile:` in the acceptance tests (TODO left in `config/config.go`). - Replace `acceptance/snowflakechecks` with the new proposed Snowflake objects assertions. - Support `showOutputValueUnset` and add a second function for each `show_output` attribute. - Support `resourceAssertionTypeValueNotSet` for import checks (`panic` left currently). @@ -454,4 +319,9 @@ func (w *WarehouseDatasourceShowOutputAssert) IsEmpty() { - 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 +- use a better definition for each objet's snowflake parameters (TODO left in `assert/objectparametersassert/gen/main/main.go`) +- add possibility to have enums generated in config builders (TODO left in `config/model/warehouse_model_ext.go`) +- handle situations where snowflake default behaves inconsistently (TODO left in `assert/objectparametersassert/gen/object_parameters_def.go`) +- handle attribute types in resource assertions (currently strings only; TODO left in `assert/resourceassert/gen/model.go`) +- distinguish between different enum types (TODO left in `assert/resourceshowoutputassert/gen/templates.go`) +- support the rest of attribute types in config model builders (TODO left in `config/model/gen/model.go`) diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go index a9635a1bc7..d9802c27d3 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/main/main.go @@ -5,12 +5,11 @@ package main import ( "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" ) func main() { genhelpers.NewGenerator( - getSdkObjectDetails, + gen.GetSdkObjectDetails, gen.ModelFromSdkObjectDetails, getFilename, gen.AllTemplates, @@ -18,38 +17,6 @@ func main() { RunAndHandleOsReturn() } -type SdkObjectDef struct { - idType string - objectType sdk.ObjectType - objectStruct any -} - -func getSdkObjectDetails() []genhelpers.SdkObjectDetails { - allSdkObjectsDetails := make([]genhelpers.SdkObjectDetails, len(allStructs)) - for idx, d := range allStructs { - structDetails := genhelpers.ExtractStructDetails(d.objectStruct) - allSdkObjectsDetails[idx] = genhelpers.SdkObjectDetails{ - IdType: d.idType, - ObjectType: d.objectType, - StructDetails: structDetails, - } - } - return allSdkObjectsDetails -} - func getFilename(_ genhelpers.SdkObjectDetails, model gen.SnowflakeObjectAssertionsModel) string { return genhelpers.ToSnakeCase(model.Name) + "_snowflake" + "_gen.go" } - -var allStructs = []SdkObjectDef{ - { - idType: "sdk.AccountObjectIdentifier", - objectType: sdk.ObjectTypeUser, - objectStruct: sdk.User{}, - }, - { - idType: "sdk.AccountObjectIdentifier", - objectType: sdk.ObjectTypeWarehouse, - objectStruct: sdk.Warehouse{}, - }, -} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go index a4de0d2846..4dd4808972 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/model.go @@ -2,7 +2,6 @@ package gen import ( "os" - "slices" "strings" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" @@ -35,19 +34,8 @@ type SnowflakeObjectFieldAssertion struct { func ModelFromSdkObjectDetails(sdkObject genhelpers.SdkObjectDetails) SnowflakeObjectAssertionsModel { name, _ := strings.CutPrefix(sdkObject.Name, "sdk.") fields := make([]SnowflakeObjectFieldAssertion, len(sdkObject.Fields)) - imports := make(map[string]struct{}) for idx, field := range sdkObject.Fields { fields[idx] = MapToSnowflakeObjectFieldAssertion(field) - additionalImport, isImportedType := field.GetImportedType() - if isImportedType { - imports[additionalImport] = struct{}{} - } - } - additionalImports := make([]string, 0) - for k := range imports { - if !slices.Contains([]string{"sdk"}, k) { - additionalImports = append(additionalImports, k) - } } packageWithGenerateDirective := os.Getenv("GOPACKAGE") @@ -58,7 +46,7 @@ func ModelFromSdkObjectDetails(sdkObject genhelpers.SdkObjectDetails) SnowflakeO Fields: fields, PreambleModel: PreambleModel{ PackageName: packageWithGenerateDirective, - AdditionalStandardImports: additionalImports, + AdditionalStandardImports: genhelpers.AdditionalStandardImports(sdkObject.Fields), }, } } diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/sdk_object_def.go b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/sdk_object_def.go new file mode 100644 index 0000000000..c634be1256 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/sdk_object_def.go @@ -0,0 +1,38 @@ +package gen + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +type SdkObjectDef struct { + IdType string + ObjectType sdk.ObjectType + ObjectStruct any +} + +var allStructs = []SdkObjectDef{ + { + IdType: "sdk.AccountObjectIdentifier", + ObjectType: sdk.ObjectTypeUser, + ObjectStruct: sdk.User{}, + }, + { + IdType: "sdk.AccountObjectIdentifier", + ObjectType: sdk.ObjectTypeWarehouse, + ObjectStruct: sdk.Warehouse{}, + }, +} + +func GetSdkObjectDetails() []genhelpers.SdkObjectDetails { + allSdkObjectsDetails := make([]genhelpers.SdkObjectDetails, len(allStructs)) + for idx, d := range allStructs { + structDetails := genhelpers.ExtractStructDetails(d.ObjectStruct) + allSdkObjectsDetails[idx] = genhelpers.SdkObjectDetails{ + IdType: d.IdType, + ObjectType: d.ObjectType, + StructDetails: structDetails, + } + } + return allSdkObjectsDetails +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl index ac7011d57e..3e0d6c6a11 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/gen/templates/preamble.tmpl @@ -1,6 +1,6 @@ {{- /*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. +// Code generated by assertions generator; DO NOT EDIT. package {{ .PackageName }} diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go index d3875a169b..39bde579b3 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/user_snowflake_gen.go @@ -1,4 +1,4 @@ -// Code generated by sdk-to-schema generator; DO NOT EDIT. +// Code generated by assertions generator; DO NOT EDIT. package objectassert diff --git a/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go index d90d75bb8b..6bd4f0c857 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectassert/warehouse_snowflake_gen.go @@ -1,4 +1,4 @@ -// Code generated by sdk-to-schema generator; DO NOT EDIT. +// Code generated by assertions generator; DO NOT EDIT. package objectassert diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go deleted file mode 100644 index 982f6daf90..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/commons.go +++ /dev/null @@ -1,22 +0,0 @@ -package gen - -import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - -type SnowflakeObjectParameters struct { - Name string - IdType string - Level sdk.ParameterType - AdditionalImports []string - Parameters []SnowflakeParameter -} - -func (p SnowflakeObjectParameters) ObjectName() string { - return p.Name -} - -type SnowflakeParameter struct { - ParameterName string - ParameterType string - DefaultValue string - DefaultLevel string -} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go index b7073aeebb..e1afc1d2e8 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/main/main.go @@ -5,12 +5,11 @@ package main import ( "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" ) func main() { genhelpers.NewGenerator( - getAllSnowflakeObjectParameters, + gen.GetAllSnowflakeObjectParameters, gen.ModelFromSnowflakeObjectParameters, getFilename, gen.AllTemplates, @@ -18,92 +17,6 @@ func main() { RunAndHandleOsReturn() } -func getAllSnowflakeObjectParameters() []gen.SnowflakeObjectParameters { - return allObjectsParameters -} - func getFilename(_ gen.SnowflakeObjectParameters, model gen.SnowflakeObjectParametersAssertionsModel) string { return genhelpers.ToSnakeCase(model.Name) + "_parameters_snowflake" + "_gen.go" } - -// TODO [SNOW-1501905]: use SDK definition after parameters rework (+ preprocessing here) -var allObjectsParameters = []gen.SnowflakeObjectParameters{ - { - Name: "User", - IdType: "sdk.AccountObjectIdentifier", - Level: sdk.ParameterTypeUser, - Parameters: []gen.SnowflakeParameter{ - {ParameterName: string(sdk.UserParameterEnableUnredactedQuerySyntaxError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterNetworkPolicy), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterPreventUnloadToInternalStages), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterAbortDetachedQuery), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterAutocommit), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeAccount"}, - {ParameterName: string(sdk.UserParameterBinaryInputFormat), ParameterType: "sdk.BinaryInputFormat", DefaultValue: "sdk.BinaryInputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterBinaryOutputFormat), ParameterType: "sdk.BinaryOutputFormat", DefaultValue: "sdk.BinaryOutputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterClientMemoryLimit), ParameterType: "int", DefaultValue: "1536", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterClientMetadataRequestUseConnectionCtx), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterClientPrefetchThreads), ParameterType: "int", DefaultValue: "4", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterClientResultChunkSize), ParameterType: "int", DefaultValue: "160", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterClientResultColumnCaseInsensitive), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterClientSessionKeepAlive), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency), ParameterType: "int", DefaultValue: "3600", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterClientTimestampTypeMapping), ParameterType: "sdk.ClientTimestampTypeMapping", DefaultValue: "sdk.ClientTimestampTypeMappingLtz", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterDateInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterDateOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterEnableUnloadPhysicalTypeOptimization), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterErrorOnNondeterministicMerge), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterErrorOnNondeterministicUpdate), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterGeographyOutputFormat), ParameterType: "sdk.GeographyOutputFormat", DefaultValue: "sdk.GeographyOutputFormatGeoJSON", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterGeometryOutputFormat), ParameterType: "sdk.GeometryOutputFormat", DefaultValue: "sdk.GeometryOutputFormatGeoJSON", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterJdbcTreatDecimalAsInt), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterJdbcTreatTimestampNtzAsUtc), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterJdbcUseSessionTimezone), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterJsonIndent), ParameterType: "int", DefaultValue: "2", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterLockTimeout), ParameterType: "int", DefaultValue: "43200", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterLogLevel), ParameterType: "sdk.LogLevel", DefaultValue: "sdk.LogLevelOff", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterMultiStatementCount), ParameterType: "int", DefaultValue: "1", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterNoorderSequenceAsDefault), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterOdbcTreatDecimalAsInt), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterQueryTag), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, - {ParameterName: string(sdk.UserParameterRowsPerResultset), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterS3StageVpceDnsName), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterSearchPath), ParameterType: "string", DefaultValue: "$current, $public", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterSimulatedDataSharingConsumer), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterStatementQueuedTimeoutInSeconds), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterStatementTimeoutInSeconds), ParameterType: "int", DefaultValue: "172800", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterStrictJsonOutput), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimestampDayIsAlways24h), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimestampInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimestampLtzOutputFormat), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimestampNtzOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD HH24:MI:SS.FF3", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimestampOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimestampTypeMapping), ParameterType: "sdk.TimestampTypeMapping", DefaultValue: "sdk.TimestampTypeMappingNtz", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimestampTzOutputFormat), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimezone), ParameterType: "string", DefaultValue: "America/Los_Angeles", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimeInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTimeOutputFormat), ParameterType: "string", DefaultValue: "HH24:MI:SS", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTraceLevel), ParameterType: "sdk.TraceLevel", DefaultValue: "sdk.TraceLevelOff", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTransactionAbortOnError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, - {ParameterName: string(sdk.UserParameterTransactionDefaultIsolationLevel), ParameterType: "sdk.TransactionDefaultIsolationLevel", DefaultValue: "sdk.TransactionDefaultIsolationLevelReadCommitted", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterTwoDigitCenturyStart), ParameterType: "int", DefaultValue: "1970", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - // TODO: quick workaround for now: lowercase for ignore in snowflake by default but uppercase for FAIL - {ParameterName: string(sdk.UserParameterUnsupportedDdlAction), ParameterType: "sdk.UnsupportedDDLAction", DefaultValue: "sdk.UnsupportedDDLAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore)))", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterUseCachedResult), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterWeekOfYearPolicy), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.UserParameterWeekStart), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - }, - // for the quickfix above - AdditionalImports: []string{"strings"}, - }, - { - Name: "Warehouse", - IdType: "sdk.AccountObjectIdentifier", - Level: sdk.ParameterTypeWarehouse, - Parameters: []gen.SnowflakeParameter{ - {ParameterName: string(sdk.WarehouseParameterMaxConcurrencyLevel), ParameterType: "int", DefaultValue: "8", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - {ParameterName: string(sdk.WarehouseParameterStatementTimeoutInSeconds), ParameterType: "int", DefaultValue: "172800", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, - }, - }, -} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/object_parameters_def.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/object_parameters_def.go new file mode 100644 index 0000000000..a4013bbad2 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/object_parameters_def.go @@ -0,0 +1,108 @@ +package gen + +import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + +type SnowflakeObjectParameters struct { + Name string + IdType string + Level sdk.ParameterType + AdditionalImports []string + Parameters []SnowflakeParameter +} + +func (p SnowflakeObjectParameters) ObjectName() string { + return p.Name +} + +type SnowflakeParameter struct { + ParameterName string + ParameterType string + DefaultValue string + DefaultLevel string +} + +func GetAllSnowflakeObjectParameters() []SnowflakeObjectParameters { + return allObjectsParameters +} + +// TODO [SNOW-1501905]: use SDK definition after parameters rework (+ preprocessing here) +var allObjectsParameters = []SnowflakeObjectParameters{ + { + Name: "User", + IdType: "sdk.AccountObjectIdentifier", + Level: sdk.ParameterTypeUser, + Parameters: []SnowflakeParameter{ + {ParameterName: string(sdk.UserParameterEnableUnredactedQuerySyntaxError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterNetworkPolicy), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterPreventUnloadToInternalStages), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterAbortDetachedQuery), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterAutocommit), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterBinaryInputFormat), ParameterType: "sdk.BinaryInputFormat", DefaultValue: "sdk.BinaryInputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterBinaryOutputFormat), ParameterType: "sdk.BinaryOutputFormat", DefaultValue: "sdk.BinaryOutputFormatHex", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientMemoryLimit), ParameterType: "int", DefaultValue: "1536", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientMetadataRequestUseConnectionCtx), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientPrefetchThreads), ParameterType: "int", DefaultValue: "4", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientResultChunkSize), ParameterType: "int", DefaultValue: "160", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientResultColumnCaseInsensitive), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientSessionKeepAlive), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency), ParameterType: "int", DefaultValue: "3600", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterClientTimestampTypeMapping), ParameterType: "sdk.ClientTimestampTypeMapping", DefaultValue: "sdk.ClientTimestampTypeMappingLtz", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterDateInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterDateOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterEnableUnloadPhysicalTypeOptimization), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterErrorOnNondeterministicMerge), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterErrorOnNondeterministicUpdate), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterGeographyOutputFormat), ParameterType: "sdk.GeographyOutputFormat", DefaultValue: "sdk.GeographyOutputFormatGeoJSON", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterGeometryOutputFormat), ParameterType: "sdk.GeometryOutputFormat", DefaultValue: "sdk.GeometryOutputFormatGeoJSON", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterJdbcTreatDecimalAsInt), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterJdbcTreatTimestampNtzAsUtc), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterJdbcUseSessionTimezone), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterJsonIndent), ParameterType: "int", DefaultValue: "2", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterLockTimeout), ParameterType: "int", DefaultValue: "43200", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterLogLevel), ParameterType: "sdk.LogLevel", DefaultValue: "sdk.LogLevelOff", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterMultiStatementCount), ParameterType: "int", DefaultValue: "1", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterNoorderSequenceAsDefault), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterOdbcTreatDecimalAsInt), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterQueryTag), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterQuotedIdentifiersIgnoreCase), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterRowsPerResultset), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterS3StageVpceDnsName), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterSearchPath), ParameterType: "string", DefaultValue: "$current, $public", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterSimulatedDataSharingConsumer), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterStatementQueuedTimeoutInSeconds), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterStatementTimeoutInSeconds), ParameterType: "int", DefaultValue: "172800", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterStrictJsonOutput), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampDayIsAlways24h), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampLtzOutputFormat), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampNtzOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD HH24:MI:SS.FF3", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampOutputFormat), ParameterType: "string", DefaultValue: "YYYY-MM-DD HH24:MI:SS.FF3 TZHTZM", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampTypeMapping), ParameterType: "sdk.TimestampTypeMapping", DefaultValue: "sdk.TimestampTypeMappingNtz", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimestampTzOutputFormat), ParameterType: "string", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimezone), ParameterType: "string", DefaultValue: "America/Los_Angeles", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimeInputFormat), ParameterType: "string", DefaultValue: "AUTO", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTimeOutputFormat), ParameterType: "string", DefaultValue: "HH24:MI:SS", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTraceLevel), ParameterType: "sdk.TraceLevel", DefaultValue: "sdk.TraceLevelOff", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTransactionAbortOnError), ParameterType: "bool", DefaultValue: "false", DefaultLevel: "sdk.ParameterTypeAccount"}, + {ParameterName: string(sdk.UserParameterTransactionDefaultIsolationLevel), ParameterType: "sdk.TransactionDefaultIsolationLevel", DefaultValue: "sdk.TransactionDefaultIsolationLevelReadCommitted", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterTwoDigitCenturyStart), ParameterType: "int", DefaultValue: "1970", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + // TODO [SNOW-1501905]: quick workaround for now: lowercase for ignore in snowflake by default but uppercase for FAIL + {ParameterName: string(sdk.UserParameterUnsupportedDdlAction), ParameterType: "sdk.UnsupportedDDLAction", DefaultValue: "sdk.UnsupportedDDLAction(strings.ToLower(string(sdk.UnsupportedDDLActionIgnore)))", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterUseCachedResult), ParameterType: "bool", DefaultValue: "true", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterWeekOfYearPolicy), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.UserParameterWeekStart), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + }, + // for the quickfix above + AdditionalImports: []string{"strings"}, + }, + { + Name: "Warehouse", + IdType: "sdk.AccountObjectIdentifier", + Level: sdk.ParameterTypeWarehouse, + Parameters: []SnowflakeParameter{ + {ParameterName: string(sdk.WarehouseParameterMaxConcurrencyLevel), ParameterType: "int", DefaultValue: "8", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds), ParameterType: "int", DefaultValue: "0", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + {ParameterName: string(sdk.WarehouseParameterStatementTimeoutInSeconds), ParameterType: "int", DefaultValue: "172800", DefaultLevel: "sdk.ParameterTypeSnowflakeDefault"}, + }, + }, +} diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl index 4e8c6394a8..a02f6e8d60 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen/templates/preamble.tmpl @@ -1,6 +1,6 @@ {{- /*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. +// Code generated by assertions generator; DO NOT EDIT. package {{ .PackageName }} 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 a8e1727714..4f860eb38d 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/user_parameters_snowflake_gen.go @@ -1,4 +1,4 @@ -// Code generated by sdk-to-schema generator; DO NOT EDIT. +// Code generated by assertions generator; DO NOT EDIT. package objectparametersassert diff --git a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/warehouse_parameters_snowflake_gen.go b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/warehouse_parameters_snowflake_gen.go index e9eb7ef3c6..90ab1ff824 100644 --- a/pkg/acceptance/bettertestspoc/assert/objectparametersassert/warehouse_parameters_snowflake_gen.go +++ b/pkg/acceptance/bettertestspoc/assert/objectparametersassert/warehouse_parameters_snowflake_gen.go @@ -1,4 +1,4 @@ -// Code generated by sdk-to-schema generator; DO NOT EDIT. +// Code generated by assertions generator; DO NOT EDIT. package objectparametersassert diff --git a/pkg/acceptance/bettertestspoc/assert/resource_assertions.go b/pkg/acceptance/bettertestspoc/assert/resource_assertions.go index 99c4b203bb..13fa6b1ae2 100644 --- a/pkg/acceptance/bettertestspoc/assert/resource_assertions.go +++ b/pkg/acceptance/bettertestspoc/assert/resource_assertions.go @@ -3,10 +3,12 @@ package assert import ( "errors" "fmt" + "strconv" "strings" "testing" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/importchecks" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" ) @@ -22,7 +24,7 @@ type ResourceAssert struct { name string id string prefix string - assertions []resourceAssertion + assertions []ResourceAssertion } // NewResourceAssert creates a ResourceAssert where the resource name should be used as a key for assertions. @@ -30,7 +32,7 @@ func NewResourceAssert(name string, prefix string) *ResourceAssert { return &ResourceAssert{ name: name, prefix: prefix, - assertions: make([]resourceAssertion, 0), + assertions: make([]ResourceAssertion, 0), } } @@ -39,7 +41,7 @@ func NewImportedResourceAssert(id string, prefix string) *ResourceAssert { return &ResourceAssert{ id: id, prefix: prefix, - assertions: make([]resourceAssertion, 0), + assertions: make([]ResourceAssertion, 0), } } @@ -50,24 +52,44 @@ const ( resourceAssertionTypeValueNotSet = "VALUE_NOT_SET" ) -type resourceAssertion struct { +type ResourceAssertion struct { fieldName string expectedValue string resourceAssertionType resourceAssertionType } -func valueSet(fieldName string, expected string) resourceAssertion { - return resourceAssertion{fieldName: fieldName, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet} +func (r *ResourceAssert) AddAssertion(assertion ResourceAssertion) { + r.assertions = append(r.assertions, assertion) } -func valueNotSet(fieldName string) resourceAssertion { - return resourceAssertion{fieldName: fieldName, resourceAssertionType: resourceAssertionTypeValueNotSet} +func ValueSet(fieldName string, expected string) ResourceAssertion { + return ResourceAssertion{fieldName: fieldName, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet} +} + +func ValueNotSet(fieldName string) ResourceAssertion { + return ResourceAssertion{fieldName: fieldName, resourceAssertionType: resourceAssertionTypeValueNotSet} } const showOutputPrefix = "show_output.0." -func showOutputValueSet(fieldName string, expected string) resourceAssertion { - return resourceAssertion{fieldName: showOutputPrefix + fieldName, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet} +func ResourceShowOutputBoolValueSet(fieldName string, expected bool) ResourceAssertion { + return ResourceShowOutputValueSet(fieldName, strconv.FormatBool(expected)) +} + +func ResourceShowOutputIntValueSet(fieldName string, expected int) ResourceAssertion { + return ResourceShowOutputValueSet(fieldName, strconv.Itoa(expected)) +} + +func ResourceShowOutputFloatValueSet(fieldName string, expected float64) ResourceAssertion { + return ResourceShowOutputValueSet(fieldName, strconv.FormatFloat(expected, 'f', -1, 64)) +} + +func ResourceShowOutputStringUnderlyingValueSet[U ~string](fieldName string, expected U) ResourceAssertion { + return ResourceShowOutputValueSet(fieldName, string(expected)) +} + +func ResourceShowOutputValueSet(fieldName string, expected string) ResourceAssertion { + return ResourceAssertion{fieldName: showOutputPrefix + fieldName, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet} } const ( @@ -76,12 +98,24 @@ const ( parametersLevelSuffix = ".0.level" ) -func parameterValueSet(fieldName string, expected string) resourceAssertion { - return resourceAssertion{fieldName: parametersPrefix + fieldName + parametersValueSuffix, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet} +func ResourceParameterBoolValueSet[T ~string](parameterName T, expected bool) ResourceAssertion { + return ResourceParameterValueSet(parameterName, strconv.FormatBool(expected)) +} + +func ResourceParameterIntValueSet[T ~string](parameterName T, expected int) ResourceAssertion { + return ResourceParameterValueSet(parameterName, strconv.Itoa(expected)) +} + +func ResourceParameterStringUnderlyingValueSet[T ~string, U ~string](parameterName T, expected U) ResourceAssertion { + return ResourceParameterValueSet(parameterName, string(expected)) +} + +func ResourceParameterValueSet[T ~string](parameterName T, expected string) ResourceAssertion { + return ResourceAssertion{fieldName: parametersPrefix + strings.ToLower(string(parameterName)) + parametersValueSuffix, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet} } -func parameterLevelSet(fieldName string, expected string) resourceAssertion { - return resourceAssertion{fieldName: parametersPrefix + fieldName + parametersLevelSuffix, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet} +func ResourceParameterLevelSet[T ~string](parameterName T, parameterType sdk.ParameterType) ResourceAssertion { + return ResourceAssertion{fieldName: parametersPrefix + strings.ToLower(string(parameterName)) + parametersLevelSuffix, expectedValue: string(parameterType), resourceAssertionType: resourceAssertionTypeValueSet} } // ToTerraformTestCheckFunc implements TestCheckFuncProvider to allow easier creation of new resource assertions. diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/main/main.go new file mode 100644 index 0000000000..e1726451cb --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/main/main.go @@ -0,0 +1,22 @@ +//go:build exclude + +package main + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceassert/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +func main() { + genhelpers.NewGenerator( + gen.GetResourceSchemaDetails, + gen.ModelFromResourceSchemaDetails, + getFilename, + gen.AllTemplates, + ). + RunAndHandleOsReturn() +} + +func getFilename(_ genhelpers.ResourceSchemaDetails, model gen.ResourceAssertionsModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_resource" + "_gen.go" +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/model.go new file mode 100644 index 0000000000..47bab21d60 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/model.go @@ -0,0 +1,52 @@ +package gen + +import ( + "os" + "slices" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" +) + +// TODO [SNOW-1501905]: extract to commons? +type PreambleModel struct { + PackageName string + AdditionalStandardImports []string +} + +type ResourceAssertionsModel struct { + Name string + Attributes []ResourceAttributeAssertionModel + PreambleModel +} + +func (m ResourceAssertionsModel) SomeFunc() { +} + +type ResourceAttributeAssertionModel struct { + Name string + AttributeType string +} + +func ModelFromResourceSchemaDetails(resourceSchemaDetails genhelpers.ResourceSchemaDetails) ResourceAssertionsModel { + attributes := make([]ResourceAttributeAssertionModel, 0) + for _, attr := range resourceSchemaDetails.Attributes { + if slices.Contains([]string{resources.ShowOutputAttributeName, resources.ParametersAttributeName, resources.DescribeOutputAttributeName}, attr.Name) { + continue + } + attributes = append(attributes, ResourceAttributeAssertionModel{ + Name: attr.Name, + // TODO [SNOW-1501905]: add attribute type logic; allow type safe assertions, not only strings + AttributeType: "string", + }) + } + + packageWithGenerateDirective := os.Getenv("GOPACKAGE") + return ResourceAssertionsModel{ + Name: resourceSchemaDetails.ObjectName(), + Attributes: attributes, + PreambleModel: PreambleModel{ + PackageName: packageWithGenerateDirective, + }, + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go new file mode 100644 index 0000000000..3e54aed96c --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go @@ -0,0 +1,32 @@ +package gen + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +type ResourceSchemaDef struct { + name string + schema map[string]*schema.Schema +} + +func GetResourceSchemaDetails() []genhelpers.ResourceSchemaDetails { + allResourceSchemas := allResourceSchemaDefs + allResourceSchemasDetails := make([]genhelpers.ResourceSchemaDetails, len(allResourceSchemas)) + for idx, s := range allResourceSchemas { + allResourceSchemasDetails[idx] = genhelpers.ExtractResourceSchemaDetails(s.name, s.schema) + } + return allResourceSchemasDetails +} + +var allResourceSchemaDefs = []ResourceSchemaDef{ + { + name: "Warehouse", + schema: resources.Warehouse().Schema, + }, + { + name: "User", + schema: resources.User().Schema, + }, +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates.go new file mode 100644 index 0000000000..4f21255de4 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates.go @@ -0,0 +1,29 @@ +package gen + +import ( + "text/template" + + _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + + //go:embed templates/definition.tmpl + definitionTemplateContent string + DefinitionTemplate, _ = template.New("definitionTemplate").Parse(definitionTemplateContent) + + //go:embed templates/assertions.tmpl + assertionsTemplateContent string + AssertionsTemplate, _ = template.New("assertionsTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + genhelpers.SnakeCaseToCamel, + )).Parse(assertionsTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, DefinitionTemplate, AssertionsTemplate} +) diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/assertions.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/assertions.tmpl new file mode 100644 index 0000000000..929304d2e6 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/assertions.tmpl @@ -0,0 +1,28 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceassert/gen.ResourceAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sResourceAssert" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $assertVar := FirstLetter $nameLowerCase }} +/////////////////////////////////// +// Attribute value string checks // +/////////////////////////////////// + +{{ range .Attributes -}} + func ({{ $assertVar }} *{{ $assertName }}) Has{{ SnakeCaseToCamel .Name }}String(expected string) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.ValueSet("{{ .Name }}", expected)) + return {{ $assertVar }} + } + +{{ end -}} + +//////////////////////////// +// Attribute empty checks // +//////////////////////////// + +{{ range .Attributes -}} + func ({{ $assertVar }} *{{ $assertName }}) HasNo{{ SnakeCaseToCamel .Name }}() *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.ValueNotSet("{{ .Name }}")) + return {{ $assertVar }} + } + +{{ end -}} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/definition.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/definition.tmpl new file mode 100644 index 0000000000..074b15a1e9 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/definition.tmpl @@ -0,0 +1,22 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceassert/gen.ResourceAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sResourceAssert" }} +type {{ $assertName }} struct { + *assert.ResourceAssert +} + +func {{ .Name }}Resource(t *testing.T, name string) *{{ $assertName }} { + t.Helper() + + return &{{ $assertName }}{ + ResourceAssert: assert.NewResourceAssert(name, "resource"), + } +} + +func Imported{{ .Name }}Resource(t *testing.T, id string) *{{ $assertName }} { + t.Helper() + + return &{{ $assertName }}{ + ResourceAssert: assert.NewImportedResourceAssert(id, "imported resource"), + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/preamble.tmpl new file mode 100644 index 0000000000..def45643ff --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/gen/templates/preamble.tmpl @@ -0,0 +1,14 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceassert/gen.PreambleModel*/ -}} + +// Code generated by assertions generator; DO NOT EDIT. + +package {{ .PackageName }} + +import ( + "testing" + {{- range .AdditionalStandardImports }} + "{{- . }}" + {{- end }} + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" +) diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/generate.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/generate.go new file mode 100644 index 0000000000..f9a4d8210f --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/generate.go @@ -0,0 +1,3 @@ +package resourceassert + +//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/user_resource_gen.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/user_resource_gen.go new file mode 100644 index 0000000000..45f5bbd716 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/user_resource_gen.go @@ -0,0 +1,207 @@ +// Code generated by assertions generator; DO NOT EDIT. + +package resourceassert + +import ( + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" +) + +type UserResourceAssert struct { + *assert.ResourceAssert +} + +func UserResource(t *testing.T, name string) *UserResourceAssert { + t.Helper() + + return &UserResourceAssert{ + ResourceAssert: assert.NewResourceAssert(name, "resource"), + } +} + +func ImportedUserResource(t *testing.T, id string) *UserResourceAssert { + t.Helper() + + return &UserResourceAssert{ + ResourceAssert: assert.NewImportedResourceAssert(id, "imported resource"), + } +} + +/////////////////////////////////// +// Attribute value string checks // +/////////////////////////////////// + +func (u *UserResourceAssert) HasCommentString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("comment", expected)) + return u +} + +func (u *UserResourceAssert) HasDefaultNamespaceString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("default_namespace", expected)) + return u +} + +func (u *UserResourceAssert) HasDefaultRoleString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("default_role", expected)) + return u +} + +func (u *UserResourceAssert) HasDefaultSecondaryRolesString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("default_secondary_roles", expected)) + return u +} + +func (u *UserResourceAssert) HasDefaultWarehouseString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("default_warehouse", expected)) + return u +} + +func (u *UserResourceAssert) HasDisabledString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("disabled", expected)) + return u +} + +func (u *UserResourceAssert) HasDisplayNameString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("display_name", expected)) + return u +} + +func (u *UserResourceAssert) HasEmailString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("email", expected)) + return u +} + +func (u *UserResourceAssert) HasFirstNameString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("first_name", expected)) + return u +} + +func (u *UserResourceAssert) HasHasRsaPublicKeyString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("has_rsa_public_key", expected)) + return u +} + +func (u *UserResourceAssert) HasLastNameString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("last_name", expected)) + return u +} + +func (u *UserResourceAssert) HasLoginNameString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("login_name", expected)) + return u +} + +func (u *UserResourceAssert) HasMustChangePasswordString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("must_change_password", expected)) + return u +} + +func (u *UserResourceAssert) HasNameString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("name", expected)) + return u +} + +func (u *UserResourceAssert) HasPasswordString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("password", expected)) + return u +} + +func (u *UserResourceAssert) HasRsaPublicKeyString(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("rsa_public_key", expected)) + return u +} + +func (u *UserResourceAssert) HasRsaPublicKey2String(expected string) *UserResourceAssert { + u.AddAssertion(assert.ValueSet("rsa_public_key_2", expected)) + return u +} + +//////////////////////////// +// Attribute empty checks // +//////////////////////////// + +func (u *UserResourceAssert) HasNoComment() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("comment")) + return u +} + +func (u *UserResourceAssert) HasNoDefaultNamespace() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("default_namespace")) + return u +} + +func (u *UserResourceAssert) HasNoDefaultRole() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("default_role")) + return u +} + +func (u *UserResourceAssert) HasNoDefaultSecondaryRoles() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("default_secondary_roles")) + return u +} + +func (u *UserResourceAssert) HasNoDefaultWarehouse() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("default_warehouse")) + return u +} + +func (u *UserResourceAssert) HasNoDisabled() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("disabled")) + return u +} + +func (u *UserResourceAssert) HasNoDisplayName() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("display_name")) + return u +} + +func (u *UserResourceAssert) HasNoEmail() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("email")) + return u +} + +func (u *UserResourceAssert) HasNoFirstName() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("first_name")) + return u +} + +func (u *UserResourceAssert) HasNoHasRsaPublicKey() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("has_rsa_public_key")) + return u +} + +func (u *UserResourceAssert) HasNoLastName() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("last_name")) + return u +} + +func (u *UserResourceAssert) HasNoLoginName() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("login_name")) + return u +} + +func (u *UserResourceAssert) HasNoMustChangePassword() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("must_change_password")) + return u +} + +func (u *UserResourceAssert) HasNoName() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("name")) + return u +} + +func (u *UserResourceAssert) HasNoPassword() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("password")) + return u +} + +func (u *UserResourceAssert) HasNoRsaPublicKey() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("rsa_public_key")) + return u +} + +func (u *UserResourceAssert) HasNoRsaPublicKey2() *UserResourceAssert { + u.AddAssertion(assert.ValueNotSet("rsa_public_key_2")) + return u +} diff --git a/pkg/acceptance/bettertestspoc/assert/warehouse_resource_ext.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/warehouse_resource_ext.go similarity index 51% rename from pkg/acceptance/bettertestspoc/assert/warehouse_resource_ext.go rename to pkg/acceptance/bettertestspoc/assert/resourceassert/warehouse_resource_ext.go index f246ae8f43..24643a19d4 100644 --- a/pkg/acceptance/bettertestspoc/assert/warehouse_resource_ext.go +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/warehouse_resource_ext.go @@ -1,35 +1,39 @@ -package assert +package resourceassert -import r "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" +import ( + r "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" +) func (w *WarehouseResourceAssert) HasDefaultMaxConcurrencyLevel() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("max_concurrency_level", "8")) + w.AddAssertion(assert.ValueSet("max_concurrency_level", "8")) return w } func (w *WarehouseResourceAssert) HasDefaultStatementQueuedTimeoutInSeconds() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("statement_queued_timeout_in_seconds", "0")) + w.AddAssertion(assert.ValueSet("statement_queued_timeout_in_seconds", "0")) return w } func (w *WarehouseResourceAssert) HasDefaultStatementTimeoutInSeconds() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("statement_timeout_in_seconds", "172800")) + w.AddAssertion(assert.ValueSet("statement_timeout_in_seconds", "172800")) return w } func (w *WarehouseResourceAssert) HasAllDefault() *WarehouseResourceAssert { return w.HasDefaultMaxConcurrencyLevel(). - HasNoType(). - HasNoSize(). + HasNoWarehouseType(). + HasNoWarehouseSize(). HasNoMaxClusterCount(). HasNoMinClusterCount(). HasNoScalingPolicy(). - HasAutoSuspend(r.IntDefaultString). - HasAutoResume(r.BooleanDefault). + HasAutoSuspendString(r.IntDefaultString). + HasAutoResumeString(r.BooleanDefault). HasNoInitiallySuspended(). HasNoResourceMonitor(). - HasEnableQueryAcceleration(r.BooleanDefault). - HasQueryAccelerationMaxScaleFactor(r.IntDefaultString). + HasEnableQueryAccelerationString(r.BooleanDefault). + HasQueryAccelerationMaxScaleFactorString(r.IntDefaultString). HasDefaultMaxConcurrencyLevel(). HasDefaultStatementQueuedTimeoutInSeconds(). HasDefaultStatementTimeoutInSeconds() diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/warehouse_resource_gen.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/warehouse_resource_gen.go new file mode 100644 index 0000000000..fe8d54d8a1 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/warehouse_resource_gen.go @@ -0,0 +1,197 @@ +// Code generated by assertions generator; DO NOT EDIT. + +package resourceassert + +import ( + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" +) + +type WarehouseResourceAssert struct { + *assert.ResourceAssert +} + +func WarehouseResource(t *testing.T, name string) *WarehouseResourceAssert { + t.Helper() + + return &WarehouseResourceAssert{ + ResourceAssert: assert.NewResourceAssert(name, "resource"), + } +} + +func ImportedWarehouseResource(t *testing.T, id string) *WarehouseResourceAssert { + t.Helper() + + return &WarehouseResourceAssert{ + ResourceAssert: assert.NewImportedResourceAssert(id, "imported resource"), + } +} + +/////////////////////////////////// +// Attribute value string checks // +/////////////////////////////////// + +func (w *WarehouseResourceAssert) HasAutoResumeString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("auto_resume", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasAutoSuspendString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("auto_suspend", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasCommentString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("comment", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasEnableQueryAccelerationString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("enable_query_acceleration", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasInitiallySuspendedString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("initially_suspended", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasMaxClusterCountString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("max_cluster_count", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasMaxConcurrencyLevelString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("max_concurrency_level", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasMinClusterCountString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("min_cluster_count", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasNameString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("name", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasQueryAccelerationMaxScaleFactorString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("query_acceleration_max_scale_factor", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasResourceMonitorString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("resource_monitor", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasScalingPolicyString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("scaling_policy", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasStatementQueuedTimeoutInSecondsString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("statement_queued_timeout_in_seconds", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasStatementTimeoutInSecondsString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("statement_timeout_in_seconds", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasWarehouseSizeString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("warehouse_size", expected)) + return w +} + +func (w *WarehouseResourceAssert) HasWarehouseTypeString(expected string) *WarehouseResourceAssert { + w.AddAssertion(assert.ValueSet("warehouse_type", expected)) + return w +} + +//////////////////////////// +// Attribute empty checks // +//////////////////////////// + +func (w *WarehouseResourceAssert) HasNoAutoResume() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("auto_resume")) + return w +} + +func (w *WarehouseResourceAssert) HasNoAutoSuspend() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("auto_suspend")) + return w +} + +func (w *WarehouseResourceAssert) HasNoComment() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("comment")) + return w +} + +func (w *WarehouseResourceAssert) HasNoEnableQueryAcceleration() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("enable_query_acceleration")) + return w +} + +func (w *WarehouseResourceAssert) HasNoInitiallySuspended() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("initially_suspended")) + return w +} + +func (w *WarehouseResourceAssert) HasNoMaxClusterCount() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("max_cluster_count")) + return w +} + +func (w *WarehouseResourceAssert) HasNoMaxConcurrencyLevel() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("max_concurrency_level")) + return w +} + +func (w *WarehouseResourceAssert) HasNoMinClusterCount() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("min_cluster_count")) + return w +} + +func (w *WarehouseResourceAssert) HasNoName() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("name")) + return w +} + +func (w *WarehouseResourceAssert) HasNoQueryAccelerationMaxScaleFactor() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("query_acceleration_max_scale_factor")) + return w +} + +func (w *WarehouseResourceAssert) HasNoResourceMonitor() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("resource_monitor")) + return w +} + +func (w *WarehouseResourceAssert) HasNoScalingPolicy() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("scaling_policy")) + return w +} + +func (w *WarehouseResourceAssert) HasNoStatementQueuedTimeoutInSeconds() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("statement_queued_timeout_in_seconds")) + return w +} + +func (w *WarehouseResourceAssert) HasNoStatementTimeoutInSeconds() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("statement_timeout_in_seconds")) + return w +} + +func (w *WarehouseResourceAssert) HasNoWarehouseSize() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("warehouse_size")) + return w +} + +func (w *WarehouseResourceAssert) HasNoWarehouseType() *WarehouseResourceAssert { + w.AddAssertion(assert.ValueNotSet("warehouse_type")) + return w +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/main/main.go new file mode 100644 index 0000000000..9f5de1a5a4 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/main/main.go @@ -0,0 +1,24 @@ +//go:build exclude + +package main + +import ( + objectparametersassertgen "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +func main() { + genhelpers.NewGenerator( + objectparametersassertgen.GetAllSnowflakeObjectParameters, + gen.ModelFromSnowflakeObjectParameters, + getFilename, + gen.AllTemplates, + ). + RunAndHandleOsReturn() +} + +func getFilename(_ objectparametersassertgen.SnowflakeObjectParameters, model gen.ResourceParametersAssertionsModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_resource_parameters" + "_gen.go" +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/model.go new file mode 100644 index 0000000000..ad4b2daee3 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/model.go @@ -0,0 +1,64 @@ +package gen + +import ( + "os" + "strings" + + objectparametersassertgen "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen" +) + +// TODO [SNOW-1501905]: extract to commons? +type PreambleModel struct { + PackageName string + AdditionalStandardImports []string +} + +type ResourceParametersAssertionsModel struct { + Name string + Parameters []ResourceParameterAssertionModel + PreambleModel +} + +func (m ResourceParametersAssertionsModel) SomeFunc() { +} + +type ResourceParameterAssertionModel struct { + Name string + Type string + AssertionCreator string +} + +func ModelFromSnowflakeObjectParameters(snowflakeObjectParameters objectparametersassertgen.SnowflakeObjectParameters) ResourceParametersAssertionsModel { + parameters := make([]ResourceParameterAssertionModel, len(snowflakeObjectParameters.Parameters)) + for idx, p := range snowflakeObjectParameters.Parameters { + // TODO [SNOW-1501905]: get a runtime name for the assertion creator + var assertionCreator string + switch { + case p.ParameterType == "bool": + assertionCreator = "ResourceParameterBoolValueSet" + case p.ParameterType == "int": + assertionCreator = "ResourceParameterIntValueSet" + case p.ParameterType == "string": + assertionCreator = "ResourceParameterValueSet" + case strings.HasPrefix(p.ParameterType, "sdk."): + assertionCreator = "ResourceParameterStringUnderlyingValueSet" + default: + assertionCreator = "ResourceParameterValueSet" + } + + parameters[idx] = ResourceParameterAssertionModel{ + Name: p.ParameterName, + Type: p.ParameterType, + AssertionCreator: assertionCreator, + } + } + + packageWithGenerateDirective := os.Getenv("GOPACKAGE") + return ResourceParametersAssertionsModel{ + Name: snowflakeObjectParameters.ObjectName(), + Parameters: parameters, + PreambleModel: PreambleModel{ + PackageName: packageWithGenerateDirective, + }, + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates.go new file mode 100644 index 0000000000..361459525e --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates.go @@ -0,0 +1,32 @@ +package gen + +import ( + "text/template" + + _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + + //go:embed templates/definition.tmpl + definitionTemplateContent string + DefinitionTemplate, _ = template.New("definitionTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + )).Parse(definitionTemplateContent) + + //go:embed templates/specific_checks.tmpl + specificChecksTemplateContent string + SpecificChecksTemplate, _ = template.New("specificChecksTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + genhelpers.SnakeCaseToCamel, + )).Parse(specificChecksTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, DefinitionTemplate, SpecificChecksTemplate} +) diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/definition.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/definition.tmpl new file mode 100644 index 0000000000..a6c550eab6 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/definition.tmpl @@ -0,0 +1,28 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen.ResourceParametersAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sResourceParametersAssert" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $assertVar := FirstLetter $nameLowerCase }} +type {{ $assertName }} struct { + *assert.ResourceAssert +} + +func {{ .Name }}ResourceParameters(t *testing.T, name string) *{{ $assertName }} { + t.Helper() + + {{ $assertVar }} := {{ $assertName }}{ + ResourceAssert: assert.NewResourceAssert(name, "parameters"), + } + {{ $assertVar }}.AddAssertion(assert.ValueSet("parameters.#", "1")) + return &{{ $assertVar }} +} + +func Imported{{ .Name }}ResourceParameters(t *testing.T, id string) *{{ $assertName }} { + t.Helper() + + {{ $assertVar }} := {{ $assertName }}{ + ResourceAssert: assert.NewImportedResourceAssert(id, "imported parameters"), + } + {{ $assertVar }}.AddAssertion(assert.ValueSet("parameters.#", "1")) + return &{{ $assertVar }} +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/preamble.tmpl new file mode 100644 index 0000000000..c8b95c0c5f --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/preamble.tmpl @@ -0,0 +1,15 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen.PreambleModel*/ -}} + +// Code generated by assertions generator; DO NOT EDIT. + +package {{ .PackageName }} + +import ( + "testing" + {{- range .AdditionalStandardImports }} + "{{- . }}" + {{- end }} + + "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/resourceparametersassert/gen/templates/specific_checks.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/specific_checks.tmpl new file mode 100644 index 0000000000..0f4ce6b56f --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen/templates/specific_checks.tmpl @@ -0,0 +1,29 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert/gen.ResourceParametersAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sResourceParametersAssert" -}} +{{- $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.ResourceParameterLevelSet({{ $sdkParameterName }}{{ SnakeCaseToCamel .Name }}, expected)) + return {{ $assertVar }} + } + +{{ end -}} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/generate.go b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/generate.go new file mode 100644 index 0000000000..6a5c31c311 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/generate.go @@ -0,0 +1,3 @@ +package resourceparametersassert + +//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/user_resource_parameters_gen.go b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/user_resource_parameters_gen.go new file mode 100644 index 0000000000..44e722144c --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/user_resource_parameters_gen.go @@ -0,0 +1,622 @@ +// Code generated by assertions generator; DO NOT EDIT. + +package resourceparametersassert + +import ( + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +type UserResourceParametersAssert struct { + *assert.ResourceAssert +} + +func UserResourceParameters(t *testing.T, name string) *UserResourceParametersAssert { + t.Helper() + + u := UserResourceParametersAssert{ + ResourceAssert: assert.NewResourceAssert(name, "parameters"), + } + u.AddAssertion(assert.ValueSet("parameters.#", "1")) + return &u +} + +func ImportedUserResourceParameters(t *testing.T, id string) *UserResourceParametersAssert { + t.Helper() + + u := UserResourceParametersAssert{ + ResourceAssert: assert.NewImportedResourceAssert(id, "imported parameters"), + } + u.AddAssertion(assert.ValueSet("parameters.#", "1")) + return &u +} + +//////////////////////////// +// Parameter value checks // +//////////////////////////// + +func (u *UserResourceParametersAssert) HasEnableUnredactedQuerySyntaxError(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasNetworkPolicy(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterNetworkPolicy, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasPreventUnloadToInternalStages(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasAbortDetachedQuery(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterAbortDetachedQuery, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasAutocommit(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterAutocommit, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasBinaryInputFormat(expected sdk.BinaryInputFormat) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterBinaryInputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasBinaryOutputFormat(expected sdk.BinaryOutputFormat) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterBinaryOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientMemoryLimit(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterClientMemoryLimit, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientMetadataRequestUseConnectionCtx(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientPrefetchThreads(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterClientPrefetchThreads, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientResultChunkSize(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterClientResultChunkSize, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientResultColumnCaseInsensitive(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientSessionKeepAlive(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterClientSessionKeepAlive, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientSessionKeepAliveHeartbeatFrequency(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientTimestampTypeMapping(expected sdk.ClientTimestampTypeMapping) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterClientTimestampTypeMapping, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasDateInputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterDateInputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasDateOutputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterDateOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasEnableUnloadPhysicalTypeOptimization(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasErrorOnNondeterministicMerge(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasErrorOnNondeterministicUpdate(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasGeographyOutputFormat(expected sdk.GeographyOutputFormat) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterGeographyOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasGeometryOutputFormat(expected sdk.GeometryOutputFormat) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterGeometryOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasJdbcTreatDecimalAsInt(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasJdbcTreatTimestampNtzAsUtc(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasJdbcUseSessionTimezone(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasJsonIndent(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterJsonIndent, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasLockTimeout(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterLockTimeout, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasLogLevel(expected sdk.LogLevel) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterLogLevel, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasMultiStatementCount(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterMultiStatementCount, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasNoorderSequenceAsDefault(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasOdbcTreatDecimalAsInt(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasQueryTag(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterQueryTag, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasQuotedIdentifiersIgnoreCase(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasRowsPerResultset(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterRowsPerResultset, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasS3StageVpceDnsName(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterS3StageVpceDnsName, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasSearchPath(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterSearchPath, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasSimulatedDataSharingConsumer(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasStatementQueuedTimeoutInSeconds(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasStatementTimeoutInSeconds(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasStrictJsonOutput(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterStrictJsonOutput, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampDayIsAlways24h(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampInputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterTimestampInputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampLtzOutputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampNtzOutputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampOutputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterTimestampOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampTypeMapping(expected sdk.TimestampTypeMapping) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterTimestampTypeMapping, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampTzOutputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterTimestampTzOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimezone(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterTimezone, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimeInputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterTimeInputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimeOutputFormat(expected string) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterValueSet(sdk.UserParameterTimeOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTraceLevel(expected sdk.TraceLevel) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterTraceLevel, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTransactionAbortOnError(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterTransactionAbortOnError, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTransactionDefaultIsolationLevel(expected sdk.TransactionDefaultIsolationLevel) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTwoDigitCenturyStart(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterTwoDigitCenturyStart, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasUnsupportedDdlAction(expected sdk.UnsupportedDDLAction) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterStringUnderlyingValueSet(sdk.UserParameterUnsupportedDdlAction, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasUseCachedResult(expected bool) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterBoolValueSet(sdk.UserParameterUseCachedResult, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasWeekOfYearPolicy(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterWeekOfYearPolicy, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasWeekStart(expected int) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterIntValueSet(sdk.UserParameterWeekStart, expected)) + return u +} + +//////////////////////////// +// Parameter level checks // +//////////////////////////// + +func (u *UserResourceParametersAssert) HasEnableUnredactedQuerySyntaxErrorLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterEnableUnredactedQuerySyntaxError, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasNetworkPolicyLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterNetworkPolicy, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasPreventUnloadToInternalStagesLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterPreventUnloadToInternalStages, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasAbortDetachedQueryLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterAbortDetachedQuery, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasAutocommitLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterAutocommit, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasBinaryInputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterBinaryInputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasBinaryOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterBinaryOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientMemoryLimitLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterClientMemoryLimit, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientMetadataRequestUseConnectionCtxLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterClientMetadataRequestUseConnectionCtx, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientPrefetchThreadsLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterClientPrefetchThreads, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientResultChunkSizeLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterClientResultChunkSize, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientResultColumnCaseInsensitiveLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterClientResultColumnCaseInsensitive, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientSessionKeepAliveLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterClientSessionKeepAlive, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientSessionKeepAliveHeartbeatFrequencyLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterClientSessionKeepAliveHeartbeatFrequency, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasClientTimestampTypeMappingLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterClientTimestampTypeMapping, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasDateInputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterDateInputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasDateOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterDateOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasEnableUnloadPhysicalTypeOptimizationLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterEnableUnloadPhysicalTypeOptimization, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasErrorOnNondeterministicMergeLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterErrorOnNondeterministicMerge, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasErrorOnNondeterministicUpdateLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterErrorOnNondeterministicUpdate, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasGeographyOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterGeographyOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasGeometryOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterGeometryOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasJdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterJdbcTreatDecimalAsInt, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasJdbcTreatTimestampNtzAsUtcLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterJdbcTreatTimestampNtzAsUtc, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasJdbcUseSessionTimezoneLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterJdbcUseSessionTimezone, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasJsonIndentLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterJsonIndent, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasLockTimeoutLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterLockTimeout, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasLogLevelLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterLogLevel, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasMultiStatementCountLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterMultiStatementCount, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasNoorderSequenceAsDefaultLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterNoorderSequenceAsDefault, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasOdbcTreatDecimalAsIntLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterOdbcTreatDecimalAsInt, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasQueryTagLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterQueryTag, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasQuotedIdentifiersIgnoreCaseLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterQuotedIdentifiersIgnoreCase, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasRowsPerResultsetLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterRowsPerResultset, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasS3StageVpceDnsNameLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterS3StageVpceDnsName, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasSearchPathLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterSearchPath, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasSimulatedDataSharingConsumerLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterSimulatedDataSharingConsumer, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasStatementQueuedTimeoutInSecondsLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterStatementQueuedTimeoutInSeconds, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasStatementTimeoutInSecondsLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterStatementTimeoutInSeconds, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasStrictJsonOutputLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterStrictJsonOutput, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampDayIsAlways24hLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimestampDayIsAlways24h, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampInputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimestampInputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampLtzOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimestampLtzOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampNtzOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimestampNtzOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimestampOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampTypeMappingLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimestampTypeMapping, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimestampTzOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimestampTzOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimezoneLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimezone, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimeInputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimeInputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTimeOutputFormatLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTimeOutputFormat, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTraceLevelLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTraceLevel, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTransactionAbortOnErrorLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTransactionAbortOnError, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTransactionDefaultIsolationLevelLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTransactionDefaultIsolationLevel, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasTwoDigitCenturyStartLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterTwoDigitCenturyStart, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasUnsupportedDdlActionLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterUnsupportedDdlAction, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasUseCachedResultLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterUseCachedResult, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasWeekOfYearPolicyLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterWeekOfYearPolicy, expected)) + return u +} + +func (u *UserResourceParametersAssert) HasWeekStartLevel(expected sdk.ParameterType) *UserResourceParametersAssert { + u.AddAssertion(assert.ResourceParameterLevelSet(sdk.UserParameterWeekStart, expected)) + return u +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/warehouse_parameters_ext.go b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/warehouse_parameters_ext.go new file mode 100644 index 0000000000..791386d56a --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/warehouse_parameters_ext.go @@ -0,0 +1,19 @@ +package resourceparametersassert + +func (w *WarehouseResourceParametersAssert) HasDefaultMaxConcurrencyLevel() *WarehouseResourceParametersAssert { + return w. + HasMaxConcurrencyLevel(8). + HasMaxConcurrencyLevelLevel("") +} + +func (w *WarehouseResourceParametersAssert) HasDefaultStatementQueuedTimeoutInSeconds() *WarehouseResourceParametersAssert { + return w. + HasStatementQueuedTimeoutInSeconds(0). + HasStatementQueuedTimeoutInSecondsLevel("") +} + +func (w *WarehouseResourceParametersAssert) HasDefaultStatementTimeoutInSeconds() *WarehouseResourceParametersAssert { + return w. + HasStatementTimeoutInSeconds(172800). + HasStatementTimeoutInSecondsLevel("") +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/warehouse_resource_parameters_gen.go b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/warehouse_resource_parameters_gen.go new file mode 100644 index 0000000000..b5b283946a --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/warehouse_resource_parameters_gen.go @@ -0,0 +1,72 @@ +// Code generated by assertions generator; DO NOT EDIT. + +package resourceparametersassert + +import ( + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +type WarehouseResourceParametersAssert struct { + *assert.ResourceAssert +} + +func WarehouseResourceParameters(t *testing.T, name string) *WarehouseResourceParametersAssert { + t.Helper() + + w := WarehouseResourceParametersAssert{ + ResourceAssert: assert.NewResourceAssert(name, "parameters"), + } + w.AddAssertion(assert.ValueSet("parameters.#", "1")) + return &w +} + +func ImportedWarehouseResourceParameters(t *testing.T, id string) *WarehouseResourceParametersAssert { + t.Helper() + + w := WarehouseResourceParametersAssert{ + ResourceAssert: assert.NewImportedResourceAssert(id, "imported parameters"), + } + w.AddAssertion(assert.ValueSet("parameters.#", "1")) + return &w +} + +//////////////////////////// +// Parameter value checks // +//////////////////////////// + +func (w *WarehouseResourceParametersAssert) HasMaxConcurrencyLevel(expected int) *WarehouseResourceParametersAssert { + w.AddAssertion(assert.ResourceParameterIntValueSet(sdk.WarehouseParameterMaxConcurrencyLevel, expected)) + return w +} + +func (w *WarehouseResourceParametersAssert) HasStatementQueuedTimeoutInSeconds(expected int) *WarehouseResourceParametersAssert { + w.AddAssertion(assert.ResourceParameterIntValueSet(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds, expected)) + return w +} + +func (w *WarehouseResourceParametersAssert) HasStatementTimeoutInSeconds(expected int) *WarehouseResourceParametersAssert { + w.AddAssertion(assert.ResourceParameterIntValueSet(sdk.WarehouseParameterStatementTimeoutInSeconds, expected)) + return w +} + +//////////////////////////// +// Parameter level checks // +//////////////////////////// + +func (w *WarehouseResourceParametersAssert) HasMaxConcurrencyLevelLevel(expected sdk.ParameterType) *WarehouseResourceParametersAssert { + w.AddAssertion(assert.ResourceParameterLevelSet(sdk.WarehouseParameterMaxConcurrencyLevel, expected)) + return w +} + +func (w *WarehouseResourceParametersAssert) HasStatementQueuedTimeoutInSecondsLevel(expected sdk.ParameterType) *WarehouseResourceParametersAssert { + w.AddAssertion(assert.ResourceParameterLevelSet(sdk.WarehouseParameterStatementQueuedTimeoutInSeconds, expected)) + return w +} + +func (w *WarehouseResourceParametersAssert) HasStatementTimeoutInSecondsLevel(expected sdk.ParameterType) *WarehouseResourceParametersAssert { + w.AddAssertion(assert.ResourceParameterLevelSet(sdk.WarehouseParameterStatementTimeoutInSeconds, expected)) + return w +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/main/main.go b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/main/main.go new file mode 100644 index 0000000000..1aeb3245f3 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/main/main.go @@ -0,0 +1,24 @@ +//go:build exclude + +package main + +import ( + objectassertgen "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert/gen" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +func main() { + genhelpers.NewGenerator( + objectassertgen.GetSdkObjectDetails, + gen.ModelFromSdkObjectDetails, + getFilename, + gen.AllTemplates, + ). + RunAndHandleOsReturn() +} + +func getFilename(_ genhelpers.SdkObjectDetails, model gen.ResourceShowOutputAssertionsModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_show_output" + "_gen.go" +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/model.go b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/model.go new file mode 100644 index 0000000000..1ee193246b --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/model.go @@ -0,0 +1,85 @@ +package gen + +import ( + "os" + "strings" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +// TODO [SNOW-1501905]: extract to commons? +type PreambleModel struct { + PackageName string + AdditionalStandardImports []string +} + +type ResourceShowOutputAssertionsModel struct { + Name string + Attributes []ResourceShowOutputAssertionModel + PreambleModel +} + +func (m ResourceShowOutputAssertionsModel) SomeFunc() { +} + +type ResourceShowOutputAssertionModel struct { + Name string + ConcreteType string + AssertionCreator string + Mapper genhelpers.Mapper +} + +func ModelFromSdkObjectDetails(sdkObject genhelpers.SdkObjectDetails) ResourceShowOutputAssertionsModel { + attributes := make([]ResourceShowOutputAssertionModel, len(sdkObject.Fields)) + for idx, field := range sdkObject.Fields { + attributes[idx] = MapToResourceShowOutputAssertion(field) + } + + name, _ := strings.CutPrefix(sdkObject.Name, "sdk.") + packageWithGenerateDirective := os.Getenv("GOPACKAGE") + return ResourceShowOutputAssertionsModel{ + Name: name, + Attributes: attributes, + PreambleModel: PreambleModel{ + PackageName: packageWithGenerateDirective, + AdditionalStandardImports: genhelpers.AdditionalStandardImports(sdkObject.Fields), + }, + } +} + +func MapToResourceShowOutputAssertion(field genhelpers.Field) ResourceShowOutputAssertionModel { + concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") + // TODO [SNOW-1501905]: get a runtime name for the assertion creator + var assertionCreator string + switch { + case concreteTypeWithoutPtr == "bool": + assertionCreator = "ResourceShowOutputBoolValueSet" + case concreteTypeWithoutPtr == "int": + assertionCreator = "ResourceShowOutputIntValueSet" + case concreteTypeWithoutPtr == "float64": + assertionCreator = "ResourceShowOutputFloatValueSet" + case concreteTypeWithoutPtr == "string": + assertionCreator = "ResourceShowOutputValueSet" + // TODO [SNOW-1501905]: distinguish between different enum types + case strings.HasPrefix(concreteTypeWithoutPtr, "sdk."): + assertionCreator = "ResourceShowOutputStringUnderlyingValueSet" + default: + assertionCreator = "ResourceShowOutputValueSet" + } + + // TODO [SNOW-1501905]: handle other mappings if needed + mapper := genhelpers.Identity + switch concreteTypeWithoutPtr { + case "sdk.AccountObjectIdentifier": + mapper = genhelpers.Name + case "time.Time": + mapper = genhelpers.ToString + } + + return ResourceShowOutputAssertionModel{ + Name: field.Name, + ConcreteType: concreteTypeWithoutPtr, + AssertionCreator: assertionCreator, + Mapper: mapper, + } +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates.go b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates.go new file mode 100644 index 0000000000..0384103bb8 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates.go @@ -0,0 +1,33 @@ +package gen + +import ( + "text/template" + + _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + + //go:embed templates/definition.tmpl + definitionTemplateContent string + DefinitionTemplate, _ = template.New("definitionTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + )).Parse(definitionTemplateContent) + + //go:embed templates/assertions.tmpl + assertionsTemplateContent string + AssertionsTemplate, _ = template.New("assertionsTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + genhelpers.SnakeCase, + genhelpers.RunMapper, + )).Parse(assertionsTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, DefinitionTemplate, AssertionsTemplate} +) diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/assertions.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/assertions.tmpl new file mode 100644 index 0000000000..33c6b3a141 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/assertions.tmpl @@ -0,0 +1,16 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen.ResourceParametersAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sShowOutputAssert" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $assertVar := FirstLetter $nameLowerCase }} +//////////////////////////// +// Attribute value checks // +//////////////////////////// + +{{ range .Attributes -}} + func ({{ $assertVar }} *{{ $assertName }}) Has{{ .Name }}(expected {{ .ConcreteType }}) *{{ $assertName }} { + {{ $assertVar }}.AddAssertion(assert.{{ .AssertionCreator }}("{{ SnakeCase .Name }}", {{ RunMapper .Mapper "expected" }})) + return {{ $assertVar }} + } + +{{ end -}} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/definition.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/definition.tmpl new file mode 100644 index 0000000000..62df9799b9 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/definition.tmpl @@ -0,0 +1,28 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceparametersassert/gen.ResourceParametersAssertionsModel*/ -}} + +{{- $assertName := .Name | printf "%sShowOutputAssert" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $assertVar := FirstLetter $nameLowerCase }} +type {{ $assertName }} struct { +*assert.ResourceAssert +} + +func {{ .Name }}ShowOutput(t *testing.T, name string) *{{ $assertName }} { + t.Helper() + + {{ $assertVar }} := {{ $assertName }}{ + ResourceAssert: assert.NewResourceAssert(name, "show_output"), + } + {{ $assertVar }}.AddAssertion(assert.ValueSet("show_output.#", "1")) + return &{{ $assertVar }} +} + +func Imported{{ .Name }}ShowOutput(t *testing.T, id string) *{{ $assertName }} { + t.Helper() + + {{ $assertVar }} := {{ $assertName }}{ + ResourceAssert: assert.NewImportedResourceAssert(id, "show_output"), + } + {{ $assertVar }}.AddAssertion(assert.ValueSet("show_output.#", "1")) + return &{{ $assertVar }} +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/preamble.tmpl new file mode 100644 index 0000000000..b7a2da71d3 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen/templates/preamble.tmpl @@ -0,0 +1,18 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/gen.PreambleModel*/ -}} + +// Code generated by assertions generator; DO NOT EDIT. + +package {{ .PackageName }} + +import ( + "testing" + {{- range .AdditionalStandardImports }} + "{{- . }}" + {{- end }} + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +// to ensure sdk package is used +var _ = sdk.Object{} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/generate.go b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/generate.go new file mode 100644 index 0000000000..ae9dee6cca --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/generate.go @@ -0,0 +1,3 @@ +package resourceshowoutputassert + +//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/user_show_output_gen.go b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/user_show_output_gen.go new file mode 100644 index 0000000000..0e64e7432e --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/user_show_output_gen.go @@ -0,0 +1,172 @@ +// Code generated by assertions generator; DO NOT EDIT. + +package resourceshowoutputassert + +import ( + "testing" + "time" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +// to ensure sdk package is used +var _ = sdk.Object{} + +type UserShowOutputAssert struct { + *assert.ResourceAssert +} + +func UserShowOutput(t *testing.T, name string) *UserShowOutputAssert { + t.Helper() + + u := UserShowOutputAssert{ + ResourceAssert: assert.NewResourceAssert(name, "show_output"), + } + u.AddAssertion(assert.ValueSet("show_output.#", "1")) + return &u +} + +func ImportedUserShowOutput(t *testing.T, id string) *UserShowOutputAssert { + t.Helper() + + u := UserShowOutputAssert{ + ResourceAssert: assert.NewImportedResourceAssert(id, "show_output"), + } + u.AddAssertion(assert.ValueSet("show_output.#", "1")) + return &u +} + +//////////////////////////// +// Attribute value checks // +//////////////////////////// + +func (u *UserShowOutputAssert) HasName(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("name", expected)) + return u +} + +func (u *UserShowOutputAssert) HasCreatedOn(expected time.Time) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("created_on", expected.String())) + return u +} + +func (u *UserShowOutputAssert) HasLoginName(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("login_name", expected)) + return u +} + +func (u *UserShowOutputAssert) HasDisplayName(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("display_name", expected)) + return u +} + +func (u *UserShowOutputAssert) HasFirstName(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("first_name", expected)) + return u +} + +func (u *UserShowOutputAssert) HasLastName(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("last_name", expected)) + return u +} + +func (u *UserShowOutputAssert) HasEmail(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("email", expected)) + return u +} + +func (u *UserShowOutputAssert) HasMinsToUnlock(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("mins_to_unlock", expected)) + return u +} + +func (u *UserShowOutputAssert) HasDaysToExpiry(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("days_to_expiry", expected)) + return u +} + +func (u *UserShowOutputAssert) HasComment(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("comment", expected)) + return u +} + +func (u *UserShowOutputAssert) HasDisabled(expected bool) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputBoolValueSet("disabled", expected)) + return u +} + +func (u *UserShowOutputAssert) HasMustChangePassword(expected bool) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputBoolValueSet("must_change_password", expected)) + return u +} + +func (u *UserShowOutputAssert) HasSnowflakeLock(expected bool) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputBoolValueSet("snowflake_lock", expected)) + return u +} + +func (u *UserShowOutputAssert) HasDefaultWarehouse(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("default_warehouse", expected)) + return u +} + +func (u *UserShowOutputAssert) HasDefaultNamespace(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("default_namespace", expected)) + return u +} + +func (u *UserShowOutputAssert) HasDefaultRole(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("default_role", expected)) + return u +} + +func (u *UserShowOutputAssert) HasDefaultSecondaryRoles(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("default_secondary_roles", expected)) + return u +} + +func (u *UserShowOutputAssert) HasExtAuthnDuo(expected bool) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputBoolValueSet("ext_authn_duo", expected)) + return u +} + +func (u *UserShowOutputAssert) HasExtAuthnUid(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("ext_authn_uid", expected)) + return u +} + +func (u *UserShowOutputAssert) HasMinsToBypassMfa(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("mins_to_bypass_mfa", expected)) + return u +} + +func (u *UserShowOutputAssert) HasOwner(expected string) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("owner", expected)) + return u +} + +func (u *UserShowOutputAssert) HasLastSuccessLogin(expected time.Time) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("last_success_login", expected.String())) + return u +} + +func (u *UserShowOutputAssert) HasExpiresAtTime(expected time.Time) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("expires_at_time", expected.String())) + return u +} + +func (u *UserShowOutputAssert) HasLockedUntilTime(expected time.Time) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputValueSet("locked_until_time", expected.String())) + return u +} + +func (u *UserShowOutputAssert) HasHasPassword(expected bool) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputBoolValueSet("has_password", expected)) + return u +} + +func (u *UserShowOutputAssert) HasHasRsaPublicKey(expected bool) *UserShowOutputAssert { + u.AddAssertion(assert.ResourceShowOutputBoolValueSet("has_rsa_public_key", expected)) + return u +} diff --git a/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/warehouse_show_output_gen.go b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/warehouse_show_output_gen.go new file mode 100644 index 0000000000..173e2870ac --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/warehouse_show_output_gen.go @@ -0,0 +1,177 @@ +// Code generated by assertions generator; DO NOT EDIT. + +package resourceshowoutputassert + +import ( + "testing" + "time" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +// to ensure sdk package is used +var _ = sdk.Object{} + +type WarehouseShowOutputAssert struct { + *assert.ResourceAssert +} + +func WarehouseShowOutput(t *testing.T, name string) *WarehouseShowOutputAssert { + t.Helper() + + w := WarehouseShowOutputAssert{ + ResourceAssert: assert.NewResourceAssert(name, "show_output"), + } + w.AddAssertion(assert.ValueSet("show_output.#", "1")) + return &w +} + +func ImportedWarehouseShowOutput(t *testing.T, id string) *WarehouseShowOutputAssert { + t.Helper() + + w := WarehouseShowOutputAssert{ + ResourceAssert: assert.NewImportedResourceAssert(id, "show_output"), + } + w.AddAssertion(assert.ValueSet("show_output.#", "1")) + return &w +} + +//////////////////////////// +// Attribute value checks // +//////////////////////////// + +func (w *WarehouseShowOutputAssert) HasName(expected string) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputValueSet("name", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasState(expected sdk.WarehouseState) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputStringUnderlyingValueSet("state", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasType(expected sdk.WarehouseType) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputStringUnderlyingValueSet("type", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasSize(expected sdk.WarehouseSize) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputStringUnderlyingValueSet("size", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasMinClusterCount(expected int) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputIntValueSet("min_cluster_count", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasMaxClusterCount(expected int) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputIntValueSet("max_cluster_count", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasStartedClusters(expected int) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputIntValueSet("started_clusters", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasRunning(expected int) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputIntValueSet("running", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasQueued(expected int) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputIntValueSet("queued", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasIsDefault(expected bool) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputBoolValueSet("is_default", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasIsCurrent(expected bool) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputBoolValueSet("is_current", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasAutoSuspend(expected int) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputIntValueSet("auto_suspend", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasAutoResume(expected bool) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputBoolValueSet("auto_resume", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasAvailable(expected float64) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputFloatValueSet("available", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasProvisioning(expected float64) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputFloatValueSet("provisioning", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasQuiescing(expected float64) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputFloatValueSet("quiescing", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasOther(expected float64) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputFloatValueSet("other", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasCreatedOn(expected time.Time) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputValueSet("created_on", expected.String())) + return w +} + +func (w *WarehouseShowOutputAssert) HasResumedOn(expected time.Time) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputValueSet("resumed_on", expected.String())) + return w +} + +func (w *WarehouseShowOutputAssert) HasUpdatedOn(expected time.Time) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputValueSet("updated_on", expected.String())) + return w +} + +func (w *WarehouseShowOutputAssert) HasOwner(expected string) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputValueSet("owner", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasComment(expected string) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputValueSet("comment", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasEnableQueryAcceleration(expected bool) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputBoolValueSet("enable_query_acceleration", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasQueryAccelerationMaxScaleFactor(expected int) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputIntValueSet("query_acceleration_max_scale_factor", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasResourceMonitor(expected sdk.AccountObjectIdentifier) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputStringUnderlyingValueSet("resource_monitor", expected.Name())) + return w +} + +func (w *WarehouseShowOutputAssert) HasScalingPolicy(expected sdk.ScalingPolicy) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputStringUnderlyingValueSet("scaling_policy", expected)) + return w +} + +func (w *WarehouseShowOutputAssert) HasOwnerRoleType(expected string) *WarehouseShowOutputAssert { + w.AddAssertion(assert.ResourceShowOutputValueSet("owner_role_type", expected)) + return w +} diff --git a/pkg/acceptance/bettertestspoc/assert/warehouse_parameters.go b/pkg/acceptance/bettertestspoc/assert/warehouse_parameters.go deleted file mode 100644 index 169ea17955..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/warehouse_parameters.go +++ /dev/null @@ -1,60 +0,0 @@ -package assert - -import ( - "strconv" - "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" -) - -type WarehouseParametersAssert struct { - *ResourceAssert -} - -func WarehouseParameters(t *testing.T, name string) *WarehouseParametersAssert { - t.Helper() - w := WarehouseParametersAssert{ - NewResourceAssert(name, "parameters"), - } - w.assertions = append(w.assertions, valueSet("parameters.#", "1")) - return &w -} - -func ImportedWarehouseParameters(t *testing.T, id string) *WarehouseParametersAssert { - t.Helper() - w := WarehouseParametersAssert{ - NewImportedResourceAssert(id, "imported parameters"), - } - w.assertions = append(w.assertions, valueSet("parameters.#", "1")) - return &w -} - -func (w *WarehouseParametersAssert) HasMaxConcurrencyLevel(expected int) *WarehouseParametersAssert { - w.assertions = append(w.assertions, parameterValueSet("max_concurrency_level", strconv.Itoa(expected))) - return w -} - -func (w *WarehouseParametersAssert) HasStatementQueuedTimeoutInSeconds(expected int) *WarehouseParametersAssert { - w.assertions = append(w.assertions, parameterValueSet("statement_queued_timeout_in_seconds", strconv.Itoa(expected))) - return w -} - -func (w *WarehouseParametersAssert) HasStatementTimeoutInSeconds(expected int) *WarehouseParametersAssert { - w.assertions = append(w.assertions, parameterValueSet("statement_timeout_in_seconds", strconv.Itoa(expected))) - return w -} - -func (w *WarehouseParametersAssert) HasMaxConcurrencyLevelLevel(expected sdk.ParameterType) *WarehouseParametersAssert { - w.assertions = append(w.assertions, parameterLevelSet("max_concurrency_level", string(expected))) - return w -} - -func (w *WarehouseParametersAssert) HasStatementQueuedTimeoutInSecondsLevel(expected sdk.ParameterType) *WarehouseParametersAssert { - w.assertions = append(w.assertions, parameterLevelSet("statement_queued_timeout_in_seconds", string(expected))) - return w -} - -func (w *WarehouseParametersAssert) HasStatementTimeoutInSecondsLevel(expected sdk.ParameterType) *WarehouseParametersAssert { - w.assertions = append(w.assertions, parameterLevelSet("statement_timeout_in_seconds", string(expected))) - return w -} diff --git a/pkg/acceptance/bettertestspoc/assert/warehouse_parameters_ext.go b/pkg/acceptance/bettertestspoc/assert/warehouse_parameters_ext.go deleted file mode 100644 index 4e3a3ad231..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/warehouse_parameters_ext.go +++ /dev/null @@ -1,19 +0,0 @@ -package assert - -func (w *WarehouseParametersAssert) HasDefaultMaxConcurrencyLevel() *WarehouseParametersAssert { - return w. - HasMaxConcurrencyLevel(8). - HasMaxConcurrencyLevelLevel("") -} - -func (w *WarehouseParametersAssert) HasDefaultStatementQueuedTimeoutInSeconds() *WarehouseParametersAssert { - return w. - HasStatementQueuedTimeoutInSeconds(0). - HasStatementQueuedTimeoutInSecondsLevel("") -} - -func (w *WarehouseParametersAssert) HasDefaultStatementTimeoutInSeconds() *WarehouseParametersAssert { - return w. - HasStatementTimeoutInSeconds(172800). - HasStatementTimeoutInSecondsLevel("") -} diff --git a/pkg/acceptance/bettertestspoc/assert/warehouse_resource.go b/pkg/acceptance/bettertestspoc/assert/warehouse_resource.go deleted file mode 100644 index 474f59a387..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/warehouse_resource.go +++ /dev/null @@ -1,185 +0,0 @@ -package assert - -import ( - "testing" -) - -type WarehouseResourceAssert struct { - *ResourceAssert -} - -func WarehouseResource(t *testing.T, name string) *WarehouseResourceAssert { - t.Helper() - - return &WarehouseResourceAssert{ - ResourceAssert: NewResourceAssert(name, "resource"), - } -} - -func ImportedWarehouseResource(t *testing.T, id string) *WarehouseResourceAssert { - t.Helper() - - return &WarehouseResourceAssert{ - ResourceAssert: NewImportedResourceAssert(id, "imported resource"), - } -} - -func (w *WarehouseResourceAssert) HasName(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("name", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasType(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("warehouse_type", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasSize(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("warehouse_size", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasMaxClusterCount(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("max_cluster_count", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasMinClusterCount(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("min_cluster_count", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasScalingPolicy(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("scaling_policy", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasAutoSuspend(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("auto_suspend", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasAutoResume(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("auto_resume", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasInitiallySuspended(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("initially_suspended", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasResourceMonitor(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("resource_monitor", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasComment(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("comment", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasEnableQueryAcceleration(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("enable_query_acceleration", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasQueryAccelerationMaxScaleFactor(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("query_acceleration_max_scale_factor", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasMaxConcurrencyLevel(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("max_concurrency_level", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasStatementQueuedTimeoutInSeconds(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("statement_queued_timeout_in_seconds", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasStatementTimeoutInSeconds(expected string) *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueSet("statement_timeout_in_seconds", expected)) - return w -} - -func (w *WarehouseResourceAssert) HasNoName() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("name")) - return w -} - -func (w *WarehouseResourceAssert) HasNoType() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("warehouse_type")) - return w -} - -func (w *WarehouseResourceAssert) HasNoSize() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("warehouse_size")) - return w -} - -func (w *WarehouseResourceAssert) HasNoMaxClusterCount() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("max_cluster_count")) - return w -} - -func (w *WarehouseResourceAssert) HasNoMinClusterCount() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("min_cluster_count")) - return w -} - -func (w *WarehouseResourceAssert) HasNoScalingPolicy() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("scaling_policy")) - return w -} - -func (w *WarehouseResourceAssert) HasNoAutoSuspend() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("auto_suspend")) - return w -} - -func (w *WarehouseResourceAssert) HasNoAutoResume() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("auto_resume")) - return w -} - -func (w *WarehouseResourceAssert) HasNoInitiallySuspended() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("initially_suspended")) - return w -} - -func (w *WarehouseResourceAssert) HasNoResourceMonitor() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("resource_monitor")) - return w -} - -func (w *WarehouseResourceAssert) HasNoComment() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("comment")) - return w -} - -func (w *WarehouseResourceAssert) HasNoEnableQueryAcceleration() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("enable_query_acceleration")) - return w -} - -func (w *WarehouseResourceAssert) HasNoQueryAccelerationMaxScaleFactor() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("query_acceleration_max_scale_factor")) - return w -} - -func (w *WarehouseResourceAssert) HasNoMaxConcurrencyLevel() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("max_concurrency_level")) - return w -} - -func (w *WarehouseResourceAssert) HasNoStatementQueuedTimeoutInSeconds() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("statement_queued_timeout_in_seconds")) - return w -} - -func (w *WarehouseResourceAssert) HasNoStatementTimeoutInSeconds() *WarehouseResourceAssert { - w.assertions = append(w.assertions, valueNotSet("statement_timeout_in_seconds")) - return w -} diff --git a/pkg/acceptance/bettertestspoc/assert/warehouse_show_output.go b/pkg/acceptance/bettertestspoc/assert/warehouse_show_output.go deleted file mode 100644 index 068d97f76e..0000000000 --- a/pkg/acceptance/bettertestspoc/assert/warehouse_show_output.go +++ /dev/null @@ -1,85 +0,0 @@ -package assert - -import ( - "strconv" - "testing" - - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" -) - -type WarehouseShowOutputAssert struct { - *ResourceAssert -} - -func WarehouseShowOutput(t *testing.T, name string) *WarehouseShowOutputAssert { - t.Helper() - w := WarehouseShowOutputAssert{ - NewResourceAssert(name, "show_output"), - } - w.assertions = append(w.assertions, valueSet("show_output.#", "1")) - return &w -} - -func ImportedWarehouseShowOutput(t *testing.T, id string) *WarehouseShowOutputAssert { - t.Helper() - w := WarehouseShowOutputAssert{ - NewImportedResourceAssert(id, "show_output"), - } - w.assertions = append(w.assertions, valueSet("show_output.#", "1")) - return &w -} - -func (w *WarehouseShowOutputAssert) HasType(expected sdk.WarehouseType) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("type", string(expected))) - return w -} - -func (w *WarehouseShowOutputAssert) HasSize(expected sdk.WarehouseSize) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("size", string(expected))) - return w -} - -func (w *WarehouseShowOutputAssert) HasMaxClusterCount(expected int) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("max_cluster_count", strconv.Itoa(expected))) - return w -} - -func (w *WarehouseShowOutputAssert) HasMinClusterCount(expected int) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("min_cluster_count", strconv.Itoa(expected))) - return w -} - -func (w *WarehouseShowOutputAssert) HasScalingPolicy(expected sdk.ScalingPolicy) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("scaling_policy", string(expected))) - return w -} - -func (w *WarehouseShowOutputAssert) HasAutoSuspend(expected int) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("auto_suspend", strconv.Itoa(expected))) - return w -} - -func (w *WarehouseShowOutputAssert) HasAutoResume(expected bool) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("auto_resume", strconv.FormatBool(expected))) - return w -} - -func (w *WarehouseShowOutputAssert) HasResourceMonitor(expected string) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("resource_monitor", expected)) - return w -} - -func (w *WarehouseShowOutputAssert) HasComment(expected string) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("comment", expected)) - return w -} - -func (w *WarehouseShowOutputAssert) HasEnableQueryAcceleration(expected bool) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("enable_query_acceleration", strconv.FormatBool(expected))) - return w -} - -func (w *WarehouseShowOutputAssert) HasQueryAccelerationMaxScaleFactor(expected int) *WarehouseShowOutputAssert { - w.assertions = append(w.assertions, showOutputValueSet("query_acceleration_max_scale_factor", strconv.Itoa(expected))) - return w -} diff --git a/pkg/acceptance/bettertestspoc/config/config.go b/pkg/acceptance/bettertestspoc/config/config.go index b38c9c6bc0..1119f4d0bc 100644 --- a/pkg/acceptance/bettertestspoc/config/config.go +++ b/pkg/acceptance/bettertestspoc/config/config.go @@ -10,46 +10,50 @@ import ( "github.com/stretchr/testify/require" ) +// TODO [SNOW-1501905]: add possibility to have reference to another object (e.g. WithResourceMonitorReference); new config.Variable impl? +// TODO [SNOW-1501905]: add possibility to have depends_on to other resources (in meta?) +// TODO [SNOW-1501905]: add a convenience method to use multiple configs from multiple models + // ResourceModel is the base interface all of our config models will implement. -// To allow easy implementation, resourceModelMeta can be embedded inside the struct (and the struct will automatically implement it). +// To allow easy implementation, ResourceModelMeta can be embedded inside the struct (and the struct will automatically implement it). type ResourceModel interface { Resource() resources.Resource ResourceName() string SetResourceName(name string) } -type resourceModelMeta struct { +type ResourceModelMeta struct { name string resource resources.Resource } -func (m *resourceModelMeta) Resource() resources.Resource { +func (m *ResourceModelMeta) Resource() resources.Resource { return m.resource } -func (m *resourceModelMeta) ResourceName() string { +func (m *ResourceModelMeta) ResourceName() string { return m.name } -func (m *resourceModelMeta) SetResourceName(name string) { +func (m *ResourceModelMeta) SetResourceName(name string) { m.name = name } // DefaultResourceName is exported to allow assertions against the resources using the default name. const DefaultResourceName = "test" -func defaultMeta(resource resources.Resource) *resourceModelMeta { - return &resourceModelMeta{name: DefaultResourceName, resource: resource} +func DefaultMeta(resource resources.Resource) *ResourceModelMeta { + return &ResourceModelMeta{name: DefaultResourceName, resource: resource} } -func meta(resourceName string, resource resources.Resource) *resourceModelMeta { - return &resourceModelMeta{name: resourceName, resource: resource} +func Meta(resourceName string, resource resources.Resource) *ResourceModelMeta { + return &ResourceModelMeta{name: resourceName, resource: resource} } // FromModel should be used in terraform acceptance tests for Config attribute to get string config from ResourceModel. // Current implementation is really straightforward but it could be improved and tested. It may not handle all cases (like objects, lists, sets) correctly. -// TODO: use reflection to build config directly from model struct (or some other different way) -// TODO: add support for config.TestStepConfigFunc (to use as ConfigFile); the naive implementation would be to just create a tmp directory and save file there +// TODO [SNOW-1501905]: use reflection to build config directly from model struct (or some other different way) +// TODO [SNOW-1501905]: add support for config.TestStepConfigFunc (to use as ConfigFile); the naive implementation would be to just create a tmp directory and save file there func FromModel(t *testing.T, model ResourceModel) string { t.Helper() diff --git a/pkg/acceptance/bettertestspoc/config/model/gen/main/main.go b/pkg/acceptance/bettertestspoc/config/model/gen/main/main.go new file mode 100644 index 0000000000..1b2e7ecc86 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/gen/main/main.go @@ -0,0 +1,22 @@ +package main + +import ( + resourceassertgen "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceassert/gen" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +func main() { + genhelpers.NewGenerator( + resourceassertgen.GetResourceSchemaDetails, + gen.ModelFromResourceSchemaDetails, + getFilename, + gen.AllTemplates, + ). + RunAndHandleOsReturn() +} + +func getFilename(_ genhelpers.ResourceSchemaDetails, model gen.ResourceConfigBuilderModel) string { + return genhelpers.ToSnakeCase(model.Name) + "_model" + "_gen.go" +} diff --git a/pkg/acceptance/bettertestspoc/config/model/gen/model.go b/pkg/acceptance/bettertestspoc/config/model/gen/model.go new file mode 100644 index 0000000000..2e5a2da525 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/gen/model.go @@ -0,0 +1,75 @@ +package gen + +import ( + "os" + "slices" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// TODO [SNOW-1501905]: extract to commons? +type PreambleModel struct { + PackageName string + AdditionalStandardImports []string +} + +type ResourceConfigBuilderModel struct { + Name string + Attributes []ResourceConfigBuilderAttributeModel + PreambleModel +} + +func (m ResourceConfigBuilderModel) SomeFunc() { +} + +type ResourceConfigBuilderAttributeModel struct { + Name string + AttributeType string + Required bool + VariableMethod string +} + +func ModelFromResourceSchemaDetails(resourceSchemaDetails genhelpers.ResourceSchemaDetails) ResourceConfigBuilderModel { + attributes := make([]ResourceConfigBuilderAttributeModel, 0) + for _, attr := range resourceSchemaDetails.Attributes { + if slices.Contains([]string{resources.ShowOutputAttributeName, resources.ParametersAttributeName, resources.DescribeOutputAttributeName}, attr.Name) { + continue + } + + // TODO [SNOW-1501905]: support the rest of attribute types + var attributeType string + var variableMethod string + switch attr.AttributeType { + case schema.TypeBool: + attributeType = "bool" + variableMethod = "BoolVariable" + case schema.TypeInt: + attributeType = "int" + variableMethod = "IntegerVariable" + case schema.TypeFloat: + attributeType = "float" + variableMethod = "FloatVariable" + case schema.TypeString: + attributeType = "string" + variableMethod = "StringVariable" + } + + attributes = append(attributes, ResourceConfigBuilderAttributeModel{ + Name: attr.Name, + AttributeType: attributeType, + Required: attr.Required, + VariableMethod: variableMethod, + }) + } + + packageWithGenerateDirective := os.Getenv("GOPACKAGE") + return ResourceConfigBuilderModel{ + Name: resourceSchemaDetails.ObjectName(), + Attributes: attributes, + PreambleModel: PreambleModel{ + PackageName: packageWithGenerateDirective, + }, + } +} diff --git a/pkg/acceptance/bettertestspoc/config/model/gen/templates.go b/pkg/acceptance/bettertestspoc/config/model/gen/templates.go new file mode 100644 index 0000000000..cbb70fff04 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/gen/templates.go @@ -0,0 +1,33 @@ +package gen + +import ( + "text/template" + + _ "embed" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/genhelpers" +) + +var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + + //go:embed templates/definition.tmpl + definitionTemplateContent string + DefinitionTemplate, _ = template.New("definitionTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + genhelpers.SnakeCaseToCamel, + )).Parse(definitionTemplateContent) + + //go:embed templates/builders.tmpl + buildersTemplateContent string + BuildersTemplate, _ = template.New("buildersTemplate").Funcs(genhelpers.BuildTemplateFuncMap( + genhelpers.FirstLetterLowercase, + genhelpers.FirstLetter, + genhelpers.SnakeCaseToCamel, + )).Parse(buildersTemplateContent) + + AllTemplates = []*template.Template{PreambleTemplate, DefinitionTemplate, BuildersTemplate} +) diff --git a/pkg/acceptance/bettertestspoc/config/model/gen/templates/builders.tmpl b/pkg/acceptance/bettertestspoc/config/model/gen/templates/builders.tmpl new file mode 100644 index 0000000000..6dd7a54c7b --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/gen/templates/builders.tmpl @@ -0,0 +1,34 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model/gen.ResourceConfigBuilderModel*/ -}} + +{{- $modelName := .Name | printf "%sModel" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $modelVar := FirstLetter $nameLowerCase }} +///////////////////////////////// +// below all the proper values // +///////////////////////////////// + +{{ range .Attributes -}} + {{- $attributeNameCamel := SnakeCaseToCamel .Name -}} + {{ if .AttributeType }} + func ({{ $modelVar }} *{{ $modelName }}) With{{ $attributeNameCamel }}({{ FirstLetterLowercase $attributeNameCamel }} {{ .AttributeType }}) *{{ $modelName }} { + {{ $modelVar }}.{{ $attributeNameCamel }} = tfconfig.{{ .VariableMethod }}({{ FirstLetterLowercase $attributeNameCamel }}) + return {{ $modelVar }} + } + {{ else }} + // {{ .Name }} attribute type is not yet supported, so With{{ $attributeNameCamel }} can't be generated + {{ end }} + +{{ end -}} + +////////////////////////////////////////// +// below it's possible to set any value // +////////////////////////////////////////// + +{{ range .Attributes -}} + {{- $attributeNameCamel := SnakeCaseToCamel .Name -}} + func ({{ $modelVar }} *{{ $modelName }}) With{{ $attributeNameCamel }}Value(value tfconfig.Variable) *{{ $modelName }} { + {{ $modelVar }}.{{ $attributeNameCamel }} = value + return {{ $modelVar }} + } + +{{ end -}} diff --git a/pkg/acceptance/bettertestspoc/config/model/gen/templates/definition.tmpl b/pkg/acceptance/bettertestspoc/config/model/gen/templates/definition.tmpl new file mode 100644 index 0000000000..76315ef0d7 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/gen/templates/definition.tmpl @@ -0,0 +1,45 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model/gen.ResourceConfigBuilderModel*/ -}} + +{{- $modelName := .Name | printf "%sModel" -}} +{{- $nameLowerCase := FirstLetterLowercase .Name -}} +{{- $modelVar := FirstLetter $nameLowerCase }} + +type {{ $modelName }} struct { + {{ range .Attributes -}} + {{ SnakeCaseToCamel .Name }} tfconfig.Variable `json:"{{ .Name }},omitempty"` + {{ end }} + *config.ResourceModelMeta +} + +///////////////////////////////////////////////// +// Basic builders (resource name and required) // +///////////////////////////////////////////////// + +func {{ .Name }}( + resourceName string, + {{ range .Attributes -}} + {{- $attributeNameCamel := SnakeCaseToCamel .Name -}} + {{ if .Required }}{{ FirstLetterLowercase $attributeNameCamel }} {{ .AttributeType }},{{ end }} + {{- end }} +) *{{ $modelName }} { + {{ $modelVar }} := &{{ $modelName }}{ResourceModelMeta: config.Meta(resourceName, resources.{{ .Name }})} + {{ range .Attributes -}} + {{- $attributeNameCamel := SnakeCaseToCamel .Name -}} + {{ if .Required }}{{ $modelVar }}.With{{ $attributeNameCamel }}({{ FirstLetterLowercase $attributeNameCamel }}) {{ end }} + {{- end }} + return {{ $modelVar }} +} + +func {{ .Name }}WithDefaultMeta( + {{ range .Attributes -}} + {{- $attributeNameCamel := SnakeCaseToCamel .Name -}} + {{ if .Required }}{{ FirstLetterLowercase $attributeNameCamel }} {{ .AttributeType }},{{ end }} + {{- end }} +) *{{ $modelName }} { + {{ $modelVar }} := &{{ $modelName }}{ResourceModelMeta: config.DefaultMeta(resources.{{ .Name }})} + {{ range .Attributes -}} + {{- $attributeNameCamel := SnakeCaseToCamel .Name -}} + {{ if .Required }}{{ $modelVar }}.With{{ $attributeNameCamel }}({{ FirstLetterLowercase $attributeNameCamel }}) {{ end }} + {{- end }} + return {{ $modelVar }} +} diff --git a/pkg/acceptance/bettertestspoc/config/model/gen/templates/preamble.tmpl b/pkg/acceptance/bettertestspoc/config/model/gen/templates/preamble.tmpl new file mode 100644 index 0000000000..b58bd18e74 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/gen/templates/preamble.tmpl @@ -0,0 +1,16 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model/gen.PreambleModel*/ -}} + +// Code generated by config model builder generator; DO NOT EDIT. + +package {{ .PackageName }} + +import ( + {{- range .AdditionalStandardImports }} + "{{- . }}" + {{- end }} + + tfconfig "github.com/hashicorp/terraform-plugin-testing/config" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" +) diff --git a/pkg/acceptance/bettertestspoc/config/model/generate.go b/pkg/acceptance/bettertestspoc/config/model/generate.go new file mode 100644 index 0000000000..a4a6f090b8 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/generate.go @@ -0,0 +1,3 @@ +package model + +//go:generate go run ./gen/main/main.go $SF_TF_GENERATOR_ARGS diff --git a/pkg/acceptance/bettertestspoc/config/model/user_model_gen.go b/pkg/acceptance/bettertestspoc/config/model/user_model_gen.go new file mode 100644 index 0000000000..230ca3a77c --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/user_model_gen.go @@ -0,0 +1,228 @@ +// Code generated by config model builder generator; DO NOT EDIT. + +package model + +import ( + tfconfig "github.com/hashicorp/terraform-plugin-testing/config" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" +) + +type UserModel struct { + Comment tfconfig.Variable `json:"comment,omitempty"` + DefaultNamespace tfconfig.Variable `json:"default_namespace,omitempty"` + DefaultRole tfconfig.Variable `json:"default_role,omitempty"` + DefaultSecondaryRoles tfconfig.Variable `json:"default_secondary_roles,omitempty"` + DefaultWarehouse tfconfig.Variable `json:"default_warehouse,omitempty"` + Disabled tfconfig.Variable `json:"disabled,omitempty"` + DisplayName tfconfig.Variable `json:"display_name,omitempty"` + Email tfconfig.Variable `json:"email,omitempty"` + FirstName tfconfig.Variable `json:"first_name,omitempty"` + HasRsaPublicKey tfconfig.Variable `json:"has_rsa_public_key,omitempty"` + LastName tfconfig.Variable `json:"last_name,omitempty"` + LoginName tfconfig.Variable `json:"login_name,omitempty"` + MustChangePassword tfconfig.Variable `json:"must_change_password,omitempty"` + Name tfconfig.Variable `json:"name,omitempty"` + Password tfconfig.Variable `json:"password,omitempty"` + RsaPublicKey tfconfig.Variable `json:"rsa_public_key,omitempty"` + RsaPublicKey2 tfconfig.Variable `json:"rsa_public_key_2,omitempty"` + + *config.ResourceModelMeta +} + +///////////////////////////////////////////////// +// Basic builders (resource name and required) // +///////////////////////////////////////////////// + +func User( + resourceName string, + name string, +) *UserModel { + u := &UserModel{ResourceModelMeta: config.Meta(resourceName, resources.User)} + u.WithName(name) + return u +} + +func UserWithDefaultMeta( + name string, +) *UserModel { + u := &UserModel{ResourceModelMeta: config.DefaultMeta(resources.User)} + u.WithName(name) + return u +} + +///////////////////////////////// +// below all the proper values // +///////////////////////////////// + +func (u *UserModel) WithComment(comment string) *UserModel { + u.Comment = tfconfig.StringVariable(comment) + return u +} + +func (u *UserModel) WithDefaultNamespace(defaultNamespace string) *UserModel { + u.DefaultNamespace = tfconfig.StringVariable(defaultNamespace) + return u +} + +func (u *UserModel) WithDefaultRole(defaultRole string) *UserModel { + u.DefaultRole = tfconfig.StringVariable(defaultRole) + return u +} + +// default_secondary_roles attribute type is not yet supported, so WithDefaultSecondaryRoles can't be generated + +func (u *UserModel) WithDefaultWarehouse(defaultWarehouse string) *UserModel { + u.DefaultWarehouse = tfconfig.StringVariable(defaultWarehouse) + return u +} + +func (u *UserModel) WithDisabled(disabled bool) *UserModel { + u.Disabled = tfconfig.BoolVariable(disabled) + return u +} + +func (u *UserModel) WithDisplayName(displayName string) *UserModel { + u.DisplayName = tfconfig.StringVariable(displayName) + return u +} + +func (u *UserModel) WithEmail(email string) *UserModel { + u.Email = tfconfig.StringVariable(email) + return u +} + +func (u *UserModel) WithFirstName(firstName string) *UserModel { + u.FirstName = tfconfig.StringVariable(firstName) + return u +} + +func (u *UserModel) WithHasRsaPublicKey(hasRsaPublicKey bool) *UserModel { + u.HasRsaPublicKey = tfconfig.BoolVariable(hasRsaPublicKey) + return u +} + +func (u *UserModel) WithLastName(lastName string) *UserModel { + u.LastName = tfconfig.StringVariable(lastName) + return u +} + +func (u *UserModel) WithLoginName(loginName string) *UserModel { + u.LoginName = tfconfig.StringVariable(loginName) + return u +} + +func (u *UserModel) WithMustChangePassword(mustChangePassword bool) *UserModel { + u.MustChangePassword = tfconfig.BoolVariable(mustChangePassword) + return u +} + +func (u *UserModel) WithName(name string) *UserModel { + u.Name = tfconfig.StringVariable(name) + return u +} + +func (u *UserModel) WithPassword(password string) *UserModel { + u.Password = tfconfig.StringVariable(password) + return u +} + +func (u *UserModel) WithRsaPublicKey(rsaPublicKey string) *UserModel { + u.RsaPublicKey = tfconfig.StringVariable(rsaPublicKey) + return u +} + +func (u *UserModel) WithRsaPublicKey2(rsaPublicKey2 string) *UserModel { + u.RsaPublicKey2 = tfconfig.StringVariable(rsaPublicKey2) + return u +} + +////////////////////////////////////////// +// below it's possible to set any value // +////////////////////////////////////////// + +func (u *UserModel) WithCommentValue(value tfconfig.Variable) *UserModel { + u.Comment = value + return u +} + +func (u *UserModel) WithDefaultNamespaceValue(value tfconfig.Variable) *UserModel { + u.DefaultNamespace = value + return u +} + +func (u *UserModel) WithDefaultRoleValue(value tfconfig.Variable) *UserModel { + u.DefaultRole = value + return u +} + +func (u *UserModel) WithDefaultSecondaryRolesValue(value tfconfig.Variable) *UserModel { + u.DefaultSecondaryRoles = value + return u +} + +func (u *UserModel) WithDefaultWarehouseValue(value tfconfig.Variable) *UserModel { + u.DefaultWarehouse = value + return u +} + +func (u *UserModel) WithDisabledValue(value tfconfig.Variable) *UserModel { + u.Disabled = value + return u +} + +func (u *UserModel) WithDisplayNameValue(value tfconfig.Variable) *UserModel { + u.DisplayName = value + return u +} + +func (u *UserModel) WithEmailValue(value tfconfig.Variable) *UserModel { + u.Email = value + return u +} + +func (u *UserModel) WithFirstNameValue(value tfconfig.Variable) *UserModel { + u.FirstName = value + return u +} + +func (u *UserModel) WithHasRsaPublicKeyValue(value tfconfig.Variable) *UserModel { + u.HasRsaPublicKey = value + return u +} + +func (u *UserModel) WithLastNameValue(value tfconfig.Variable) *UserModel { + u.LastName = value + return u +} + +func (u *UserModel) WithLoginNameValue(value tfconfig.Variable) *UserModel { + u.LoginName = value + return u +} + +func (u *UserModel) WithMustChangePasswordValue(value tfconfig.Variable) *UserModel { + u.MustChangePassword = value + return u +} + +func (u *UserModel) WithNameValue(value tfconfig.Variable) *UserModel { + u.Name = value + return u +} + +func (u *UserModel) WithPasswordValue(value tfconfig.Variable) *UserModel { + u.Password = value + return u +} + +func (u *UserModel) WithRsaPublicKeyValue(value tfconfig.Variable) *UserModel { + u.RsaPublicKey = value + return u +} + +func (u *UserModel) WithRsaPublicKey2Value(value tfconfig.Variable) *UserModel { + u.RsaPublicKey2 = value + return u +} diff --git a/pkg/acceptance/bettertestspoc/config/model/warehouse_model_ext.go b/pkg/acceptance/bettertestspoc/config/model/warehouse_model_ext.go new file mode 100644 index 0000000000..caba4e00e6 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/warehouse_model_ext.go @@ -0,0 +1,19 @@ +package model + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +func BasicWarehouseModel( + name string, + comment string, +) *WarehouseModel { + return WarehouseWithDefaultMeta(name).WithComment(comment) +} + +// TODO [SNOW-1501905]: currently config builder are generated from the resource schema, so there is no direct connection to the source enum (like sdk.WarehouseSize) +// For now, we can just add extension methods manually. +// Later, we could provide type overrides map or even SDK object to automatically match by name. +func (w *WarehouseModel) WithWarehouseSizeEnum(warehouseSize sdk.WarehouseSize) *WarehouseModel { + return w.WithWarehouseSize(string(warehouseSize)) +} diff --git a/pkg/acceptance/bettertestspoc/config/model/warehouse_model_gen.go b/pkg/acceptance/bettertestspoc/config/model/warehouse_model_gen.go new file mode 100644 index 0000000000..26b25b684d --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/warehouse_model_gen.go @@ -0,0 +1,220 @@ +// Code generated by config model builder generator; DO NOT EDIT. + +package model + +import ( + tfconfig "github.com/hashicorp/terraform-plugin-testing/config" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" +) + +type WarehouseModel struct { + AutoResume tfconfig.Variable `json:"auto_resume,omitempty"` + AutoSuspend tfconfig.Variable `json:"auto_suspend,omitempty"` + Comment tfconfig.Variable `json:"comment,omitempty"` + EnableQueryAcceleration tfconfig.Variable `json:"enable_query_acceleration,omitempty"` + InitiallySuspended tfconfig.Variable `json:"initially_suspended,omitempty"` + MaxClusterCount tfconfig.Variable `json:"max_cluster_count,omitempty"` + MaxConcurrencyLevel tfconfig.Variable `json:"max_concurrency_level,omitempty"` + MinClusterCount tfconfig.Variable `json:"min_cluster_count,omitempty"` + Name tfconfig.Variable `json:"name,omitempty"` + QueryAccelerationMaxScaleFactor tfconfig.Variable `json:"query_acceleration_max_scale_factor,omitempty"` + ResourceMonitor tfconfig.Variable `json:"resource_monitor,omitempty"` + ScalingPolicy tfconfig.Variable `json:"scaling_policy,omitempty"` + StatementQueuedTimeoutInSeconds tfconfig.Variable `json:"statement_queued_timeout_in_seconds,omitempty"` + StatementTimeoutInSeconds tfconfig.Variable `json:"statement_timeout_in_seconds,omitempty"` + WarehouseSize tfconfig.Variable `json:"warehouse_size,omitempty"` + WarehouseType tfconfig.Variable `json:"warehouse_type,omitempty"` + + *config.ResourceModelMeta +} + +///////////////////////////////////////////////// +// Basic builders (resource name and required) // +///////////////////////////////////////////////// + +func Warehouse( + resourceName string, + name string, +) *WarehouseModel { + w := &WarehouseModel{ResourceModelMeta: config.Meta(resourceName, resources.Warehouse)} + w.WithName(name) + return w +} + +func WarehouseWithDefaultMeta( + name string, +) *WarehouseModel { + w := &WarehouseModel{ResourceModelMeta: config.DefaultMeta(resources.Warehouse)} + w.WithName(name) + return w +} + +///////////////////////////////// +// below all the proper values // +///////////////////////////////// + +func (w *WarehouseModel) WithAutoResume(autoResume string) *WarehouseModel { + w.AutoResume = tfconfig.StringVariable(autoResume) + return w +} + +func (w *WarehouseModel) WithAutoSuspend(autoSuspend int) *WarehouseModel { + w.AutoSuspend = tfconfig.IntegerVariable(autoSuspend) + return w +} + +func (w *WarehouseModel) WithComment(comment string) *WarehouseModel { + w.Comment = tfconfig.StringVariable(comment) + return w +} + +func (w *WarehouseModel) WithEnableQueryAcceleration(enableQueryAcceleration string) *WarehouseModel { + w.EnableQueryAcceleration = tfconfig.StringVariable(enableQueryAcceleration) + return w +} + +func (w *WarehouseModel) WithInitiallySuspended(initiallySuspended bool) *WarehouseModel { + w.InitiallySuspended = tfconfig.BoolVariable(initiallySuspended) + return w +} + +func (w *WarehouseModel) WithMaxClusterCount(maxClusterCount int) *WarehouseModel { + w.MaxClusterCount = tfconfig.IntegerVariable(maxClusterCount) + return w +} + +func (w *WarehouseModel) WithMaxConcurrencyLevel(maxConcurrencyLevel int) *WarehouseModel { + w.MaxConcurrencyLevel = tfconfig.IntegerVariable(maxConcurrencyLevel) + return w +} + +func (w *WarehouseModel) WithMinClusterCount(minClusterCount int) *WarehouseModel { + w.MinClusterCount = tfconfig.IntegerVariable(minClusterCount) + return w +} + +func (w *WarehouseModel) WithName(name string) *WarehouseModel { + w.Name = tfconfig.StringVariable(name) + return w +} + +func (w *WarehouseModel) WithQueryAccelerationMaxScaleFactor(queryAccelerationMaxScaleFactor int) *WarehouseModel { + w.QueryAccelerationMaxScaleFactor = tfconfig.IntegerVariable(queryAccelerationMaxScaleFactor) + return w +} + +func (w *WarehouseModel) WithResourceMonitor(resourceMonitor string) *WarehouseModel { + w.ResourceMonitor = tfconfig.StringVariable(resourceMonitor) + return w +} + +func (w *WarehouseModel) WithScalingPolicy(scalingPolicy string) *WarehouseModel { + w.ScalingPolicy = tfconfig.StringVariable(scalingPolicy) + return w +} + +func (w *WarehouseModel) WithStatementQueuedTimeoutInSeconds(statementQueuedTimeoutInSeconds int) *WarehouseModel { + w.StatementQueuedTimeoutInSeconds = tfconfig.IntegerVariable(statementQueuedTimeoutInSeconds) + return w +} + +func (w *WarehouseModel) WithStatementTimeoutInSeconds(statementTimeoutInSeconds int) *WarehouseModel { + w.StatementTimeoutInSeconds = tfconfig.IntegerVariable(statementTimeoutInSeconds) + return w +} + +func (w *WarehouseModel) WithWarehouseSize(warehouseSize string) *WarehouseModel { + w.WarehouseSize = tfconfig.StringVariable(warehouseSize) + return w +} + +func (w *WarehouseModel) WithWarehouseType(warehouseType string) *WarehouseModel { + w.WarehouseType = tfconfig.StringVariable(warehouseType) + return w +} + +////////////////////////////////////////// +// below it's possible to set any value // +////////////////////////////////////////// + +func (w *WarehouseModel) WithAutoResumeValue(value tfconfig.Variable) *WarehouseModel { + w.AutoResume = value + return w +} + +func (w *WarehouseModel) WithAutoSuspendValue(value tfconfig.Variable) *WarehouseModel { + w.AutoSuspend = value + return w +} + +func (w *WarehouseModel) WithCommentValue(value tfconfig.Variable) *WarehouseModel { + w.Comment = value + return w +} + +func (w *WarehouseModel) WithEnableQueryAccelerationValue(value tfconfig.Variable) *WarehouseModel { + w.EnableQueryAcceleration = value + return w +} + +func (w *WarehouseModel) WithInitiallySuspendedValue(value tfconfig.Variable) *WarehouseModel { + w.InitiallySuspended = value + return w +} + +func (w *WarehouseModel) WithMaxClusterCountValue(value tfconfig.Variable) *WarehouseModel { + w.MaxClusterCount = value + return w +} + +func (w *WarehouseModel) WithMaxConcurrencyLevelValue(value tfconfig.Variable) *WarehouseModel { + w.MaxConcurrencyLevel = value + return w +} + +func (w *WarehouseModel) WithMinClusterCountValue(value tfconfig.Variable) *WarehouseModel { + w.MinClusterCount = value + return w +} + +func (w *WarehouseModel) WithNameValue(value tfconfig.Variable) *WarehouseModel { + w.Name = value + return w +} + +func (w *WarehouseModel) WithQueryAccelerationMaxScaleFactorValue(value tfconfig.Variable) *WarehouseModel { + w.QueryAccelerationMaxScaleFactor = value + return w +} + +func (w *WarehouseModel) WithResourceMonitorValue(value tfconfig.Variable) *WarehouseModel { + w.ResourceMonitor = value + return w +} + +func (w *WarehouseModel) WithScalingPolicyValue(value tfconfig.Variable) *WarehouseModel { + w.ScalingPolicy = value + return w +} + +func (w *WarehouseModel) WithStatementQueuedTimeoutInSecondsValue(value tfconfig.Variable) *WarehouseModel { + w.StatementQueuedTimeoutInSeconds = value + return w +} + +func (w *WarehouseModel) WithStatementTimeoutInSecondsValue(value tfconfig.Variable) *WarehouseModel { + w.StatementTimeoutInSeconds = value + return w +} + +func (w *WarehouseModel) WithWarehouseSizeValue(value tfconfig.Variable) *WarehouseModel { + w.WarehouseSize = value + return w +} + +func (w *WarehouseModel) WithWarehouseTypeValue(value tfconfig.Variable) *WarehouseModel { + w.WarehouseType = value + return w +} diff --git a/pkg/acceptance/bettertestspoc/config/warehouse_model.go b/pkg/acceptance/bettertestspoc/config/warehouse_model.go deleted file mode 100644 index 0a9a55cb4e..0000000000 --- a/pkg/acceptance/bettertestspoc/config/warehouse_model.go +++ /dev/null @@ -1,221 +0,0 @@ -package config - -import ( - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/hashicorp/terraform-plugin-testing/config" -) - -// TODO: add possibility to have reference to another object (e.g. WithResourceMonitorReference); new config.Variable impl? -// TODO: add possibility to have depends_on to other resources (in meta?) -// TODO: add a convenience method to use multiple configs from multiple models -type WarehouseModel struct { - Name config.Variable `json:"name,omitempty"` - WarehouseType config.Variable `json:"warehouse_type,omitempty"` - WarehouseSize config.Variable `json:"warehouse_size,omitempty"` - MaxClusterCount config.Variable `json:"max_cluster_count,omitempty"` - MinClusterCount config.Variable `json:"min_cluster_count,omitempty"` - ScalingPolicy config.Variable `json:"scaling_policy,omitempty"` - AutoSuspend config.Variable `json:"auto_suspend,omitempty"` - AutoResume config.Variable `json:"auto_resume,omitempty"` - InitiallySuspended config.Variable `json:"initially_suspended,omitempty"` - ResourceMonitor config.Variable `json:"resource_monitor,omitempty"` - Comment config.Variable `json:"comment,omitempty"` - EnableQueryAcceleration config.Variable `json:"enable_query_acceleration,omitempty"` - QueryAccelerationMaxScaleFactor config.Variable `json:"query_acceleration_max_scale_factor,omitempty"` - - MaxConcurrencyLevel config.Variable `json:"max_concurrency_level,omitempty"` - StatementQueuedTimeoutInSeconds config.Variable `json:"statement_queued_timeout_in_seconds,omitempty"` - StatementTimeoutInSeconds config.Variable `json:"statement_timeout_in_seconds,omitempty"` - - *resourceModelMeta -} - -///////////////////////////////////////////////// -// Basic builders (resource name and required) // -///////////////////////////////////////////////// - -func NewWarehouseModel( - resourceName string, - name string, -) *WarehouseModel { - m := &WarehouseModel{resourceModelMeta: meta(resourceName, resources.Warehouse)} - m.WithName(name) - return m -} - -func NewDefaultWarehouseModel( - name string, -) *WarehouseModel { - m := &WarehouseModel{resourceModelMeta: defaultMeta(resources.Warehouse)} - m.WithName(name) - return m -} - -///////////////////////////////// -// below all the proper values // -///////////////////////////////// - -func (m *WarehouseModel) WithName(name string) *WarehouseModel { - m.Name = config.StringVariable(name) - return m -} - -func (m *WarehouseModel) WithWarehouseType(warehouseType sdk.WarehouseType) *WarehouseModel { - m.WarehouseType = config.StringVariable(string(warehouseType)) - return m -} - -func (m *WarehouseModel) WithWarehouseSize(warehouseSize sdk.WarehouseSize) *WarehouseModel { - m.WarehouseSize = config.StringVariable(string(warehouseSize)) - return m -} - -func (m *WarehouseModel) WithMaxClusterCount(maxClusterCount int) *WarehouseModel { - m.MaxClusterCount = config.IntegerVariable(maxClusterCount) - return m -} - -func (m *WarehouseModel) WithMinClusterCount(minClusterCount int) *WarehouseModel { - m.MinClusterCount = config.IntegerVariable(minClusterCount) - return m -} - -func (m *WarehouseModel) WithScalingPolicy(scalingPolicy sdk.ScalingPolicy) *WarehouseModel { - m.ScalingPolicy = config.StringVariable(string(scalingPolicy)) - return m -} - -func (m *WarehouseModel) WithAutoSuspend(autoSuspend int) *WarehouseModel { - m.AutoSuspend = config.IntegerVariable(autoSuspend) - return m -} - -func (m *WarehouseModel) WithAutoResume(autoResume bool) *WarehouseModel { - m.AutoResume = config.BoolVariable(autoResume) - return m -} - -func (m *WarehouseModel) WithInitiallySuspended(initiallySuspended bool) *WarehouseModel { - m.InitiallySuspended = config.BoolVariable(initiallySuspended) - return m -} - -func (m *WarehouseModel) WithResourceMonitor(resourceMonitor sdk.AccountObjectIdentifier) *WarehouseModel { - m.ResourceMonitor = config.StringVariable(resourceMonitor.Name()) - return m -} - -func (m *WarehouseModel) WithComment(comment string) *WarehouseModel { - m.Comment = config.StringVariable(comment) - return m -} - -func (m *WarehouseModel) WithEnableQueryAcceleration(enableQueryAcceleration bool) *WarehouseModel { - m.EnableQueryAcceleration = config.BoolVariable(enableQueryAcceleration) - return m -} - -func (m *WarehouseModel) WithQueryAccelerationMaxScaleFactor(queryAccelerationMaxScaleFactor int) *WarehouseModel { - m.QueryAccelerationMaxScaleFactor = config.IntegerVariable(queryAccelerationMaxScaleFactor) - return m -} - -func (m *WarehouseModel) WithMaxConcurrencyLevel(maxConcurrencyLevel int) *WarehouseModel { - m.MaxConcurrencyLevel = config.IntegerVariable(maxConcurrencyLevel) - return m -} - -func (m *WarehouseModel) WithStatementQueuedTimeoutInSeconds(statementQueuedTimeoutInSeconds int) *WarehouseModel { - m.StatementQueuedTimeoutInSeconds = config.IntegerVariable(statementQueuedTimeoutInSeconds) - return m -} - -func (m *WarehouseModel) WithStatementTimeoutInSeconds(statementTimeoutInSeconds int) *WarehouseModel { - m.StatementTimeoutInSeconds = config.IntegerVariable(statementTimeoutInSeconds) - return m -} - -////////////////////////////////////////// -// below it's possible to set any value // -////////////////////////////////////////// - -func (m *WarehouseModel) WithNameValue(value config.Variable) *WarehouseModel { - m.Name = value - return m -} - -func (m *WarehouseModel) WithWarehouseTypeValue(value config.Variable) *WarehouseModel { - m.WarehouseType = value - return m -} - -func (m *WarehouseModel) WithWarehouseSizeValue(value config.Variable) *WarehouseModel { - m.WarehouseSize = value - return m -} - -func (m *WarehouseModel) WithMaxClusterCountValue(value config.Variable) *WarehouseModel { - m.MaxClusterCount = value - return m -} - -func (m *WarehouseModel) WithMinClusterCountValue(value config.Variable) *WarehouseModel { - m.MinClusterCount = value - return m -} - -func (m *WarehouseModel) WithScalingPolicyValue(value config.Variable) *WarehouseModel { - m.ScalingPolicy = value - return m -} - -func (m *WarehouseModel) WithAutoSuspendValue(value config.Variable) *WarehouseModel { - m.AutoSuspend = value - return m -} - -func (m *WarehouseModel) WithAutoResumeValue(value config.Variable) *WarehouseModel { - m.AutoResume = value - return m -} - -func (m *WarehouseModel) WithInitiallySuspendedValue(value config.Variable) *WarehouseModel { - m.InitiallySuspended = value - return m -} - -func (m *WarehouseModel) WithResourceMonitorValue(value config.Variable) *WarehouseModel { - m.ResourceMonitor = value - return m -} - -func (m *WarehouseModel) WithCommentValue(value config.Variable) *WarehouseModel { - m.Comment = value - return m -} - -func (m *WarehouseModel) WithEnableQueryAccelerationValue(value config.Variable) *WarehouseModel { - m.EnableQueryAcceleration = value - return m -} - -func (m *WarehouseModel) WithQueryAccelerationMaxScaleFactorValue(value config.Variable) *WarehouseModel { - m.QueryAccelerationMaxScaleFactor = value - return m -} - -func (m *WarehouseModel) WithMaxConcurrencyLevelValue(value config.Variable) *WarehouseModel { - m.MaxConcurrencyLevel = value - return m -} - -func (m *WarehouseModel) WithStatementQueuedTimeoutInSecondsValue(value config.Variable) *WarehouseModel { - m.StatementQueuedTimeoutInSeconds = value - return m -} - -func (m *WarehouseModel) WithStatementTimeoutInSecondsValue(value config.Variable) *WarehouseModel { - m.StatementTimeoutInSeconds = value - return m -} diff --git a/pkg/acceptance/bettertestspoc/config/warehouse_model_ext.go b/pkg/acceptance/bettertestspoc/config/warehouse_model_ext.go deleted file mode 100644 index 11eba4f7ab..0000000000 --- a/pkg/acceptance/bettertestspoc/config/warehouse_model_ext.go +++ /dev/null @@ -1,8 +0,0 @@ -package config - -func BasicWarehouseModel( - name string, - comment string, -) *WarehouseModel { - return NewDefaultWarehouseModel(name).WithComment(comment) -} diff --git a/pkg/internal/genhelpers/resource_schema_details_extractor.go b/pkg/internal/genhelpers/resource_schema_details_extractor.go new file mode 100644 index 0000000000..ff660ebccb --- /dev/null +++ b/pkg/internal/genhelpers/resource_schema_details_extractor.go @@ -0,0 +1,46 @@ +package genhelpers + +import ( + "slices" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +type ResourceSchemaDetails struct { + Name string + Attributes []SchemaAttribute +} + +func (s ResourceSchemaDetails) ObjectName() string { + return s.Name +} + +type SchemaAttribute struct { + Name string + AttributeType schema.ValueType + Required bool +} + +// TODO: test +func ExtractResourceSchemaDetails(name string, schema map[string]*schema.Schema) ResourceSchemaDetails { + orderedAttributeNames := make([]string, 0) + for key := range schema { + orderedAttributeNames = append(orderedAttributeNames, key) + } + slices.Sort(orderedAttributeNames) + + attributes := make([]SchemaAttribute, 0) + for _, k := range orderedAttributeNames { + s := schema[k] + attributes = append(attributes, SchemaAttribute{ + Name: k, + AttributeType: s.Type, + Required: s.Required, + }) + } + + return ResourceSchemaDetails{ + Name: name, + Attributes: attributes, + } +} diff --git a/pkg/internal/genhelpers/struct_details_extractor.go b/pkg/internal/genhelpers/struct_details_extractor.go index 34ddf34ca7..ad84b97f5d 100644 --- a/pkg/internal/genhelpers/struct_details_extractor.go +++ b/pkg/internal/genhelpers/struct_details_extractor.go @@ -2,6 +2,7 @@ package genhelpers import ( "reflect" + "slices" "strings" ) @@ -65,3 +66,21 @@ func ExtractStructDetails(s any) StructDetails { } return StructDetails{v.Type().String(), fields} } + +// TODO: test +func AdditionalStandardImports(fields []Field) []string { + imports := make(map[string]struct{}) + for _, field := range fields { + 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) + } + } + return additionalImports +} diff --git a/pkg/internal/genhelpers/struct_details_extractor_test.go b/pkg/internal/genhelpers/struct_details_extractor_test.go index b79c02cdca..1eae83d7b2 100644 --- a/pkg/internal/genhelpers/struct_details_extractor_test.go +++ b/pkg/internal/genhelpers/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, "gencommons.testStruct") + assert.Equal(t, structDetails.Name, "genhelpers.testStruct") assertFieldExtracted(structDetails.Fields[0], "unexportedString", "string", "string") assertFieldExtracted(structDetails.Fields[1], "unexportedInt", "int", "int") diff --git a/pkg/internal/genhelpers/template_commons.go b/pkg/internal/genhelpers/template_commons.go index 1480f1357f..c6a410f367 100644 --- a/pkg/internal/genhelpers/template_commons.go +++ b/pkg/internal/genhelpers/template_commons.go @@ -27,6 +27,10 @@ func TypeWithoutPointer(t string) string { return without } +func SnakeCase(name string) string { + return ToSnakeCase(name) +} + func CamelToWords(camel string) string { return strings.ReplaceAll(ToSnakeCase(camel), "_", " ") } diff --git a/pkg/resources/warehouse_acceptance_test.go b/pkg/resources/warehouse_acceptance_test.go index 6a045646bc..1a3e58d601 100644 --- a/pkg/resources/warehouse_acceptance_test.go +++ b/pkg/resources/warehouse_acceptance_test.go @@ -13,7 +13,11 @@ 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/assert/resourceassert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceparametersassert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/importchecks" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/planchecks" @@ -40,9 +44,9 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { t.Cleanup(resourceMonitorCleanup) resourceMonitorId := resourceMonitor.ID() - model := config.NewWarehouseModel("w", name).WithComment(comment) + warehouseModel := model.Warehouse("w", name).WithComment(comment) // alternatively we can add an extension func - _ = config.BasicWarehouseModel(name, comment) + _ = model.BasicWarehouseModel(name, comment) resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, @@ -53,32 +57,32 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { CheckDestroy: acc.CheckDestroy(t, resources.Warehouse), Steps: []resource.TestStep{ { - Config: config.FromModel(t, model), + Config: config.FromModel(t, warehouseModel), Check: assert.AssertThat(t, - assert.WarehouseResource(t, "snowflake_warehouse.w"). - HasName(name). - HasNoType(). - HasNoSize(). + resourceassert.WarehouseResource(t, "snowflake_warehouse.w"). + HasNameString(name). + HasNoWarehouseType(). + HasNoWarehouseSize(). HasNoMaxClusterCount(). HasNoMinClusterCount(). HasNoScalingPolicy(). - HasAutoSuspend(r.IntDefaultString). - HasAutoResume(r.BooleanDefault). + HasAutoSuspendString(r.IntDefaultString). + HasAutoResumeString(r.BooleanDefault). HasNoInitiallySuspended(). HasNoResourceMonitor(). - HasComment(comment). - HasEnableQueryAcceleration(r.BooleanDefault). - HasQueryAccelerationMaxScaleFactor(r.IntDefaultString). - HasMaxConcurrencyLevel("8"). - HasStatementQueuedTimeoutInSeconds("0"). - HasStatementTimeoutInSeconds("172800"). + HasCommentString(comment). + HasEnableQueryAccelerationString(r.BooleanDefault). + HasQueryAccelerationMaxScaleFactorString(r.IntDefaultString). + HasMaxConcurrencyLevelString("8"). + HasStatementQueuedTimeoutInSecondsString("0"). + HasStatementTimeoutInSecondsString("172800"). // alternatively extensions possible: HasDefaultMaxConcurrencyLevel(). HasDefaultStatementQueuedTimeoutInSeconds(). HasDefaultStatementTimeoutInSeconds(). // alternatively extension possible HasAllDefault(), - assert.WarehouseShowOutput(t, "snowflake_warehouse.w"). + resourceshowoutputassert.WarehouseShowOutput(t, "snowflake_warehouse.w"). HasType(sdk.WarehouseTypeStandard). HasSize(sdk.WarehouseSizeXSmall). HasMaxClusterCount(1). @@ -86,11 +90,11 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { HasScalingPolicy(sdk.ScalingPolicyStandard). HasAutoSuspend(600). HasAutoResume(true). - HasResourceMonitor(""). + HasResourceMonitor(sdk.AccountObjectIdentifier{}). HasComment(comment). HasEnableQueryAcceleration(false). HasQueryAccelerationMaxScaleFactor(8), - assert.WarehouseParameters(t, "snowflake_warehouse.w"). + resourceparametersassert.WarehouseResourceParameters(t, "snowflake_warehouse.w"). HasMaxConcurrencyLevel(8). HasStatementQueuedTimeoutInSeconds(0). HasStatementTimeoutInSeconds(172800). @@ -125,24 +129,24 @@ func TestAcc_Warehouse_BasicFlows(t *testing.T) { ImportState: true, ImportStateCheck: assert.AssertThatImport(t, assert.CheckImport(importchecks.TestCheckResourceAttrInstanceState(warehouseId.Name(), "name", name)), - assert.ImportedWarehouseResource(t, warehouseId.Name()). - HasName(name). - HasType(string(sdk.WarehouseTypeStandard)). - HasSize(string(sdk.WarehouseSizeXSmall)). - HasMaxClusterCount("1"). - HasMinClusterCount("1"). - HasScalingPolicy(string(sdk.ScalingPolicyStandard)). - HasAutoSuspend("600"). - HasAutoResume("true"). - HasResourceMonitor(""). - HasComment(comment). - HasEnableQueryAcceleration("false"). - HasQueryAccelerationMaxScaleFactor("8"). + resourceassert.ImportedWarehouseResource(t, warehouseId.Name()). + HasNameString(name). + HasWarehouseTypeString(string(sdk.WarehouseTypeStandard)). + HasWarehouseSizeString(string(sdk.WarehouseSizeXSmall)). + HasMaxClusterCountString("1"). + HasMinClusterCountString("1"). + HasScalingPolicyString(string(sdk.ScalingPolicyStandard)). + HasAutoSuspendString("600"). + HasAutoResumeString("true"). + HasResourceMonitorString(""). + HasCommentString(comment). + HasEnableQueryAccelerationString("false"). + HasQueryAccelerationMaxScaleFactorString("8"). HasDefaultMaxConcurrencyLevel(). HasDefaultStatementQueuedTimeoutInSeconds(). HasDefaultStatementTimeoutInSeconds(), - assert.ImportedWarehouseShowOutput(t, warehouseId.Name()), - assert.ImportedWarehouseParameters(t, warehouseId.Name()). + resourceshowoutputassert.ImportedWarehouseShowOutput(t, warehouseId.Name()), + resourceparametersassert.ImportedWarehouseResourceParameters(t, warehouseId.Name()). HasMaxConcurrencyLevel(8). HasMaxConcurrencyLevelLevel(""). HasStatementQueuedTimeoutInSeconds(0).