Skip to content

Commit

Permalink
Migrate TestResolveComplexVariable to acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
denik committed Jan 15, 2025
1 parent 626045a commit d17a71b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 58 deletions.
28 changes: 28 additions & 0 deletions acceptance/bundle/variables/complex-simple/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This example works and properly merges resources.jobs.job1.job_clusters.new_cluster and ${var.cluster}.
# retaining num_workers, spark_version and overriding node_type_id.
# However, it prints a warning "expected map, found string" which is unnecessary.
bundle:
name: TestResolveComplexVariable

variables:
type: "complex"
cluster:
value:
node_type_id: "Standard_DS3_v2"
num_workers: 2

resources:
jobs:
job1:
job_clusters:
- new_cluster:
node_type_id: "random"
spark_version: 13.3.x-scala2.12

targets:
dev:
resources:
jobs:
job1:
job_clusters:
- new_cluster: ${var.cluster}
14 changes: 14 additions & 0 deletions acceptance/bundle/variables/complex-simple/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Warning: expected map, found string
at variables.type
in databricks.yml:5:9

[
{
"job_cluster_key": "",
"new_cluster": {
"node_type_id": "Standard_DS3_v2",
"num_workers": 2,
"spark_version": "13.3.x-scala2.12"
}
}
]
1 change: 1 addition & 0 deletions acceptance/bundle/variables/complex-simple/script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$CLI bundle validate -o json | jq .resources.jobs.job1.job_clusters
58 changes: 0 additions & 58 deletions bundle/config/mutator/resolve_variable_references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,6 @@ import (
"github.com/stretchr/testify/require"
)

func TestResolveComplexVariable(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]")
v, err = dyn.SetByPath(v, p.Append(dyn.Key("new_cluster")), dyn.V("${var.cluster}"))
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)
require.Equal(t, 2, b.Config.Resources.Jobs["job1"].JobSettings.JobClusters[0].NewCluster.NumWorkers)
}

func TestResolveComplexVariableReferencesWithComplexVariablesError(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Expand Down

0 comments on commit d17a71b

Please sign in to comment.