lintball client. add tests. add help message

This commit is contained in:
Michael Hobbs
2015-01-16 15:19:14 -08:00
parent cb39110904
commit 161111aab5
2 changed files with 180 additions and 5 deletions

View File

@@ -1,9 +1,17 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
function client_help_msg() {
echo "==> Configure the DOKKU_HOST environment variable or run $0 from a repository with a git remote named dokku"
echo "--> i.e. git remote add dokku dokku@<dokku-host>:<app-name>"
exit 20 # exit with specific status. only used in units tests for now
}
if [[ -z $DOKKU_HOST ]]; then
if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then
DOKKU_HOST=$(git remote -v 2>/dev/null | grep -Ei "^dokku" | head -n 1 | cut -f1 -d' ' | cut -f2 -d '@' | cut -f1 -d':' 2>/dev/null)
DOKKU_HOST=$(git remote -v 2>/dev/null | grep -Ei "^dokku" | head -n 1 | cut -f1 -d' ' | cut -f2 -d '@' | cut -f1 -d':' 2>/dev/null || true)
else
client_help_msg
fi
fi
@@ -16,7 +24,6 @@ if [[ ! -z $DOKKU_HOST ]]; then
set -e
else
echo "This is not a git repository"
exit 1
fi
if [[ "$appname" != "" ]]; then
@@ -25,7 +32,7 @@ if [[ ! -z $DOKKU_HOST ]]; then
if [[ "$1" = "create" ]]; then
appname=$(echo "print(elfs.GenName())" | lua -l elfs)
if git remote add dokku dokku@$DOKKU_HOST:$appname
if git remote add dokku "dokku@$DOKKU_HOST:$appname"
then
echo "-----> Dokku remote added at $DOKKU_HOST"
echo "-----> Application name is $appname"
@@ -38,17 +45,19 @@ if [[ ! -z $DOKKU_HOST ]]; then
fi
if [[ -z "$donotshift" ]]; then
ssh dokku@$DOKKU_HOST $*
ssh "dokku@$DOKKU_HOST" "$*"
exit $?
fi
verb=$1
shift
ssh dokku@$DOKKU_HOST "$verb" "$appname" $@
ssh "dokku@$DOKKU_HOST" "$verb" "$appname" "$@"
}
if [[ "$0" == "dokku" ]] || [[ "$0" == *dokku_client.sh ]]; then
_dokku "$@"
exit $?
fi
else
client_help_msg
fi

166
tests/unit/client.bats Normal file
View File

@@ -0,0 +1,166 @@
#!/usr/bin/env bats
load test_helper
setup() {
export DOKKU_HOST=dokku.me
create_app
}
teardown() {
destroy_app
unset DOKKU_HOST
}
@test "dokku client (unconfigured DOKKU_HOST)" {
unset DOKKU_HOST
run ./contrib/dokku_client.sh apps
echo "output: "$output
echo "status: "$status
assert_exit_status 20
}
@test "dokku client (no args should print help)" {
run /bin/bash -c "./contrib/dokku_client.sh | head -1 | grep -q 'dokku COMMAND <app>'"
echo "output: "$output
echo "status: "$status
assert_success
}
@test "dokku client (apps:create)" {
destroy_app
run ./contrib/dokku_client.sh apps:create $TEST_APP
echo "output: "$output
echo "status: "$status
assert_success
}
@test "dokku client (apps:destroy)" {
run ./contrib/dokku_client.sh apps:destroy $TEST_APP force
echo "output: "$output
echo "status: "$status
assert_success
create_app # prevent teardown() failure
}
@test "dokku client (config:set)" {
run ./contrib/dokku_client.sh config:set $TEST_APP test_var=true test_var2=\"hello world\"
echo "output: "$output
echo "status: "$status
assert_success
run /bin/bash -c "./contrib/dokku_client.sh config:get $TEST_APP test_var2 | grep -q 'hello world'"
echo "output: "$output
echo "status: "$status
assert_success
}
@test "dokku client (config:unset)" {
run ./contrib/dokku_client.sh config:set $TEST_APP test_var=true test_var2=\"hello world\"
echo "output: "$output
echo "status: "$status
assert_success
run ./contrib/dokku_client.sh config:get $TEST_APP test_var
echo "output: "$output
echo "status: "$status
assert_success
run ./contrib/dokku_client.sh config:unset $TEST_APP test_var
echo "output: "$output
echo "status: "$status
assert_success
run /bin/bash -c "./contrib/dokku_client.sh config:get $TEST_APP test_var | grep test_var"
echo "output: "$output
echo "status: "$status
assert_failure
}
@test "dokku client (domains)" {
run bash -c "./contrib/dokku_client.sh domains $TEST_APP | grep -q ${TEST_APP}.dokku.me"
echo "output: "$output
echo "status: "$status
assert_success
}
@test "dokku client (domains:add)" {
run ./contrib/dokku_client.sh domains:add $TEST_APP www.test.app.dokku.me
echo "output: "$output
echo "status: "$status
assert_success
run ./contrib/dokku_client.sh domains:add $TEST_APP test.app.dokku.me
echo "output: "$output
echo "status: "$status
assert_success
}
@test "dokku client (domains:remove)" {
run ./contrib/dokku_client.sh domains:add $TEST_APP test.app.dokku.me
echo "output: "$output
echo "status: "$status
assert_success
run ./contrib/dokku_client.sh domains:remove $TEST_APP test.app.dokku.me
echo "output: "$output
echo "status: "$status
refute_line "test.app.dokku.me"
}
@test "dokku client (domains:clear)" {
run ./contrib/dokku_client.sh domains:add $TEST_APP test.app.dokku.me
echo "output: "$output
echo "status: "$status
assert_success
run ./contrib/dokku_client.sh domains:clear $TEST_APP
echo "output: "$output
echo "status: "$status
assert_success
}
@test "dokku client (ps)" {
# CI support: 'Ah. I just spoke with our Docker expert --
# looks like docker exec is built to work with docker-under-libcontainer,
# but we're using docker-under-lxc. I don't have an estimated time for the fix, sorry
skip "circleci does not support docker exec at the moment."
deploy_app
run bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh ps $TEST_APP | grep -q 'node web.js'"
echo "output: "$output
echo "status: "$status
assert_success
}
@test "dokku client (ps:start)" {
deploy_app
run bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh ps:stop $TEST_APP"
echo "output: "$output
echo "status: "$status
assert_success
run bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh ps:start $TEST_APP"
echo "output: "$output
echo "status: "$status
assert_success
run bash -c "docker ps -q --no-trunc | grep -q $(< $DOKKU_ROOT/$TEST_APP/CONTAINER)"
echo "output: "$output
echo "status: "$status
assert_success
}
@test "dokku client (ps:stop)" {
deploy_app
run bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh ps:stop $TEST_APP"
echo "output: "$output
echo "status: "$status
assert_success
run bash -c "docker ps -q --no-trunc | grep -q $(< $DOKKU_ROOT/$TEST_APP/CONTAINER)"
echo "output: "$output
echo "status: "$status
assert_failure
}
@test "dokku client (ps:restart)" {
deploy_app
run bash -c "${BATS_TEST_DIRNAME}/../../contrib/dokku_client.sh ps:restart $TEST_APP"
echo "output: "$output
echo "status: "$status
assert_success
run bash -c "docker ps -q --no-trunc | grep -q $(< $DOKKU_ROOT/$TEST_APP/CONTAINER)"
echo "output: "$output
echo "status: "$status
assert_success
}