From 822a0259f9db7fda29b87060f5ea4b284d1156b8 Mon Sep 17 00:00:00 2001 From: Edgars Beigarts Date: Wed, 24 Feb 2016 09:16:59 +0200 Subject: [PATCH] Fix exit code for mongo:export when SSH_TTY is not present --- commands | 2 ++ tests/service_export.bats | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/commands b/commands index 1051ffe..fb73807 100755 --- a/commands +++ b/commands @@ -122,7 +122,9 @@ case "$1" in [[ -n $SSH_TTY ]] && stty -opost docker exec "$SERVICE_NAME" bash -c "DIR=\$(mktemp -d) && mongodump -d $SERVICE -o \"\$DIR\" -u \"$SERVICE\" -p \"$PASSWORD\" --authenticationDatabase \"$SERVICE\" 1>&2 && tar cf - -C \"\$DIR\" . && rm -rf \"\$DIR\"" + status=$? [[ -n $SSH_TTY ]] && stty opost + exit $status ;; $PLUGIN_COMMAND_PREFIX:import) diff --git a/tests/service_export.bats b/tests/service_export.bats index 38a9746..ff32716 100755 --- a/tests/service_export.bats +++ b/tests/service_export.bats @@ -21,10 +21,20 @@ teardown() { assert_contains "${lines[*]}" "service not_existing_service does not exist" } -@test "($PLUGIN_COMMAND_PREFIX:export) success" { +@test "($PLUGIN_COMMAND_PREFIX:export) success with SSH_TTY" { export ECHO_DOCKER_COMMAND="true" + export SSH_TTY=`tty` run dokku "$PLUGIN_COMMAND_PREFIX:export" l password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" + assert_exit_status 0 assert_output "docker exec dokku.mongo.l bash -c DIR=\$(mktemp -d) && mongodump -d l -o \"\$DIR\" -u \"l\" -p \"$password\" --authenticationDatabase \"l\" 1>&2 && tar cf - -C \"\$DIR\" . && rm -rf \"\$DIR\"" } +@test "($PLUGIN_COMMAND_PREFIX:export) success without SSH_TTY" { + export ECHO_DOCKER_COMMAND="true" + unset SSH_TTY + run dokku "$PLUGIN_COMMAND_PREFIX:export" l + password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" + assert_exit_status 0 + assert_output "docker exec dokku.mongo.l bash -c DIR=\$(mktemp -d) && mongodump -d l -o \"\$DIR\" -u \"l\" -p \"$password\" --authenticationDatabase \"l\" 1>&2 && tar cf - -C \"\$DIR\" . && rm -rf \"\$DIR\"" +}