self-contained "testing" infrastructure
This commit is contained in:
20
Makefile
20
Makefile
@@ -1,17 +1,24 @@
|
|||||||
shellcheck:
|
shellcheck:
|
||||||
ifeq ($(shell shellcheck > /dev/null 2>&1 ; echo $$?),127)
|
ifeq ($(shell shellcheck > /dev/null 2>&1 ; echo $$?),127)
|
||||||
ifeq ($(shell uname),Darwin)
|
ifeq ($(shell uname),Darwin)
|
||||||
brew install shellcheck
|
brew install shellcheck
|
||||||
else
|
else
|
||||||
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse'
|
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
|
||||||
endif
|
endif
|
||||||
|
|
||||||
bats:
|
bats:
|
||||||
|
ifeq ($(shell bats > /dev/null 2>&1 ; echo $$?),127)
|
||||||
|
ifeq ($(shell uname),Darwin)
|
||||||
git clone https://github.com/sstephenson/bats.git /tmp/bats
|
git clone https://github.com/sstephenson/bats.git /tmp/bats
|
||||||
cd /tmp/bats && sudo ./install.sh /usr/local
|
cd /tmp/bats && sudo ./install.sh /usr/local
|
||||||
rm -rf /tmp/bats
|
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
|
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
|
# 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
|
# SC2086: Double quote to prevent globbing and word splitting - https://github.com/koalaman/shellcheck/wiki/SC2086
|
||||||
@echo linting...
|
@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:
|
unit-tests:
|
||||||
@echo running unit tests...
|
@echo running unit tests...
|
||||||
@$(QUIET) bats tests/unit
|
@$(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
16
tests/setup.sh
Normal 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 \;
|
||||||
@@ -1,37 +1,6 @@
|
|||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
export SERVICE=redis
|
|
||||||
|
|
||||||
flunk() {
|
load test_helper
|
||||||
{ 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" {
|
@test "(service) dokku" {
|
||||||
dokku $SERVICE:create l
|
dokku $SERVICE:create l
|
||||||
|
|||||||
56
tests/unit/test_helper.bash
Normal file
56
tests/unit/test_helper.bash
Normal 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"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user