Add acceptance test for binding/unbinding schemas (#2441)

## Changes
<!-- Brief summary of your changes that is easy to understand -->
1. Created a new acceptance test for binding an existing schema to a
bundle
2. Added a feature flag support for acceptance test runner

## Why
<!-- Why are these changes needed? Provide the context that the reviewer
might be missing.
For example, were there any decisions behind the change that are not
reflected in the code itself? -->
1. The test is more simple than an existing integration test for bind
2. The test only can run in environments where Unity Catalog is enabled

## Tests
<!-- How have you tested the changes? -->
New test is passing in CI/CD

## Changelog
NO_CHANGELOG=true
This commit is contained in:
Anton Nekipelov 2025-03-07 17:41:25 +01:00 committed by GitHub
parent 5948339f92
commit 0225c77b68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 98 additions and 0 deletions

View File

@ -223,6 +223,10 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
if !isTruePtr(config.Cloud) && cloudEnv != "" { if !isTruePtr(config.Cloud) && cloudEnv != "" {
t.Skipf("Disabled via Cloud setting in %s (CLOUD_ENV=%s)", configPath, 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 var tmpDir string

View File

@ -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

View File

@ -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

View File

@ -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}'

View File

@ -0,0 +1,3 @@
Local = false
Cloud = true
RequiresUnityCatalog = true

View File

@ -31,6 +31,9 @@ type TestConfig struct {
// If true, run this test when running with cloud env configured // If true, run this test when running with cloud env configured
Cloud *bool 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. // List of additional replacements to apply on this test.
// Old is a regexp, New is a replacement expression. // Old is a regexp, New is a replacement expression.
Repls []testdiff.Replacement Repls []testdiff.Replacement

View File

@ -59,3 +59,7 @@ withdir() {
cd "$orig_dir" || return $? cd "$orig_dir" || return $?
return $exit_code return $exit_code
} }
uuid() {
python3 -c 'import uuid; print(uuid.uuid4())'
}