From 6002e0d0402525e3c265fbb44f177ae91ef245bb Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Mar 2025 14:01:41 +0100 Subject: [PATCH] some more tests --- acceptance/acceptance_test.go | 2 +- acceptance/bundle/exec/basic/databricks.yml | 2 ++ acceptance/bundle/exec/basic/output.txt | 5 +++-- acceptance/bundle/exec/basic/script | 2 +- acceptance/bundle/exec/no-separator/output.txt | 5 +++++ acceptance/bundle/exec/no-separator/script | 1 + cmd/bundle/exec.go | 8 ++++---- 7 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 acceptance/bundle/exec/basic/databricks.yml create mode 100644 acceptance/bundle/exec/no-separator/output.txt create mode 100644 acceptance/bundle/exec/no-separator/script diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index f8b259643..066a84299 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -41,7 +41,7 @@ var ( // In order to debug CLI running under acceptance test, set this to full subtest name, e.g. "bundle/variables/empty" // Then install your breakpoints and click "debug test" near TestAccept in VSCODE. // example: var SingleTest = "bundle/variables/empty" -var SingleTest = "bundle/exec/basic" +var SingleTest = "" // If enabled, instead of compiling and running CLI externally, we'll start in-process server that accepts and runs // CLI commands. The $CLI in test scripts is a helper that just forwards command-line arguments to this server (see bin/callserver.py). diff --git a/acceptance/bundle/exec/basic/databricks.yml b/acceptance/bundle/exec/basic/databricks.yml new file mode 100644 index 000000000..432311dab --- /dev/null +++ b/acceptance/bundle/exec/basic/databricks.yml @@ -0,0 +1,2 @@ +bundle: + name: foobar diff --git a/acceptance/bundle/exec/basic/output.txt b/acceptance/bundle/exec/basic/output.txt index bc6165d26..d45ebfb83 100644 --- a/acceptance/bundle/exec/basic/output.txt +++ b/acceptance/bundle/exec/basic/output.txt @@ -1,5 +1,6 @@ ->>> errcode [CLI] bundle exec -- echo Hello, World! -Error: Please add a '--' separator. Usage: 'databricks bundle exec -- arg1 arg2 ...' +>>> errcode [CLI] bundle exec -- echo hello +hello +Error: Error waiting for command: exec: Wait was already called Exit code: 1 diff --git a/acceptance/bundle/exec/basic/script b/acceptance/bundle/exec/basic/script index f0d714b9a..c65cd19ea 100644 --- a/acceptance/bundle/exec/basic/script +++ b/acceptance/bundle/exec/basic/script @@ -1 +1 @@ -trace errcode $CLI bundle exec echo "Hello,\ World" +trace errcode $CLI bundle exec -- echo hello diff --git a/acceptance/bundle/exec/no-separator/output.txt b/acceptance/bundle/exec/no-separator/output.txt new file mode 100644 index 000000000..ef7b6f1ce --- /dev/null +++ b/acceptance/bundle/exec/no-separator/output.txt @@ -0,0 +1,5 @@ + +>>> [CLI] bundle exec echo hello +Error: Please add a '--' separator. Usage: 'databricks bundle exec -- echo hello' + +Exit code: 1 diff --git a/acceptance/bundle/exec/no-separator/script b/acceptance/bundle/exec/no-separator/script new file mode 100644 index 000000000..050538fa4 --- /dev/null +++ b/acceptance/bundle/exec/no-separator/script @@ -0,0 +1 @@ +trace $CLI bundle exec echo hello diff --git a/cmd/bundle/exec.go b/cmd/bundle/exec.go index 11b38ef18..daeb0c4a2 100644 --- a/cmd/bundle/exec.go +++ b/cmd/bundle/exec.go @@ -25,8 +25,8 @@ func newExecCommand() *cobra.Command { Short: "Execute a command using the same authentication context as the bundle", Args: cobra.MinimumNArgs(1), Long: `Examples: -1. databricks bundle exec -- echo "Hello, world!" -2. databricks bundle exec -- /bin/bash -c "echo 'Hello, world!'" +1. databricks bundle exec -- echo hello +2. databricks bundle exec -- /bin/bash -c "echo hello"" 3. databricks bundle exec -- uv run pytest"`, RunE: func(cmd *cobra.Command, args []string) error { if cmd.ArgsLenAtDash() != 0 { @@ -41,7 +41,7 @@ func newExecCommand() *cobra.Command { return diags.Error() } - childCmd := exec.Command(args[1], args[2:]...) + childCmd := exec.Command(args[0], args[1:]...) childCmd.Env = auth.ProcessEnv(root.ConfigUsed(cmd.Context())) // Create pipes for stdout and stderr @@ -82,7 +82,7 @@ func newExecCommand() *cobra.Command { // Wait for the command to finish. // TODO: Pretty exit codes? - // TODO: Make CLI return the same exit codes? + // TODO: Make CLI return the same exit codes? It has to, that's a requirement. err = childCmd.Wait() if exitErr, ok := err.(*exec.ExitError); ok { return fmt.Errorf("Command exited with code: %d", exitErr.ExitCode())