Merge pull request #4335 from dokku/4313-plugin-update
Add error checking to plugin:install and plugin:update
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ cmd-plugin-install() {
|
||||
plugn trigger install
|
||||
;;
|
||||
*)
|
||||
if [[ -n "$FLAG" ]]; then
|
||||
dokku_log_warn "First argument must be --core or url to plugin"
|
||||
dokku_log_warn "Valid prefixes: https:, git:, ssh:, file:"
|
||||
dokku_log_warn "Valid suffixes: .tar.gz, .tgz"
|
||||
dokku_log_fail "Please retry with valid arguments"
|
||||
fi
|
||||
plugn trigger install
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,80 @@ teardown() {
|
||||
assert_output_contains "dokku" "3"
|
||||
}
|
||||
|
||||
@test "(plugin) plugin:install [errors]" {
|
||||
run /bin/bash -c "dokku plugin:install YABBA_DABBA_DOO XXXX YYYY"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Please retry with valid arguments"
|
||||
|
||||
run /bin/bash -c "dokku plugin:install ZXZX --random-flag"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Please retry with valid arguments"
|
||||
|
||||
run /bin/bash -c "dokku plugin:install http://www.example.com/ --random-flag"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Please retry with valid arguments"
|
||||
|
||||
run /bin/bash -c "dokku plugin:install http://www.example.com/gives-a-404"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Please retry with valid arguments"
|
||||
|
||||
run /bin/bash -c "dokku plugin:install http://xxxx/ --random-flag"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Please retry with valid arguments"
|
||||
|
||||
run /bin/bash -c "dokku plugin:install /path/to/nonexistent/dir"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Please retry with valid arguments"
|
||||
}
|
||||
|
||||
@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"
|
||||
|
||||
Reference in New Issue
Block a user