Travis testing

This commit is contained in:
Jose Diaz-Gonzalez
2015-09-07 00:39:28 -04:00
parent ac2652fd92
commit b3156c5553
9 changed files with 177 additions and 66 deletions

6
.travis.yml Normal file
View File

@@ -0,0 +1,6 @@
sudo: required
language: bash
env:
- DOKKU_VERSION=master
before_install: make setup
script: make test

View File

@@ -1,17 +1,24 @@
shellcheck:
ifeq ($(shell shellcheck > /dev/null 2>&1 ; echo $$?),127)
ifeq ($(shell uname),Darwin)
brew install shellcheck
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
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse'
sudo apt-get update -qq && sudo apt-get install -qq -y shellcheck
endif
endif
bats:
ifeq ($(shell bats > /dev/null 2>&1 ; echo $$?),127)
ifeq ($(shell uname),Darwin)
git clone https://github.com/sstephenson/bats.git /tmp/bats
cd /tmp/bats && sudo ./install.sh /usr/local
rm -rf /tmp/bats
else
sudo add-apt-repository ppa:duggan/bats --yes
sudo apt-get update -qq && sudo apt-get install -qq -y bats
endif
endif
ci-dependencies: shellcheck bats
@@ -21,10 +28,14 @@ lint:
# 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
@$(QUIET) find ./ -maxdepth 1 -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
@$(QUIET) bats tests
test: ci-dependencies lint unit-tests
setup:
bash tests/setup.sh
$(MAKE) ci-dependencies
test: setup lint unit-tests

49
tests/bin/docker Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/env bash
case "$1" in
stop)
echo "testid"
;;
start)
echo "testid"
;;
kill)
echo "testid"
;;
run)
echo "testid"
;;
rm)
echo "testid"
;;
ps)
if [[ $@ = *"no-trunc"* ]]; then
echo "1479bbd60ade8a92617d2aeb4935bd3ff3179bd0fd71c22c3102c421f4bc221f"
exit 0
else
echo "CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES"
echo "testid redis:3.0.3 \"/entrypoint.sh redi 5 minutes ago Up 5 minutes 6379/tcp dokku.redis.l"
fi
;;
exec)
echo "exec called with $@"
;;
inspect)
if [[ $@ = *"IPAddress"* ]]; then
echo "172.17.0.34"
exit 0
fi
# running
echo "true"
;;
images)
echo "REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE"
echo "redis 3.0.3 9216d5a4eec8 13 days ago 109.3 MB"
;;
pull)
exit 0
;;
*)
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
;;
esac

2
tests/bin/id Executable file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
echo "dokku"

2
tests/bin/redis-cli Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
exit 0

28
tests/service.bats Normal file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bats
load test_helper
@test "(service) dokku" {
dokku $PLUGIN_COMMAND_PREFIX:create l
assert_success
dokku $PLUGIN_COMMAND_PREFIX:info l
assert_success
dokku $PLUGIN_COMMAND_PREFIX:stop l
assert_success
dokku $PLUGIN_COMMAND_PREFIX:stop l
assert_success
dokku $PLUGIN_COMMAND_PREFIX:expose l
assert_success
dokku $PLUGIN_COMMAND_PREFIX:restart l
assert_success
dokku $PLUGIN_COMMAND_PREFIX:info l
assert_success
dokku --force $PLUGIN_COMMAND_PREFIX:destroy l
assert_success
}

15
tests/setup.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test_helper.bash"
if [[ ! -d $DOKKU_ROOT ]]; then
git clone https://github.com/progrium/dokku.git $DOKKU_ROOT > /dev/null
fi
cd $DOKKU_ROOT
echo "Dokku version $DOKKU_VERSION"
git checkout $DOKKU_VERSION > /dev/null
cd -
rm -rf $DOKKU_ROOT/plugins/service
mkdir -p $DOKKU_ROOT/plugins/service
find ./ -maxdepth 1 -type f -exec cp '{}' $DOKKU_ROOT/plugins/service \;

58
tests/test_helper.bash Normal file
View File

@@ -0,0 +1,58 @@
#!/usr/bin/env bash
export DOKKU_QUIET_OUTPUT=1
export DOKKU_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/dokku"
export DOKKU_VERSION=${DOKKU_VERSION:-"master"}
export PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/bin:$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/dokku:$PATH"
export PLUGIN_COMMAND_PREFIX="postgres"
export PLUGIN_PATH="$DOKKU_ROOT/plugins"
export PLUGIN_DATA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/fixtures"
mkdir -p $PLUGIN_DATA_ROOT
flunk() {
{ if [ "$#" -eq 0 ]; then cat -
else echo "$*"
fi
}
return 1
}
assert_equal() {
if [ "$1" != "$2" ]; then
{ echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_exit_status() {
assert_equal "$status" "$1"
}
assert_success() {
if [ "$status" -ne 0 ]; then
flunk "command failed with exit status $status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_exists() {
if [ ! -f "$1" ]; then
flunk "expected file to exist: $1"
fi
}
assert_contains() {
if [[ "$1" != *"$2"* ]]; then
flunk "expected $2 to be in: $1"
fi
}
assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal "$expected" "$output"
}

View File

@@ -1,60 +0,0 @@
#!/usr/bin/env bats
export SERVICE=postgres
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
}