From e2a5953568c8e34e40960c6c7c04bd7306cb5bdc Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Tue, 11 Mar 2025 13:25:32 +0100 Subject: [PATCH] Make bind/schema acceptance test run locally (#2463) ## Changes 1. Change the cloud acceptance test for `bind/schema` to run locally 2. Add debug lines to the mock server 3. Change `fake_workspace` to create directories for imported files ## Why 1. Local version of the test run can indicate breaking changes faster than the cloud version and it can be run locally without any predefined environment variables ## Tests 1. Ran both acloud and local versions of test, both succeeded --- acceptance/acceptance_test.go | 5 +++- .../bundle/deployment/bind/schema/output.txt | 3 +- .../bundle/deployment/bind/schema/script | 6 +++- .../bundle/deployment/bind/schema/test.toml | 29 ++++++++++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 302a1b50d..6dcc713c9 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -223,7 +223,9 @@ 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 cloudEnv != "" { if isTruePtr(config.RequiresUnityCatalog) && os.Getenv("TEST_METASTORE_ID") == "" { t.Skipf("Skipping on non-UC workspaces") } @@ -361,6 +363,7 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont absDir, err := filepath.Abs(dir) require.NoError(t, err) cmd.Env = append(cmd.Env, "TESTDIR="+absDir) + cmd.Env = append(cmd.Env, "CLOUD_ENV="+cloudEnv) // Write combined output to a file out, err := os.Create(filepath.Join(tmpDir, "output.txt")) diff --git a/acceptance/bundle/deployment/bind/schema/output.txt b/acceptance/bundle/deployment/bind/schema/output.txt index df30475e6..772eaae84 100644 --- a/acceptance/bundle/deployment/bind/schema/output.txt +++ b/acceptance/bundle/deployment/bind/schema/output.txt @@ -3,8 +3,7 @@ === Substitute variables in the template: === Create a pre-defined schema: { "full_name": "main.test-schema-[UUID]", - "catalog_name": "main", - "comment": null + "catalog_name": "main" } === Bind schema: Updating deployment state... diff --git a/acceptance/bundle/deployment/bind/schema/script b/acceptance/bundle/deployment/bind/schema/script index ef0ce1514..10763fa81 100644 --- a/acceptance/bundle/deployment/bind/schema/script +++ b/acceptance/bundle/deployment/bind/schema/script @@ -2,12 +2,16 @@ title "Bind schema test: " title "Substitute variables in the template: " export BUNDLE_NAME_SUFFIX=$(uuid) + export SCHEMA_NAME="test-schema-$(uuid)" +if [ -z "$CLOUD_ENV" ]; then + export SCHEMA_NAME="test-schema-6260d50f-e8ff-4905-8f28-812345678903" # use hard-coded uuid when running locally +fi 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}' +$CLI schemas create ${SCHEMA_NAME} ${CATALOG_NAME} | jq '{full_name, catalog_name}' cleanupRemoveSchema() { title "Test cleanup: " diff --git a/acceptance/bundle/deployment/bind/schema/test.toml b/acceptance/bundle/deployment/bind/schema/test.toml index 46518d61e..ff8321da2 100644 --- a/acceptance/bundle/deployment/bind/schema/test.toml +++ b/acceptance/bundle/deployment/bind/schema/test.toml @@ -1,3 +1,30 @@ -Local = false +Local = true Cloud = true RequiresUnityCatalog = true + +[[Server]] +Pattern = "POST /api/2.1/unity-catalog/schemas" +Response.Body = ''' +{ + "name":"test-schema-6260d50f-e8ff-4905-8f28-812345678903", + "catalog_name":"main", + "full_name":"main.test-schema-6260d50f-e8ff-4905-8f28-812345678903" +} +''' + +[[Server]] +Pattern = "GET /api/2.1/unity-catalog/schemas/{schema_fullname}" +Response.Body = ''' +{ + "name":"test-schema-6260d50f-e8ff-4905-8f28-812345678903", + "catalog_name":"main", + "full_name":"main.test-schema-6260d50f-e8ff-4905-8f28-812345678903", + "comment": "This schema was created from DABs" +} +''' + +[[Server]] +Pattern = "PATCH /api/2.1/unity-catalog/schemas/{schema_fullname}" + +[[Server]] +Pattern = "DELETE /api/2.1/unity-catalog/schemas/{schema_fullname}" \ No newline at end of file