self-contained "testing" infrastructure

This commit is contained in:
Jose Diaz-Gonzalez
2015-09-06 23:25:07 -04:00
parent 7f8b77d4df
commit 72222dddf9
4 changed files with 88 additions and 37 deletions

View File

@@ -4,14 +4,21 @@ 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
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,13 @@ 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
test: ci-dependencies lint unit-tests
setup:
bash tests/setup.sh
test: setup ci-dependencies lint unit-tests

16
tests/setup.sh Normal file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
source "$(dirname $0)/unit/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 \;

View File

@@ -1,37 +1,6 @@
#!/usr/bin/env bats
export SERVICE=redis
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"
}
load test_helper
@test "(service) dokku" {
dokku $SERVICE:create l

View File

@@ -0,0 +1,56 @@
#!/usr/bin/env bash
export DOKKU_QUIET_OUTPUT=1
export DOKKU_ROOT="tests/dokku"
export DOKKU_VERSION=${DOKKU_VERSION:-"master"}
export PATH="$(dirname $0)/../dokku:$PATH"
export PLUGIN_PATH="$DOKKU_ROOT/plugins"
export SERVICE=redis
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"
}