make test
This commit is contained in:
30
Makefile
Normal file
30
Makefile
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
shellcheck:
|
||||||
|
ifeq ($(shell shellcheck > /dev/null 2>&1 ; echo $$?),127)
|
||||||
|
ifeq ($(shell uname),Darwin)
|
||||||
|
brew install shellcheck
|
||||||
|
else
|
||||||
|
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse'
|
||||||
|
sudo apt-get update && sudo apt-get install -y shellcheck
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
bats:
|
||||||
|
git clone https://github.com/sstephenson/bats.git /tmp/bats
|
||||||
|
cd /tmp/bats && sudo ./install.sh /usr/local
|
||||||
|
rm -rf /tmp/bats
|
||||||
|
|
||||||
|
ci-dependencies: shellcheck bats
|
||||||
|
|
||||||
|
lint:
|
||||||
|
# these are disabled due to their expansive existence in the codebase. we should clean it up though
|
||||||
|
# SC2046: Quote this to prevent word splitting. - https://github.com/koalaman/shellcheck/wiki/SC2046
|
||||||
|
# SC2068: Double quote array expansions, otherwise they're like $* and break on spaces. - https://github.com/koalaman/shellcheck/wiki/SC2068
|
||||||
|
# SC2086: Double quote to prevent globbing and word splitting - https://github.com/koalaman/shellcheck/wiki/SC2086
|
||||||
|
@echo linting...
|
||||||
|
@$(QUIET) find . -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC2046,SC2068,SC2086
|
||||||
|
|
||||||
|
unit-tests:
|
||||||
|
@echo running unit tests...
|
||||||
|
@$(QUIET) bats tests/unit
|
||||||
|
|
||||||
|
test: ci-dependencies lint unit-tests
|
||||||
4
commands
4
commands
@@ -75,7 +75,7 @@ case "$1" in
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
dokku_log_info1 "Deleting $SERVICE"
|
dokku_log_info1 "Deleting $SERVICE"
|
||||||
if [[ -f "$SERVICE_ROOT/ID" ]] && docker ps -aq --no-trunc | grep -q $(cat "$SERVICE_ROOT/ID"); then
|
if [[ -f "$SERVICE_ROOT/ID" ]] && docker ps -aq --no-trunc | grep -q "$(cat "$SERVICE_ROOT/ID")"; then
|
||||||
ID=$(cat "$SERVICE_ROOT/ID")
|
ID=$(cat "$SERVICE_ROOT/ID")
|
||||||
|
|
||||||
dokku_log_verbose_quiet "Deleting container data"
|
dokku_log_verbose_quiet "Deleting container data"
|
||||||
@@ -176,7 +176,7 @@ case "$1" in
|
|||||||
$PLUGIN_COMMAND_PREFIX:info)
|
$PLUGIN_COMMAND_PREFIX:info)
|
||||||
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
|
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
|
||||||
verify_service_name "$2"
|
verify_service_name "$2"
|
||||||
service_info $2
|
service_info "$2"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
$PLUGIN_COMMAND_PREFIX:list)
|
$PLUGIN_COMMAND_PREFIX:list)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ service_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
service_list() {
|
service_list() {
|
||||||
local SERVICES=$(ls $PLUGIN_DATA_ROOT 2> /dev/null)
|
local SERVICES=$(ls "$PLUGIN_DATA_ROOT" 2> /dev/null)
|
||||||
if [[ -z $SERVICES ]]; then
|
if [[ -z $SERVICES ]]; then
|
||||||
dokku_log_warn "There are no $PLUGIN_SERVICE services"
|
dokku_log_warn "There are no $PLUGIN_SERVICE services"
|
||||||
else
|
else
|
||||||
|
|||||||
8
install
8
install
@@ -2,11 +2,11 @@
|
|||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$(dirname "$0")/config"
|
source "$(dirname "$0")/config"
|
||||||
|
|
||||||
if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q $PLUGIN_IMAGE_VERSION ; then
|
if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q "$PLUGIN_IMAGE_VERSION" ; then
|
||||||
docker pull $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION
|
docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker pull svendowideit/ambassador:latest
|
docker pull svendowideit/ambassador:latest
|
||||||
|
|
||||||
mkdir -p $PLUGIN_DATA_ROOT || echo "Failed to create $PLUGIN_SERVICE directory"
|
mkdir -p "$PLUGIN_DATA_ROOT" || echo "Failed to create $PLUGIN_SERVICE directory"
|
||||||
chown dokku:dokku $PLUGIN_DATA_ROOT
|
chown dokku:dokku "$PLUGIN_DATA_ROOT"
|
||||||
|
|||||||
60
tests/unit/service.bats
Normal file
60
tests/unit/service.bats
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
export SERVICE=mysql
|
||||||
|
|
||||||
|
flunk() {
|
||||||
|
{ if [ "$#" -eq 0 ]; then cat -
|
||||||
|
else echo "$*"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_success() {
|
||||||
|
if [ "$status" -ne 0 ]; then
|
||||||
|
flunk "command failed with exit status $status"
|
||||||
|
elif [ "$#" -gt 0 ]; then
|
||||||
|
assert_output "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equal() {
|
||||||
|
if [ "$1" != "$2" ]; then
|
||||||
|
{ echo "expected: $1"
|
||||||
|
echo "actual: $2"
|
||||||
|
} | flunk
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_output() {
|
||||||
|
local expected
|
||||||
|
if [ $# -eq 0 ]; then expected="$(cat -)"
|
||||||
|
else expected="$1"
|
||||||
|
fi
|
||||||
|
assert_equal "$expected" "$output"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "(service) dokku" {
|
||||||
|
dokku $SERVICE:create l
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
dokku $SERVICE:info l
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
dokku $SERVICE:stop l
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
dokku $SERVICE:stop l
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
dokku $SERVICE:expose l
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
dokku $SERVICE:restart l
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
dokku $SERVICE:info l
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
dokku --force $SERVICE:destroy l
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user