mirror of https://github.com/databricks/cli.git
Convert some resolve variables tests to acceptance test (#2100)
This commit is contained in:
parent
42b34c7bef
commit
df17e4b4ea
|
@ -0,0 +1,6 @@
|
||||||
|
bundle:
|
||||||
|
name: TestResolveVariableReferences
|
||||||
|
|
||||||
|
workspace:
|
||||||
|
root_path: "${bundle.name}/bar"
|
||||||
|
file_path: "${workspace.root_path}/baz"
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"artifact_path": "TestResolveVariableReferences/bar/artifacts",
|
||||||
|
"current_user": {
|
||||||
|
"short_name": "tester",
|
||||||
|
"userName": "tester@databricks.com"
|
||||||
|
},
|
||||||
|
"file_path": "TestResolveVariableReferences/bar/baz",
|
||||||
|
"resource_path": "TestResolveVariableReferences/bar/resources",
|
||||||
|
"root_path": "TestResolveVariableReferences/bar",
|
||||||
|
"state_path": "TestResolveVariableReferences/bar/state"
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
$CLI bundle validate -o json | jq .workspace
|
|
@ -0,0 +1,10 @@
|
||||||
|
bundle:
|
||||||
|
name: TestResolveVariableReferencesToEmptyFields
|
||||||
|
git:
|
||||||
|
branch: ""
|
||||||
|
|
||||||
|
resources:
|
||||||
|
jobs:
|
||||||
|
job1:
|
||||||
|
tags:
|
||||||
|
git_branch: "${bundle.git.branch}"
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"git_branch": ""
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
$CLI bundle validate -o json | jq .resources.jobs.job1.tags
|
|
@ -0,0 +1,16 @@
|
||||||
|
bundle:
|
||||||
|
name: TestResolveComplexVariableReferencesToFields
|
||||||
|
|
||||||
|
variables:
|
||||||
|
cluster:
|
||||||
|
type: "complex"
|
||||||
|
default:
|
||||||
|
node_type_id: "Standard_DS3_v2"
|
||||||
|
num_workers: 2
|
||||||
|
|
||||||
|
resources:
|
||||||
|
jobs:
|
||||||
|
job1:
|
||||||
|
job_clusters:
|
||||||
|
- new_cluster:
|
||||||
|
node_type_id: "${var.cluster.node_type_id}"
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"node_type_id": "Standard_DS3_v2"
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
$CLI bundle validate -o json | jq .resources.jobs.job1.job_clusters[0].new_cluster
|
|
@ -17,32 +17,6 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolveVariableReferences(t *testing.T) {
|
|
||||||
b := &bundle.Bundle{
|
|
||||||
Config: config.Root{
|
|
||||||
Bundle: config.Bundle{
|
|
||||||
Name: "example",
|
|
||||||
},
|
|
||||||
Workspace: config.Workspace{
|
|
||||||
RootPath: "${bundle.name}/bar",
|
|
||||||
FilePath: "${workspace.root_path}/baz",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply with an invalid prefix. This should not change the workspace root path.
|
|
||||||
diags := bundle.Apply(context.Background(), b, ResolveVariableReferences("doesntexist"))
|
|
||||||
require.NoError(t, diags.Error())
|
|
||||||
require.Equal(t, "${bundle.name}/bar", b.Config.Workspace.RootPath)
|
|
||||||
require.Equal(t, "${workspace.root_path}/baz", b.Config.Workspace.FilePath)
|
|
||||||
|
|
||||||
// Apply with a valid prefix. This should change the workspace root path.
|
|
||||||
diags = bundle.Apply(context.Background(), b, ResolveVariableReferences("bundle", "workspace"))
|
|
||||||
require.NoError(t, diags.Error())
|
|
||||||
require.Equal(t, "example/bar", b.Config.Workspace.RootPath)
|
|
||||||
require.Equal(t, "example/bar/baz", b.Config.Workspace.FilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveVariableReferencesToBundleVariables(t *testing.T) {
|
func TestResolveVariableReferencesToBundleVariables(t *testing.T) {
|
||||||
b := &bundle.Bundle{
|
b := &bundle.Bundle{
|
||||||
Config: config.Root{
|
Config: config.Root{
|
||||||
|
@ -66,37 +40,6 @@ func TestResolveVariableReferencesToBundleVariables(t *testing.T) {
|
||||||
require.Equal(t, "example/bar", b.Config.Workspace.RootPath)
|
require.Equal(t, "example/bar", b.Config.Workspace.RootPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveVariableReferencesToEmptyFields(t *testing.T) {
|
|
||||||
b := &bundle.Bundle{
|
|
||||||
Config: config.Root{
|
|
||||||
Bundle: config.Bundle{
|
|
||||||
Name: "example",
|
|
||||||
Git: config.Git{
|
|
||||||
Branch: "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Resources: config.Resources{
|
|
||||||
Jobs: map[string]*resources.Job{
|
|
||||||
"job1": {
|
|
||||||
JobSettings: &jobs.JobSettings{
|
|
||||||
Tags: map[string]string{
|
|
||||||
"git_branch": "${bundle.git.branch}",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply for the bundle prefix.
|
|
||||||
diags := bundle.Apply(context.Background(), b, ResolveVariableReferences("bundle"))
|
|
||||||
require.NoError(t, diags.Error())
|
|
||||||
|
|
||||||
// The job settings should have been interpolated to an empty string.
|
|
||||||
require.Equal(t, "", b.Config.Resources.Jobs["job1"].JobSettings.Tags["git_branch"])
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveVariableReferencesForPrimitiveNonStringFields(t *testing.T) {
|
func TestResolveVariableReferencesForPrimitiveNonStringFields(t *testing.T) {
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
|
@ -251,63 +194,6 @@ func TestResolveComplexVariable(t *testing.T) {
|
||||||
require.Equal(t, 2, b.Config.Resources.Jobs["job1"].JobSettings.JobClusters[0].NewCluster.NumWorkers)
|
require.Equal(t, 2, b.Config.Resources.Jobs["job1"].JobSettings.JobClusters[0].NewCluster.NumWorkers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveComplexVariableReferencesToFields(t *testing.T) {
|
|
||||||
b := &bundle.Bundle{
|
|
||||||
Config: config.Root{
|
|
||||||
Bundle: config.Bundle{
|
|
||||||
Name: "example",
|
|
||||||
},
|
|
||||||
Variables: map[string]*variable.Variable{
|
|
||||||
"cluster": {
|
|
||||||
Value: map[string]any{
|
|
||||||
"node_type_id": "Standard_DS3_v2",
|
|
||||||
"num_workers": 2,
|
|
||||||
},
|
|
||||||
Type: variable.VariableTypeComplex,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
Resources: config.Resources{
|
|
||||||
Jobs: map[string]*resources.Job{
|
|
||||||
"job1": {
|
|
||||||
JobSettings: &jobs.JobSettings{
|
|
||||||
JobClusters: []jobs.JobCluster{
|
|
||||||
{
|
|
||||||
NewCluster: compute.ClusterSpec{
|
|
||||||
NodeTypeId: "random",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
// Assign the variables to the dynamic configuration.
|
|
||||||
diags := bundle.ApplyFunc(ctx, b, func(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
|
||||||
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
|
|
||||||
var p dyn.Path
|
|
||||||
var err error
|
|
||||||
|
|
||||||
p = dyn.MustPathFromString("resources.jobs.job1.job_clusters[0].new_cluster")
|
|
||||||
v, err = dyn.SetByPath(v, p.Append(dyn.Key("node_type_id")), dyn.V("${var.cluster.node_type_id}"))
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
return v, nil
|
|
||||||
})
|
|
||||||
return diag.FromErr(err)
|
|
||||||
})
|
|
||||||
require.NoError(t, diags.Error())
|
|
||||||
|
|
||||||
diags = bundle.Apply(ctx, b, ResolveVariableReferences("bundle", "workspace", "variables"))
|
|
||||||
require.NoError(t, diags.Error())
|
|
||||||
require.Equal(t, "Standard_DS3_v2", b.Config.Resources.Jobs["job1"].JobSettings.JobClusters[0].NewCluster.NodeTypeId)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveComplexVariableReferencesWithComplexVariablesError(t *testing.T) {
|
func TestResolveComplexVariableReferencesWithComplexVariablesError(t *testing.T) {
|
||||||
b := &bundle.Bundle{
|
b := &bundle.Bundle{
|
||||||
Config: config.Root{
|
Config: config.Root{
|
||||||
|
|
Loading…
Reference in New Issue