Skip to content

Commit 7a558e0

Browse files
committed
Travis testing
1 parent 3481b5a commit 7a558e0

File tree

9 files changed

+177
-66
lines changed

9 files changed

+177
-66
lines changed

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sudo: required
2+
language: bash
3+
env:
4+
- DOKKU_VERSION=master
5+
before_install: make setup
6+
script: make test

Makefile

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
shellcheck:
22
ifeq ($(shell shellcheck > /dev/null 2>&1 ; echo $$?),127)
33
ifeq ($(shell uname),Darwin)
4-
brew install shellcheck
4+
brew install shellcheck
55
else
6-
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse'
7-
sudo apt-get update && sudo apt-get install -y shellcheck
6+
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse'
7+
sudo apt-get update -qq && sudo apt-get install -qq -y shellcheck
88
endif
99
endif
1010

1111
bats:
12+
ifeq ($(shell bats > /dev/null 2>&1 ; echo $$?),127)
13+
ifeq ($(shell uname),Darwin)
1214
git clone https://github.com/sstephenson/bats.git /tmp/bats
1315
cd /tmp/bats && sudo ./install.sh /usr/local
1416
rm -rf /tmp/bats
17+
else
18+
sudo add-apt-repository ppa:duggan/bats --yes
19+
sudo apt-get update -qq && sudo apt-get install -qq -y bats
20+
endif
21+
endif
1522

1623
ci-dependencies: shellcheck bats
1724

@@ -21,10 +28,14 @@ lint:
2128
# SC2068: Double quote array expansions, otherwise they're like $* and break on spaces. - https://github.com/koalaman/shellcheck/wiki/SC2068
2229
# SC2086: Double quote to prevent globbing and word splitting - https://github.com/koalaman/shellcheck/wiki/SC2086
2330
@echo linting...
24-
@$(QUIET) find . -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC2046,SC2068,SC2086
31+
@$(QUIET) find ./ -maxdepth 1 -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC2046,SC2068,SC2086
2532

2633
unit-tests:
2734
@echo running unit tests...
28-
@$(QUIET) bats tests/unit
35+
@$(QUIET) bats tests
36+
37+
setup:
38+
bash tests/setup.sh
39+
$(MAKE) ci-dependencies
2940

30-
test: ci-dependencies lint unit-tests
41+
test: setup lint unit-tests

tests/bin/docker

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
case "$1" in
3+
stop)
4+
echo "testid"
5+
;;
6+
start)
7+
echo "testid"
8+
;;
9+
kill)
10+
echo "testid"
11+
;;
12+
run)
13+
echo "testid"
14+
;;
15+
rm)
16+
echo "testid"
17+
;;
18+
ps)
19+
if [[ $@ = *"no-trunc"* ]]; then
20+
echo "1479bbd60ade8a92617d2aeb4935bd3ff3179bd0fd71c22c3102c421f4bc221f"
21+
exit 0
22+
else
23+
echo "CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES"
24+
echo "testid redis:3.0.3 \"/entrypoint.sh redi 5 minutes ago Up 5 minutes 6379/tcp dokku.redis.l"
25+
fi
26+
;;
27+
exec)
28+
echo "exec called with $@"
29+
;;
30+
inspect)
31+
if [[ $@ = *"IPAddress"* ]]; then
32+
echo "172.17.0.34"
33+
exit 0
34+
fi
35+
36+
# running
37+
echo "true"
38+
;;
39+
images)
40+
echo "REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE"
41+
echo "redis 3.0.3 9216d5a4eec8 13 days ago 109.3 MB"
42+
;;
43+
pull)
44+
exit 0
45+
;;
46+
*)
47+
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
48+
;;
49+
esac

tests/bin/id

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
echo "dokku"

tests/bin/redis-cli

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
exit 0

tests/service.bats

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bats
2+
load test_helper
3+
4+
@test "(service) dokku" {
5+
dokku $PLUGIN_COMMAND_PREFIX:create l
6+
assert_success
7+
8+
dokku $PLUGIN_COMMAND_PREFIX:info l
9+
assert_success
10+
11+
dokku $PLUGIN_COMMAND_PREFIX:stop l
12+
assert_success
13+
14+
dokku $PLUGIN_COMMAND_PREFIX:stop l
15+
assert_success
16+
17+
dokku $PLUGIN_COMMAND_PREFIX:expose l
18+
assert_success
19+
20+
dokku $PLUGIN_COMMAND_PREFIX:restart l
21+
assert_success
22+
23+
dokku $PLUGIN_COMMAND_PREFIX:info l
24+
assert_success
25+
26+
dokku --force $PLUGIN_COMMAND_PREFIX:destroy l
27+
assert_success
28+
}

tests/setup.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test_helper.bash"
3+
4+
if [[ ! -d $DOKKU_ROOT ]]; then
5+
git clone https://github.com/progrium/dokku.git $DOKKU_ROOT > /dev/null
6+
fi
7+
8+
cd $DOKKU_ROOT
9+
echo "Dokku version $DOKKU_VERSION"
10+
git checkout $DOKKU_VERSION > /dev/null
11+
cd -
12+
13+
rm -rf $DOKKU_ROOT/plugins/service
14+
mkdir -p $DOKKU_ROOT/plugins/service
15+
find ./ -maxdepth 1 -type f -exec cp '{}' $DOKKU_ROOT/plugins/service \;

tests/test_helper.bash

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
export DOKKU_QUIET_OUTPUT=1
3+
export DOKKU_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/dokku"
4+
export DOKKU_VERSION=${DOKKU_VERSION:-"master"}
5+
export PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/bin:$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/dokku:$PATH"
6+
export PLUGIN_COMMAND_PREFIX="mysql"
7+
export PLUGIN_PATH="$DOKKU_ROOT/plugins"
8+
export PLUGIN_DATA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/fixtures"
9+
10+
mkdir -p $PLUGIN_DATA_ROOT
11+
12+
flunk() {
13+
{ if [ "$#" -eq 0 ]; then cat -
14+
else echo "$*"
15+
fi
16+
}
17+
return 1
18+
}
19+
20+
assert_equal() {
21+
if [ "$1" != "$2" ]; then
22+
{ echo "expected: $1"
23+
echo "actual: $2"
24+
} | flunk
25+
fi
26+
}
27+
28+
assert_exit_status() {
29+
assert_equal "$status" "$1"
30+
}
31+
32+
assert_success() {
33+
if [ "$status" -ne 0 ]; then
34+
flunk "command failed with exit status $status"
35+
elif [ "$#" -gt 0 ]; then
36+
assert_output "$1"
37+
fi
38+
}
39+
40+
assert_exists() {
41+
if [ ! -f "$1" ]; then
42+
flunk "expected file to exist: $1"
43+
fi
44+
}
45+
46+
assert_contains() {
47+
if [[ "$1" != *"$2"* ]]; then
48+
flunk "expected $2 to be in: $1"
49+
fi
50+
}
51+
52+
assert_output() {
53+
local expected
54+
if [ $# -eq 0 ]; then expected="$(cat -)"
55+
else expected="$1"
56+
fi
57+
assert_equal "$expected" "$output"
58+
}

tests/unit/service.bats

-60
This file was deleted.

0 commit comments

Comments
 (0)