fix: add error checking to plugin:update

Closes #4313
This commit is contained in:
Jose Diaz-Gonzalez
2021-01-17 22:23:04 -05:00
parent e64b69248a
commit 89cc896c27
3 changed files with 81 additions and 2 deletions

View File

@@ -33,3 +33,33 @@ plugin_prime_bash_completion() {
dokku_log_info1_quiet "Priming bash-completion cache"
dokku --quiet help --all | awk '/^ /{ print $1 }' | sort >"/var/cache/dokku-completion"
}
fn-is-core-plugin() {
declare PLUGIN_NAME="$1"
if [[ -L "$PLUGIN_CORE_ENABLED_PATH/$PLUGIN_NAME" ]]; then
return 0
fi
return 1
}
fn-is-valid-plugin() {
declare PLUGIN_NAME="$1"
if [[ "$PLUGIN_NAME" =~ ^[0-9a-zA-Z_-]+$ ]]; then
return 0
fi
return 1
}
fn-plugin-enabled() {
declare PLUGIN_NAME="$1"
if [[ -L "$PLUGIN_ENABLED_PATH/$PLUGIN_NAME" ]]; then
return 0
fi
return 1
}

View File

@@ -10,8 +10,21 @@ cmd-plugin-update() {
declare PLUGIN="$1" PLUGIN_COMMITTISH="$2"
if [[ -n "$PLUGIN" ]]; then
if ! fn-is-valid-plugin "$PLUGIN"; then
dokku_log_fail "Invalid plugin name specified"
fi
if ! fn-plugin-enabled "$PLUGIN"; then
dokku_log_fail "Specified plugin not enabled or installed"
fi
if fn-is-core-plugin "$PLUGIN"; then
dokku_log_fail "Cannot trigger plugin:update against core plugin, please update Dokku instead"
fi
plugn update "$PLUGIN" "$PLUGIN_COMMITTISH"
fi
plugn trigger update
plugin_prime_bash_completion
}

View File

@@ -42,7 +42,7 @@ teardown() {
run /bin/bash -c "dokku plugin:installed $TEST_PLUGIN_NAME"
echo "output: $output"
echo "status: $status"
assert_failure
assert_failure
run /bin/bash -c "dokku plugin:install $TEST_PLUGIN_GIT_REPO --name $TEST_PLUGIN_NAME"
echo "output: $output"
@@ -52,7 +52,7 @@ teardown() {
run /bin/bash -c "dokku plugin:installed $TEST_PLUGIN_NAME"
echo "output: $output"
echo "status: $status"
assert_success
assert_success
run /bin/bash -c "dokku plugin:update $TEST_PLUGIN_NAME"
echo "output: $output"
@@ -214,6 +214,42 @@ teardown() {
assert_output_contains "dokku" "3"
}
@test "(plugin) plugin:update [errors]" {
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 plugin:disable $TEST_PLUGIN_NAME"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku plugin:update $TEST_PLUGIN_NAME"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Specified plugin not enabled or installed"
run /bin/bash -c "dokku plugin:update invalid"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Specified plugin not enabled or installed"
run /bin/bash -c "dokku plugin:update $TEST_PLUGIN_GIT_REPO"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Invalid plugin name specified"
run /bin/bash -c "dokku plugin:update app-json"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "please update Dokku instead"
}
@test "(plugin) plugin:update permissions set properly" {
run /bin/bash -c "ls -lah /var/lib/dokku/core-plugins/available/git/commands"
echo "output: $output"