-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retain location information of variable reference (#1333)
## Changes Variable substitution works as if the variable reference is literally replaced with its contents. The following fields should be interpreted in the same way regardless of where the variable is defined: ```yaml foo: ${var.some_path} bar: "./${var.some_path}" ``` Before this change, `foo` would inherit the location information of the variable definition. After this change, it uses the location information of the variable reference, making the behavior for `foo` and `bar` identical. Fixes #1330. ## Tests The new test passes only with the fix.
- Loading branch information
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
bundle: | ||
name: relative_path_translation | ||
|
||
include: | ||
- resources/*.yml | ||
|
||
variables: | ||
file_path: | ||
# This path is expected to be resolved relative to where it is used. | ||
default: ../src/file1.py | ||
|
||
workspace: | ||
file_path: /remote | ||
|
||
targets: | ||
default: | ||
default: true | ||
|
||
override: | ||
variables: | ||
file_path: ./src/file2.py | ||
|
||
resources: | ||
jobs: | ||
job: | ||
tasks: | ||
- task_key: local | ||
spark_python_task: | ||
python_file: ./src/file2.py | ||
|
||
- task_key: variable_reference | ||
spark_python_task: | ||
python_file: ${var.file_path} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
resources: | ||
jobs: | ||
job: | ||
tasks: | ||
- task_key: local | ||
spark_python_task: | ||
python_file: ../src/file1.py | ||
|
||
- task_key: variable_reference | ||
spark_python_task: | ||
# Note: this is a pure variable reference yet needs to persist the location | ||
# of the reference, not the location of the variable value. | ||
# Also see https://github.com/databricks/cli/issues/1330. | ||
python_file: ${var.file_path} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package config_tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/phases" | ||
"github.com/databricks/databricks-sdk-go/config" | ||
"github.com/databricks/databricks-sdk-go/experimental/mocks" | ||
"github.com/databricks/databricks-sdk-go/service/iam" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func configureMock(t *testing.T, b *bundle.Bundle) { | ||
// Configure mock workspace client | ||
m := mocks.NewMockWorkspaceClient(t) | ||
m.WorkspaceClient.Config = &config.Config{ | ||
Host: "https://mock.databricks.workspace.com", | ||
} | ||
m.GetMockCurrentUserAPI().EXPECT().Me(mock.Anything).Return(&iam.User{ | ||
UserName: "[email protected]", | ||
}, nil) | ||
b.SetWorkpaceClient(m.WorkspaceClient) | ||
} | ||
|
||
func TestRelativePathTranslationDefault(t *testing.T) { | ||
b := loadTarget(t, "./relative_path_translation", "default") | ||
configureMock(t, b) | ||
|
||
diags := bundle.Apply(context.Background(), b, phases.Initialize()) | ||
require.NoError(t, diags.Error()) | ||
|
||
t0 := b.Config.Resources.Jobs["job"].Tasks[0] | ||
assert.Equal(t, "/remote/src/file1.py", t0.SparkPythonTask.PythonFile) | ||
t1 := b.Config.Resources.Jobs["job"].Tasks[1] | ||
assert.Equal(t, "/remote/src/file1.py", t1.SparkPythonTask.PythonFile) | ||
} | ||
|
||
func TestRelativePathTranslationOverride(t *testing.T) { | ||
b := loadTarget(t, "./relative_path_translation", "override") | ||
configureMock(t, b) | ||
|
||
diags := bundle.Apply(context.Background(), b, phases.Initialize()) | ||
require.NoError(t, diags.Error()) | ||
|
||
t0 := b.Config.Resources.Jobs["job"].Tasks[0] | ||
assert.Equal(t, "/remote/src/file2.py", t0.SparkPythonTask.PythonFile) | ||
t1 := b.Config.Resources.Jobs["job"].Tasks[1] | ||
assert.Equal(t, "/remote/src/file2.py", t1.SparkPythonTask.PythonFile) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters