-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialize dynamic value for
bundle validate
output (#1499)
## Changes Using dynamic values allows us to retain references like `${resources.jobs...}` even when the type of field is not integer, eg: `run_job_task`, or in general values that do not map to the Go types for a field. ## Tests Integration test
- Loading branch information
1 parent
274688d
commit 553fdd1
Showing
6 changed files
with
122 additions
and
27 deletions.
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
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
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
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,60 @@ | ||
package bundle | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/databricks/cli/internal/testutil" | ||
"github.com/databricks/cli/libs/dyn" | ||
"github.com/databricks/cli/libs/dyn/convert" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAccBundleValidate(t *testing.T) { | ||
testutil.GetEnvOrSkipTest(t, "CLOUD_ENV") | ||
|
||
tmpDir := t.TempDir() | ||
testutil.WriteFile(t, | ||
` | ||
bundle: | ||
name: "foobar" | ||
resources: | ||
jobs: | ||
outer_loop: | ||
name: outer loop | ||
tasks: | ||
- task_key: my task | ||
run_job_task: | ||
job_id: ${resources.jobs.inner_loop.id} | ||
inner_loop: | ||
name: inner loop | ||
`, tmpDir, "databricks.yml") | ||
|
||
ctx := context.Background() | ||
stdout, err := validateBundle(t, ctx, tmpDir) | ||
require.NoError(t, err) | ||
|
||
config := make(map[string]any) | ||
err = json.Unmarshal(stdout, &config) | ||
require.NoError(t, err) | ||
|
||
getValue := func(key string) any { | ||
v, err := convert.FromTyped(config, dyn.NilValue) | ||
require.NoError(t, err) | ||
v, err = dyn.GetByPath(v, dyn.MustPathFromString(key)) | ||
require.NoError(t, err) | ||
return v.AsAny() | ||
} | ||
|
||
assert.Equal(t, "foobar", getValue("bundle.name")) | ||
assert.Equal(t, "outer loop", getValue("resources.jobs.outer_loop.name")) | ||
assert.Equal(t, "inner loop", getValue("resources.jobs.inner_loop.name")) | ||
assert.Equal(t, "my task", getValue("resources.jobs.outer_loop.tasks[0].task_key")) | ||
// Assert resource references are retained in the output. | ||
assert.Equal(t, "${resources.jobs.inner_loop.id}", getValue("resources.jobs.outer_loop.tasks[0].run_job_task.job_id")) | ||
} |
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,48 @@ | ||
package testutil | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TouchNotebook(t *testing.T, elems ...string) string { | ||
path := filepath.Join(elems...) | ||
err := os.MkdirAll(filepath.Dir(path), 0755) | ||
require.NoError(t, err) | ||
|
||
err = os.WriteFile(path, []byte("# Databricks notebook source"), 0644) | ||
require.NoError(t, err) | ||
return path | ||
} | ||
|
||
func Touch(t *testing.T, elems ...string) string { | ||
path := filepath.Join(elems...) | ||
err := os.MkdirAll(filepath.Dir(path), 0755) | ||
require.NoError(t, err) | ||
|
||
f, err := os.Create(path) | ||
require.NoError(t, err) | ||
|
||
err = f.Close() | ||
require.NoError(t, err) | ||
return path | ||
} | ||
|
||
func WriteFile(t *testing.T, content string, elems ...string) string { | ||
path := filepath.Join(elems...) | ||
err := os.MkdirAll(filepath.Dir(path), 0755) | ||
require.NoError(t, err) | ||
|
||
f, err := os.Create(path) | ||
require.NoError(t, err) | ||
|
||
_, err = f.WriteString(content) | ||
require.NoError(t, err) | ||
|
||
err = f.Close() | ||
require.NoError(t, err) | ||
return path | ||
} |
This file was deleted.
Oops, something went wrong.