diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index afdc42abc..302a1b50d 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -223,6 +223,10 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont if !isTruePtr(config.Cloud) && cloudEnv != "" { t.Skipf("Disabled via Cloud setting in %s (CLOUD_ENV=%s)", configPath, cloudEnv) + } else { + if isTruePtr(config.RequiresUnityCatalog) && os.Getenv("TEST_METASTORE_ID") == "" { + t.Skipf("Skipping on non-UC workspaces") + } } var tmpDir string diff --git a/acceptance/bundle/deployment/bind/schema/databricks.yml b/acceptance/bundle/deployment/bind/schema/databricks.yml new file mode 100644 index 000000000..e8e0f150c --- /dev/null +++ b/acceptance/bundle/deployment/bind/schema/databricks.yml @@ -0,0 +1,10 @@ +bundle: + name: bind-schema-test-$BUNDLE_NAME_SUFFIX + +resources: + schemas: + schema1: + name: $SCHEMA_NAME + catalog_name: main + comment: This schema was created from DABs + diff --git a/acceptance/bundle/deployment/bind/schema/output.txt b/acceptance/bundle/deployment/bind/schema/output.txt new file mode 100644 index 000000000..df30475e6 --- /dev/null +++ b/acceptance/bundle/deployment/bind/schema/output.txt @@ -0,0 +1,38 @@ + +=== Bind schema test: +=== Substitute variables in the template: +=== Create a pre-defined schema: { + "full_name": "main.test-schema-[UUID]", + "catalog_name": "main", + "comment": null +} + +=== Bind schema: Updating deployment state... +Successfully bound databricks_schema with an id 'main.test-schema-[UUID]'. Run 'bundle deploy' to deploy changes to your workspace + +=== Deploy bundle: Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/bind-schema-test-[UUID]/default/files... +Deploying resources... +Updating deployment state... +Deployment complete! + +=== Read the pre-defined schema: { + "full_name": "main.test-schema-[UUID]", + "catalog_name": "main", + "comment": "This schema was created from DABs" +} + +=== Unbind the schema: Updating deployment state... + +=== Destroy the bundle: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/bind-schema-test-[UUID]/default + +Deleting files... +Destroy complete! + +=== Read the pre-defined schema again (expecting it still exists): { + "full_name": "main.test-schema-[UUID]", + "catalog_name": "main", + "comment": "This schema was created from DABs" +} + +=== Test cleanup: +=== Delete the pre-defined schema test-schema-[UUID]: 0 diff --git a/acceptance/bundle/deployment/bind/schema/script b/acceptance/bundle/deployment/bind/schema/script new file mode 100644 index 000000000..ef0ce1514 --- /dev/null +++ b/acceptance/bundle/deployment/bind/schema/script @@ -0,0 +1,36 @@ +title "Bind schema test: " + +title "Substitute variables in the template: " +export BUNDLE_NAME_SUFFIX=$(uuid) +export SCHEMA_NAME="test-schema-$(uuid)" +envsubst < databricks.yml > out.yml && mv out.yml databricks.yml + +title "Create a pre-defined schema: " +CATALOG_NAME=main +$CLI schemas create ${SCHEMA_NAME} ${CATALOG_NAME} | jq '{full_name, catalog_name, comment}' + +cleanupRemoveSchema() { + title "Test cleanup: " + title "Delete the pre-defined schema ${SCHEMA_NAME}: " + $CLI schemas delete ${CATALOG_NAME}.${SCHEMA_NAME} + echo $? +} +trap cleanupRemoveSchema EXIT + +title "Bind schema: " +$CLI bundle deployment bind schema1 ${CATALOG_NAME}.${SCHEMA_NAME} --auto-approve + +title "Deploy bundle: " +$CLI bundle deploy --force-lock --auto-approve + +title "Read the pre-defined schema: " +$CLI schemas get ${CATALOG_NAME}.${SCHEMA_NAME} | jq '{full_name, catalog_name, comment}' + +title "Unbind the schema: " +$CLI bundle deployment unbind schema1 + +title "Destroy the bundle: " +$CLI bundle destroy --auto-approve + +title "Read the pre-defined schema again (expecting it still exists): " +$CLI schemas get ${CATALOG_NAME}.${SCHEMA_NAME} | jq '{full_name, catalog_name, comment}' diff --git a/acceptance/bundle/deployment/bind/schema/test.toml b/acceptance/bundle/deployment/bind/schema/test.toml new file mode 100644 index 000000000..46518d61e --- /dev/null +++ b/acceptance/bundle/deployment/bind/schema/test.toml @@ -0,0 +1,3 @@ +Local = false +Cloud = true +RequiresUnityCatalog = true diff --git a/acceptance/config_test.go b/acceptance/config_test.go index cc5257c65..fa236275b 100644 --- a/acceptance/config_test.go +++ b/acceptance/config_test.go @@ -31,6 +31,9 @@ type TestConfig struct { // If true, run this test when running with cloud env configured Cloud *bool + // If true and Cloud=true, run this test only if unity catalog is available in the cloud environment + RequiresUnityCatalog *bool + // List of additional replacements to apply on this test. // Old is a regexp, New is a replacement expression. Repls []testdiff.Replacement diff --git a/acceptance/script.prepare b/acceptance/script.prepare index ca47cdbff..4d2afb98c 100644 --- a/acceptance/script.prepare +++ b/acceptance/script.prepare @@ -59,3 +59,7 @@ withdir() { cd "$orig_dir" || return $? return $exit_code } + +uuid() { + python3 -c 'import uuid; print(uuid.uuid4())' +} \ No newline at end of file