From e43927a69e634a67ecee53b0e199452c90588e96 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 13 Mar 2024 11:06:55 -0400 Subject: [PATCH] tests: add a test for argument handling --- contrib/dokku_client.sh | 8 +++++++- tests/unit/client.bats | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/contrib/dokku_client.sh b/contrib/dokku_client.sh index 590d3d0dc..654acf03c 100755 --- a/contrib/dokku_client.sh +++ b/contrib/dokku_client.sh @@ -190,7 +190,13 @@ main() { [[ -n "$APP_ARG" ]] && [[ "$APP_ARG" == "--global" ]] && unset APP [[ -n "$@" ]] && [[ -n "$APP" ]] && app_arg="--app $APP" # echo "ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_REMOTE_HOST -- $app_arg $@" - ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_REMOTE_HOST -- $app_arg $@ || { + local ssh_args=("-o" "LogLevel=QUIET" "-p" "$DOKKU_PORT" "-t" "dokku@$DOKKU_REMOTE_HOST" "--") + if [[ -n "$app_arg" ]]; then + ssh_args+=("'$app_arg $@'") + else + ssh_args+=("$@") + fi + ssh "${ssh_args[@]}" || { ssh_exit_code="$?" echo " ! Failed to execute dokku command over ssh: exit code $?" 1>&2 echo " ! If there was no output from Dokku, ensure your configured SSH Key can connect to the remote server" 1>&2 diff --git a/tests/unit/client.bats b/tests/unit/client.bats index bfb51a64d..0c0610ea9 100644 --- a/tests/unit/client.bats +++ b/tests/unit/client.bats @@ -6,9 +6,11 @@ setup() { global_setup export "DOKKU_HOST=${DOKKU_DOMAIN}" create_app + clone_test_plugin } teardown() { + remove_test_plugin || true destroy_app unset DOKKU_HOST global_teardown @@ -311,3 +313,22 @@ teardown() { assert_success assert_output "dokku" } + +@test "(client) test-args" { + run /bin/bash -c "dokku plugin:install $TEST_PLUGIN_GIT_REPO --name $TEST_PLUGIN_NAME" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku smoke-test-plugin:args bash -c 'echo Hello'" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "triggered smoke-test-plugin:args with args: smoke-test-plugin:args, bash, -c, echo Hello" + + run /bin/bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh 'smoke-test-plugin:args bash -c \"echo Hello\"'" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "triggered smoke-test-plugin:args with args: smoke-test-plugin:args, bash, -c, echo Hello" +}