Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bundle/config/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"reflect"
"testing"

"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/bundle/config/variable"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -252,3 +254,30 @@
assert.Equal(t, tc.expected, isFullVariableOverrideDef(tc.value), "test case %d", i)
}
}

const inputJob = `{"deployment":{"kind":"BUNDLE","metadata_file_path":"/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json"},"edit_mode":"UI_LOCKED","format":"MULTI_TASK","max_concurrent_runs":1,"name":"job foo","permissions":[],"queue":{"enabled":true},"tasks":[{"run_job_task":{"job_id":"${resources.jobs.bar.id}"},"task_key":"job_task"}]}`

// I'm expecting either:
// a) job_id is ignored, everything else is parsed
// b) an error
// However, what happens is task_key gets zeroed out:
// const expectedOut = `{"deployment":{"kind":"BUNDLE","metadata_file_path":"/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json"},"edit_mode":"UI_LOCKED","format":"MULTI_TASK","max_concurrent_runs":1,"name":"job foo","permissions":[],"queue":{"enabled":true},"tasks":[{"run_job_task":{"job_id":0},"task_key":"job_task"}]}`
const actualOut = `{"deployment":{"kind":"BUNDLE","metadata_file_path":"/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json"},"edit_mode":"UI_LOCKED","format":"MULTI_TASK","lifecycle":{},"max_concurrent_runs":1,"name":"job foo","queue":{"enabled":true},"tasks":[{"run_job_task":{"job_id":0},"task_key":""}]}`

func TestUnmarshalResourceJob(t *testing.T) {
x := resources.Job{}
err := json.Unmarshal([]byte(inputJob), &x)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if/where this error gets swallowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I did not debug this further than this.


newBytes, err := json.Marshal(x)
require.NoError(t, err)
assert.Equal(t, actualOut, string(newBytes))
}

func TestUnmarshalJobSettings(t *testing.T) {
// When parsing into jobs.JobSettings directly, error is raised:
x := jobs.JobSettings{}
err := json.Unmarshal([]byte(inputJob), &x)
require.Error(t, err)
require.Equal(t, err.Error(), "invalid character 'r' after top-level value")

Check failure on line 282 in bundle/config/root_test.go

View workflow job for this annotation

GitHub Actions / lint

expected-actual: need to reverse actual and expected values (testifylint)
}
Loading