tests: add a test for argument handling

This commit is contained in:
Jose Diaz-Gonzalez
2024-03-13 11:06:55 -04:00
parent ca55f58446
commit e43927a69e
2 changed files with 28 additions and 1 deletions

View File

@@ -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

View File

@@ -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"
}