add tests and prompt to unlock

This commit is contained in:
arturs committed 2021-03-11 17:41:39 +02:00
1 parent 5ae531ca25
commit 8d11789566
2 files changed
+56 -4

No files matched your search

+24 -4
View File
@@ -231,14 +231,34 @@ cmd-git-unlock() {
declare desc="removes the clone folder for an app" declare desc="removes the clone folder for an app"
local cmd="git:unlock" local cmd="git:unlock"
[[ "$1" == "$cmd" ]] && shift 1 [[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" declare APP="$1" FLAG
for arg in "$@"; do
if [[ "$arg" == "--force" ]]; then
FLAG="--force"
continue
fi
ARGS+=("$arg")
done
local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP" local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP"
if [[ -d "$APP_CLONE_ROOT" ]]; then if [[ -d "$APP_CLONE_ROOT" ]]; then
dokku_log_info1 "About to delete $APP_CLONE_ROOT" if [[ "$FLAG" == "--force" ]]; then
rm -rf "$APP_CLONE_ROOT" dokku_log_info1 "About to delete $APP_CLONE_ROOT"
dokku_log_info1 "Successfully unlocked $APP" rm -rf "$APP_CLONE_ROOT"
dokku_log_info1 "Successfully unlocked $APP"
else
read -rp "Are you sure that want to delete clone folder (y/n)?" choice
case "$choice" in
y|Y ) dokku_log_info1 "About to delete $APP_CLONE_ROOT"
rm -rf "$APP_CLONE_ROOT"
dokku_log_info1 "Successfully unlocked $APP";;
n|N ) echo "no";;
* ) echo "please answer with yes or no";;
esac
fi
else else
dokku_log_info1 "No clone folder exists app already unlocked" dokku_log_info1 "No clone folder exists app already unlocked"
fi fi
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bats
load test_helper
setup() {
global_setup
create_app
touch /home/dokku/.ssh/known_hosts
chown dokku:dokku /home/dokku/.ssh/known_hosts
touch /home/dokku/data/git/$TEST_APP
}
teardown() {
rm -f /home/dokku/.ssh/id_rsa.pub || true
destroy_app
global_teardown
}
@test "(git) git:unlock [succes]" {
run /bin/bash -c "dokku git:unlock $TEST_APP --force"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(git) git:unlock [missing]" {
run /bin/bash -c "dokku git:unlock
echo "output: $output"
echo "status: $status"
assert_failure
}