Skip to content
Merged
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
2 changes: 1 addition & 1 deletion acceptance/pipelines/databricks-cli-help/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Main Commands
run Run a pipeline
show Preview a table's columns and sample rows
stop Stop a pipeline
test *Preview* Run the tests of a pipeline
test *Experimental* Run the tests of a pipeline

Management Commands
apply-environment *Public Preview* Apply the latest environment to the pipeline.
Expand Down
4 changes: 2 additions & 2 deletions acceptance/pipelines/test/immutable/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Files: 0 uploaded, 0 deleted
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
View your pipeline my_pipeline here: [DATABRICKS_URL]/pipelines/[UUID][0]?w=[WORKSPACE_ID]

=== Local test paths are not supported with workspace.sync_mode immutable
=== Relative test paths are rejected with workspace.sync_mode immutable

>>> musterr [CLI] pipelines test my_pipeline tests/test_orders.py::test_backfill
Recommendation: This command runs the last deployed version of the code

If you've made local changes, run 'databricks pipelines deploy' first to ensure they are included.

Error: cannot resolve test selection "tests/test_orders.py::test_backfill": local test paths are not supported with workspace.sync_mode immutable; pass an absolute workspace path
Error: cannot resolve test selection "tests/test_orders.py::test_backfill": relative test paths need synced local files, but workspace.sync_mode is immutable; pass the /Workspace path

=== Absolute workspace paths and running all tests still work

Expand Down
2 changes: 1 addition & 1 deletion acceptance/pipelines/test/immutable/script
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
trace $CLI pipelines deploy
rm "$OUT_REQUESTS"

title "Local test paths are not supported with workspace.sync_mode immutable"
title "Relative test paths are rejected with workspace.sync_mode immutable"
trace musterr $CLI pipelines test my_pipeline tests/test_orders.py::test_backfill

title "Absolute workspace paths and running all tests still work"
Expand Down
10 changes: 5 additions & 5 deletions acceptance/pipelines/test/selection/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ Update: [UUID][2]
"body": {
"test_only": true,
"test_options": {
"test_selection": [
"/Workspace/Users/[USERNAME]/.bundle/test-pipeline-test-selection/default/files/tests",
"/Workspace/Users/[USERNAME]/.bundle/test-pipeline-test-selection/default/files/tests/test_orders.py::test_backfill",
"/Workspace/Users/someone@example.com/tests/test_other.py"
],
"pytest_args": [
"-k",
"orders and not slow",
"-m",
"smoke,fast"
],
"test_selection": [
"/Workspace/Users/[USERNAME]/.bundle/test-pipeline-test-selection/default/files/tests",
"/Workspace/Users/[USERNAME]/.bundle/test-pipeline-test-selection/default/files/tests/test_orders.py::test_backfill",
"/Workspace/Users/someone@example.com/tests/test_other.py"
]
}
}
Expand Down
47 changes: 10 additions & 37 deletions cmd/pipelines/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"io/fs"
"maps"
"net/http"
"os"
"path"
"path/filepath"
Expand All @@ -20,36 +19,23 @@ import (
"github.com/databricks/cli/bundle/resources"
"github.com/databricks/cli/cmd/bundle/utils"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/cmdgroup"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/cli/libs/logdiag"
"github.com/databricks/cli/libs/shellquote"
databricks "github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/service/pipelines"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

// startTestUpdateRequest is the Start Update body of a test run.
// test_only and test_options are not in the Go SDK yet, so the request is sent directly.
type startTestUpdateRequest struct {
TestOnly bool `json:"test_only"`
TestOptions *testOptions `json:"test_options,omitempty"`
}

type testOptions struct {
TestSelection []string `json:"test_selection,omitempty"`
PytestArgs []string `json:"pytest_args,omitempty"`
}

func newStartTestUpdateRequest(selection, pytestArgs []string) startTestUpdateRequest {
req := startTestUpdateRequest{TestOnly: true}
// newStartTestUpdateRequest returns the Start Update request of a test run.
func newStartTestUpdateRequest(selection, pytestArgs []string) pipelines.StartUpdate {
req := pipelines.StartUpdate{TestOnly: true}
if len(selection) > 0 || len(pytestArgs) > 0 {
req.TestOptions = &testOptions{TestSelection: selection, PytestArgs: pytestArgs}
req.TestOptions = &pipelines.PipelineTestOptions{TestSelection: selection, PytestArgs: pytestArgs}
}
return req
}
Expand Down Expand Up @@ -134,7 +120,7 @@ func bundleWorkspacePath(cwd, syncRoot, filesRoot, localPath string) (string, er
}
rel, err := filepath.Rel(syncRoot, localPath)
if err != nil || !filepath.IsLocal(rel) {
return "", fmt.Errorf("%s is outside the synchronized bundle files in %s", filepath.ToSlash(localPath), filepath.ToSlash(syncRoot))
return "", fmt.Errorf("%s is not in the files synced from %s; pass its /Workspace path", filepath.ToSlash(localPath), filepath.ToSlash(syncRoot))
}
return path.Join(filesRoot, filepath.ToSlash(rel)), nil
}
Expand All @@ -156,7 +142,7 @@ func bundleFilesRoot(b *bundle.Bundle) string {
// under filesRoot. The path must exist locally, so that a typo fails before compute starts.
func bundleTestSelectionPath(cwd, syncRoot, filesRoot, localPath string) (string, error) {
if filesRoot == "" {
return "", errors.New("local test paths are not supported with workspace.sync_mode immutable; pass an absolute workspace path")
return "", errors.New("relative test paths need synced local files, but workspace.sync_mode is immutable; pass the /Workspace path")
}
workspacePath, err := bundleWorkspacePath(cwd, syncRoot, filesRoot, localPath)
if err != nil {
Expand Down Expand Up @@ -205,22 +191,9 @@ func getRootPath(ctx context.Context, w *databricks.WorkspaceClient, pipelineID
}

// startTestUpdate starts a test-only update and returns its ID.
func startTestUpdate(ctx context.Context, w *databricks.WorkspaceClient, pipelineID string, req startTestUpdateRequest) (string, error) {
apiClient, err := client.New(w.Config)
if err != nil {
return "", fmt.Errorf("failed to create API client: %w", err)
}

var response pipelines.StartUpdateResponse
err = apiClient.Do(
ctx,
http.MethodPost,
fmt.Sprintf("/api/2.0/pipelines/%s/updates", pipelineID),
auth.WorkspaceIDHeaders(w.Config),
nil,
req,
&response,
)
func startTestUpdate(ctx context.Context, w *databricks.WorkspaceClient, pipelineID string, req pipelines.StartUpdate) (string, error) {
req.PipelineId = pipelineID
response, err := w.Pipelines.StartUpdate(ctx, req)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -333,7 +306,7 @@ func notPipelineKeyError(cmd *cobra.Command, b *bundle.Bundle, key string, args
func testCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "test [flags] [KEY] [TEST_SELECTION...]",
Short: "*Preview* Run the tests of a pipeline",
Short: "*Experimental* Run the tests of a pipeline",
Long: `Run the tests of a pipeline in a test-only update.

This command is experimental. Set DATABRICKS_CLI_PIPELINES_TEST=true to enable it.
Expand Down
Loading
Loading