Skip to content

Commit

Permalink
chore: Test support for object renaming (#3130)
Browse files Browse the repository at this point in the history
## Changes
- Added integration tests to show the inconsistency between ShowByID
errors
- Added acceptance tests to show different behaviors of objects after
renaming higher-hierarchy objects
- Added generated models for database and schema
- Added new test command to Makefile that runs the tests (they're
separated from the CI tests by env variable that has to be enabled to
run the tests)

## TODO
- Pick the important tests that should be running with other acceptance
tests
- Transform shallow hierarchy tests into parametrized ones (similar to
what we have right now in deep hierarchy test).
  • Loading branch information
sfc-gh-jcieslak authored Oct 22, 2024
1 parent 893b288 commit d665419
Show file tree
Hide file tree
Showing 11 changed files with 2,139 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ test-architecture: ## check architecture constraints between packages
test-client: ## runs test that checks sdk.Client without instrumentedsql
SF_TF_NO_INSTRUMENTED_SQL=1 SF_TF_GOSNOWFLAKE_LOG_LEVEL=debug go test ./pkg/sdk/internal/client/... -v

test-object-renaming: ## runs tests in object_renaming_acceptance_test.go
TEST_SF_TF_ENABLE_OBJECT_RENAMING=1 go test ./pkg/resources/object_renaming_acceptace_test.go -v

test-acceptance-%: ## run acceptance tests for the given resource only, e.g. test-acceptance-Warehouse
TF_ACC=1 TF_LOG=DEBUG SF_TF_ACC_TEST_CONFIGURE_CLIENT_ONCE=true go test -run ^TestAcc_$*_ -v -timeout=20m ./pkg/resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ var allResourceSchemaDefs = []ResourceSchemaDef{
name: "View",
schema: resources.View().Schema,
},
{
name: "Database",
schema: resources.Database().Schema,
},
{
name: "DatabaseRole",
schema: resources.DatabaseRole().Schema,
Expand All @@ -53,6 +57,10 @@ var allResourceSchemaDefs = []ResourceSchemaDef{
name: "RowAccessPolicy",
schema: resources.RowAccessPolicy().Schema,
},
{
name: "Schema",
schema: resources.Schema().Schema,
},
{
name: "MaskingPolicy",
schema: resources.MaskingPolicy().Schema,
Expand Down
13 changes: 11 additions & 2 deletions pkg/acceptance/bettertestspoc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ResourceModel interface {
SetResourceName(name string)
ResourceReference() string
DependsOn() []string
SetDependsOn(values []string)
SetDependsOn(values ...string)
}

type ResourceModelMeta struct {
Expand Down Expand Up @@ -54,7 +54,7 @@ func (m *ResourceModelMeta) DependsOn() []string {
return m.dependsOn
}

func (m *ResourceModelMeta) SetDependsOn(values []string) {
func (m *ResourceModelMeta) SetDependsOn(values ...string) {
m.dependsOn = values
}

Expand Down Expand Up @@ -99,6 +99,15 @@ func FromModel(t *testing.T, model ResourceModel) string {
return s
}

func FromModels(t *testing.T, models ...ResourceModel) string {
t.Helper()
var sb strings.Builder
for _, model := range models {
sb.WriteString(FromModel(t, model) + "\n")
}
return sb.String()
}

// ConfigVariablesFromModel constructs config.Variables needed in acceptance tests that are using ConfigVariables in
// combination with ConfigDirectory. It's necessary for cases not supported by FromModel, like lists of objects.
func ConfigVariablesFromModel(t *testing.T, model ResourceModel) tfconfig.Variables {
Expand Down
283 changes: 283 additions & 0 deletions pkg/acceptance/bettertestspoc/config/model/database_model_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d665419

Please sign in to comment.