Skip to content

Convert TestAbortBind to an acceptance test #3111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@
=== Create a pre-defined job:
Created job with ID: [NUMID]

=== Bind job:
=== Expect binding to fail without an auto-approve flag:
Error: failed to bind the resource, err: This bind operation requires user confirmation, but the current console does not support prompting. Please specify --auto-approve if you would like to skip prompts and proceed.

=== Check that job is not bound and not updated with config from bundle:
>>> [CLI] jobs get [NUMID]
{
"job_id": [NUMID],
"settings": {
"name": "test-job-bind-[UNIQUE_NAME]",
"tasks": [
{
"task_key": "my_notebook_task",
"spark_python_task": {
"python_file": "/Workspace/Users/[USERNAME]/initial_hello_world.py"
}
}
]
}
}

=== Bind job with auto-approve:
>>> [CLI] bundle deployment bind foo [NUMID] --auto-approve
Updating deployment state...
Successfully bound job with an id '[NUMID]'. Run 'bundle deploy' to deploy changes to your workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ cleanup() {
}
trap cleanup EXIT

title "Bind job:"
title "Expect binding to fail without an auto-approve flag:\n"
trace errcode $CLI bundle deployment bind foo $JOB_ID &> out.bind-result.txt
grep "^Error:" out.bind-result.txt
rm out.bind-result.txt

title "Check that job is not bound and not updated with config from bundle:"
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a missing deploy in between the failed bind and the job get.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I realized that this needs to be a separate test, created it here: #3116

trace $CLI jobs get $JOB_ID | jq '{job_id, settings: {name: .settings.name, tasks: [.settings.tasks[] | {task_key, spark_python_task: .spark_python_task}]}}'

title "Bind job with auto-approve:"
trace $CLI bundle deployment bind foo $JOB_ID --auto-approve

title "Remove .databricks directory to simulate fresh deployment:"
Expand Down
45 changes: 0 additions & 45 deletions integration/bundle/bind_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,13 @@ import (

"github.com/databricks/cli/integration/internal/acc"
"github.com/databricks/cli/internal/testcli"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/cli/libs/env"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAbortBind(t *testing.T) {
ctx, wt := acc.WorkspaceTest(t)
gt := &generateJobTest{T: wt, w: wt.W}

nodeTypeId := testutil.GetCloud(t).NodeTypeID()
uniqueId := uuid.New().String()
bundleRoot := initTestTemplate(t, ctx, "basic", map[string]any{
"unique_id": uniqueId,
"spark_version": "13.3.x-scala2.12",
"node_type_id": nodeTypeId,
})

jobId := gt.createTestJob(ctx)
t.Cleanup(func() {
gt.destroyJob(ctx, jobId)
destroyBundle(t, ctx, bundleRoot)
})

// Bind should fail because prompting is not possible.
ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
ctx = env.Set(ctx, "TERM", "dumb")
c := testcli.NewRunner(t, ctx, "bundle", "deployment", "bind", "foo", strconv.FormatInt(jobId, 10))

// Expect error suggesting to use --auto-approve
_, _, err := c.Run()
assert.ErrorContains(t, err, "failed to bind the resource")
assert.ErrorContains(t, err, "This bind operation requires user confirmation, but the current console does not support prompting. Please specify --auto-approve if you would like to skip prompts and proceed")

deployBundle(t, ctx, bundleRoot)

w, err := databricks.NewWorkspaceClient()
require.NoError(t, err)

// Check that job is not bound and not updated with config from bundle
job, err := w.Jobs.Get(ctx, jobs.GetJobRequest{
JobId: jobId,
})
require.NoError(t, err)

require.NotEqual(t, job.Settings.Name, "test-job-basic-"+uniqueId)
require.Contains(t, job.Settings.Tasks[0].NotebookTask.NotebookPath, "test")
}

func TestGenerateAndBind(t *testing.T) {
ctx, wt := acc.WorkspaceTest(t)
gt := &generateJobTest{T: wt, w: wt.W}
Expand Down
Loading