这是indexloc提供的服务,不要输入任何密码
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
9 changes: 7 additions & 2 deletions contrib/dokku_client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ main() {
[[ " storage:ensure-directory " == *" $CMD "* ]] && unset APP
[[ "$CMD" =~ events*|plugin*|ssh-keys* ]] && unset APP
[[ -n "$APP_ARG" ]] && [[ "$APP_ARG" == "--global" ]] && unset APP
[[ -n "$@" ]] && [[ -n "$APP" ]] && app_arg="--app $APP"
if [[ -n "$@" ]] && [[ -n "$APP" ]]; then
set -- "$APP" "$@"
set -- "--app" "$@"
fi
# 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" "--")
ssh_args+=("$@")
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
Expand Down
15 changes: 10 additions & 5 deletions dokku
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,20 @@ fi

if [[ -n "$SSH_ORIGINAL_COMMAND" ]]; then
export -n SSH_ORIGINAL_COMMAND
if [[ $1 =~ config-* ]] || [[ $1 =~ docker-options* ]]; then
xargs $0 <<<$SSH_ORIGINAL_COMMAND
exit $?
else
exit_code=0
if [[ $1 =~ git-* ]] || [[ $1 =~ git:* ]]; then
set -f
$0 $SSH_ORIGINAL_COMMAND
exit_code=$?
set +f
else
readarray -t -O "${#ssh_arg_array[@]}" ssh_arg_array < <(printf '%s' "$SSH_ORIGINAL_COMMAND" | xargs -n 1)
set -f
$0 "${ssh_arg_array[@]}"
exit_code=$?
set +f
exit $?
fi
exit $exit_code
fi

if ! dokku_auth "$@"; then
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/client.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
12 changes: 0 additions & 12 deletions tests/unit/plugin.bats
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
#!/usr/bin/env bats

load test_helper
TEST_PLUGIN_NAME=smoke-test-plugin
TEST_PLUGIN_GIT_REPO=https://github.com/dokku/${TEST_PLUGIN_NAME}.git
TEST_PLUGIN_LOCAL_REPO="$(mktemp -d)/$TEST_PLUGIN_NAME"

clone_test_plugin() {
git clone "$TEST_PLUGIN_GIT_REPO" "$TEST_PLUGIN_LOCAL_REPO"
}

setup() {
global_setup
clone_test_plugin
}

remove_test_plugin() {
rm -rf $PLUGIN_ENABLED_PATH/$TEST_PLUGIN_NAME $PLUGIN_AVAILABLE_PATH/$TEST_PLUGIN_NAME
rm -rf $TEST_PLUGIN_LOCAL_REPO
}

teardown() {
remove_test_plugin || true
global_teardown
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ UUID=$(uuidgen)
TEST_APP="rdmtestapp-${UUID}"
TEST_NETWORK="test-network-${UUID}"
SKIPPED_TEST_ERR_MSG="previous test failed! skipping remaining tests..."
TEST_PLUGIN_NAME=smoke-test-plugin
TEST_PLUGIN_GIT_REPO=https://github.com/dokku/${TEST_PLUGIN_NAME}.git
TEST_PLUGIN_LOCAL_REPO="$(mktemp -d)/$TEST_PLUGIN_NAME"

# global setup() and teardown()
# skips remaining tests on first failure
Expand Down Expand Up @@ -45,6 +48,15 @@ cleanup_containers() {
fi
}

clone_test_plugin() {
git clone "$TEST_PLUGIN_GIT_REPO" "$TEST_PLUGIN_LOCAL_REPO"
}

remove_test_plugin() {
rm -rf "${PLUGIN_ENABLED_PATH:?}/$TEST_PLUGIN_NAME" "${PLUGIN_AVAILABLE_PATH:?}/$TEST_PLUGIN_NAME"
rm -rf "$TEST_PLUGIN_LOCAL_REPO"
}

# test functions
flunk() {
{
Expand Down