Add test about using variable in bundle.git.branch (#2118)

This test checks load git details functionality + variable interpolation
there.

The variables are not working there because LoadGitDetails mutator is
running before variable interpolation.

Additionally, correctly replace tmp path that is used for DATABRICKS_TF_EXEC_PATH
This commit is contained in:
Denis Bilenko 2025-01-15 10:34:51 +01:00 committed by GitHub
parent cc44e368b8
commit 55494a0bda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 139 additions and 3 deletions

View File

@ -59,6 +59,13 @@ func TestAccept(t *testing.T) {
repls := testdiff.ReplacementsContext{} repls := testdiff.ReplacementsContext{}
repls.Set(execPath, "$CLI") repls.Set(execPath, "$CLI")
tempHomeDir := t.TempDir()
repls.Set(tempHomeDir, "$TMPHOME")
t.Logf("$TMPHOME=%v", tempHomeDir)
// Prevent CLI from downloading terraform in each test:
t.Setenv("DATABRICKS_TF_EXEC_PATH", tempHomeDir)
ctx := context.Background() ctx := context.Background()
cloudEnv := os.Getenv("CLOUD_ENV") cloudEnv := os.Getenv("CLOUD_ENV")

View File

@ -0,0 +1,19 @@
bundle:
name: git
git:
# This is currently not supported
branch: ${var.deployment_branch}
variables:
deployment_branch:
# By setting deployment_branch to "" we set bundle.git.branch to "" which is the same unsetting it.
# This this should make CLI read branch from git and update bundle.git.branch accordingly. It should
# Also set bundle.git.inferred to true.
default: ""
targets:
prod:
default: true
dev:
variables:
deployment_branch: dev-branch

View File

@ -0,0 +1,98 @@
>>> $CLI bundle validate -o json
{
"bundle": {
"environment": "prod",
"git": {
"actual_branch": "main",
"branch": "",
"bundle_root_path": ".",
},
"name": "git",
"target": "prod",
"terraform": {
"exec_path": "$TMPHOME"
}
},
"sync": {
"paths": [
"."
]
},
"targets": null,
"variables": {
"deployment_branch": {
"default": "",
"value": ""
}
},
"workspace": {
"artifact_path": "/Workspace/Users/$USERNAME/.bundle/git/prod/artifacts",
"current_user": {
"short_name": "$USERNAME",
"userName": "$USERNAME"
},
"file_path": "/Workspace/Users/$USERNAME/.bundle/git/prod/files",
"resource_path": "/Workspace/Users/$USERNAME/.bundle/git/prod/resources",
"root_path": "/Workspace/Users/$USERNAME/.bundle/git/prod",
"state_path": "/Workspace/Users/$USERNAME/.bundle/git/prod/state"
}
}
>>> $CLI bundle validate
Name: git
Target: prod
Workspace:
User: $USERNAME
Path: /Workspace/Users/$USERNAME/.bundle/git/prod
Validation OK!
>>> $CLI bundle validate -o json -t dev
{
"bundle": {
"environment": "dev",
"git": {
"actual_branch": "main",
"branch": "dev-branch",
"bundle_root_path": ".",
},
"name": "git",
"target": "dev",
"terraform": {
"exec_path": "$TMPHOME"
}
},
"sync": {
"paths": [
"."
]
},
"targets": null,
"variables": {
"deployment_branch": {
"default": "dev-branch",
"value": "dev-branch"
}
},
"workspace": {
"artifact_path": "/Workspace/Users/$USERNAME/.bundle/git/dev/artifacts",
"current_user": {
"short_name": "$USERNAME",
"userName": "$USERNAME"
},
"file_path": "/Workspace/Users/$USERNAME/.bundle/git/dev/files",
"resource_path": "/Workspace/Users/$USERNAME/.bundle/git/dev/resources",
"root_path": "/Workspace/Users/$USERNAME/.bundle/git/dev",
"state_path": "/Workspace/Users/$USERNAME/.bundle/git/dev/state"
}
}
>>> $CLI bundle validate -t dev
Name: git
Target: dev
Workspace:
User: $USERNAME
Path: /Workspace/Users/$USERNAME/.bundle/git/dev
Validation OK!

View File

@ -0,0 +1,6 @@
git-repo-init
trace $CLI bundle validate -o json | grep -v '"commit"'
trace $CLI bundle validate
trace $CLI bundle validate -o json -t dev | grep -v '"commit"'
trace $CLI bundle validate -t dev | grep -v '"commit"'
rm -fr .git

View File

@ -1,6 +1,3 @@
# Prevent CLI from downloading terraform in each test:
export DATABRICKS_TF_EXEC_PATH=/tmp/
errcode() { errcode() {
# Temporarily disable 'set -e' to prevent the script from exiting on error # Temporarily disable 'set -e' to prevent the script from exiting on error
set +e set +e
@ -34,3 +31,12 @@ trace() {
return $? return $?
} }
git-repo-init() {
git init -qb main
git config --global core.autocrlf false
git config user.name "Tester"
git config user.email "tester@databricks.com"
git add databricks.yml
git commit -qm 'Add databricks.yml'
}