test with wercker

This commit is contained in:
Michael Hobbs
2014-12-13 18:56:31 -08:00
parent ab7c313411
commit 3706392e65
34 changed files with 380 additions and 63 deletions

View File

@@ -9,3 +9,6 @@ indent_size = 2
insert_final_newline = true
indent_style = tab
indent_size = 4
[*.mk]
indent_style = tab

View File

@@ -17,6 +17,8 @@ endif
.PHONY: all install copyfiles version plugins dependencies sshcommand pluginhook docker aufs stack count dokku-installer vagrant-acl-add vagrant-dokku
include tests.mk
all:
# Type "make install" to install.
@@ -27,10 +29,10 @@ copyfiles: addman
mkdir -p ${PLUGINS_PATH}
find ${PLUGINS_PATH} -mindepth 2 -maxdepth 2 -name '.core' -printf '%h\0' | xargs -0 rm -Rf
find plugins/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read plugin; do \
rm -Rf ${PLUGINS_PATH}/$$plugin && \
cp -R plugins/$$plugin ${PLUGINS_PATH} && \
touch ${PLUGINS_PATH}/$$plugin/.core; \
done
rm -Rf ${PLUGINS_PATH}/$$plugin && \
cp -R plugins/$$plugin ${PLUGINS_PATH} && \
touch ${PLUGINS_PATH}/$$plugin/.core; \
done
addman:
mkdir -p /usr/local/share/man/man1
@@ -72,7 +74,9 @@ endif
sleep 2 # give docker a moment i guess
aufs:
ifndef CI
lsmod | grep aufs || modprobe aufs || apt-get install -qq -y linux-image-extra-`uname -r` > /dev/null
endif
stack:
@echo "Start building buildstep"
@@ -106,3 +110,4 @@ vagrant-acl-add:
vagrant-dokku:
vagrant ssh -- "sudo -H -u root bash -c 'dokku $(RUN_ARGS)'"

View File

@@ -16,9 +16,10 @@ fi
apt-get update
apt-get install -qq -y git make curl software-properties-common man-db
[[ `lsb_release -sr` == "12.04" ]] && apt-get install -qq -y python-software-properties
[[ $(lsb_release -sr) == "12.04" ]] && apt-get install -qq -y python-software-properties
cd ~ && test -d dokku || git clone $DOKKU_REPO
cd ~
test -d dokku || git clone $DOKKU_REPO
cd dokku
git fetch origin

14
dokku
View File

@@ -44,13 +44,13 @@ case "$1" in
build)
APP="$2"; IMAGE="dokku/$APP"; CACHE_DIR="$DOKKU_ROOT/$APP/cache"
id=$(cat | docker run -i -a stdin $DOKKU_IMAGE /bin/bash -c "mkdir -p /app && tar -xC /app")
test $(docker wait $id) -eq 0
test "$(docker wait $id)" -eq 0
docker commit $id $IMAGE > /dev/null
[[ -d $CACHE_DIR ]] || mkdir $CACHE_DIR
pluginhook pre-build $APP
id=$(docker run -d -v $CACHE_DIR:/cache $IMAGE /build/builder)
docker attach $id
test $(docker wait $id) -eq 0
test "$(docker wait $id)" -eq 0
docker commit $id $IMAGE > /dev/null
pluginhook post-build $APP
;;
@@ -59,8 +59,8 @@ case "$1" in
APP="$2"; IMAGE="dokku/$APP"
pluginhook pre-release $APP
if [[ -f "$DOKKU_ROOT/$APP/ENV" ]]; then
id=$(cat "$DOKKU_ROOT/$APP/ENV" | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/app-env.sh")
test $(docker wait $id) -eq 0
id=$(docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/app-env.sh" < "$DOKKU_ROOT/$APP/ENV")
test "$(docker wait $id)" -eq 0
docker commit $id $IMAGE > /dev/null
fi
pluginhook post-release $APP
@@ -143,8 +143,8 @@ case "$1" in
# temporary hack for https://github.com/progrium/dokku/issues/82
deploy:all)
for app in $(ls -d $DOKKU_ROOT/*/CONTAINER); do
APP=$(basename $(dirname $app));
for app in $DOKKU_ROOT/*/CONTAINER; do
APP=$(basename "$(dirname $app)");
dokku deploy $APP
done
;;
@@ -163,7 +163,7 @@ EOF
*)
implemented=0
for script in $(ls -d $PLUGIN_PATH/*/commands); do
for script in $PLUGIN_PATH/*/commands; do
set +e; $script "$@" ; exit_code=$? ; set -e
if [ "$exit_code" -eq "$DOKKU_NOT_IMPLEMENTED_EXIT" ]; then
continue

View File

@@ -8,7 +8,7 @@ TARGET_DIR="$3"
[[ -f $IMPORT_DIR/.sshcommand ]] && mv $IMPORT_DIR/.sshcommand $TARGET_DIR/.sshcommand
if [[ -f $IMPORT_DIR/.ssh/authorized_keys ]]; then
mkdir -p $TARGET_DIR/.ssh
cat $IMPORT_DIR/.ssh/authorized_keys $TARGET_DIR/.ssh/authorized_keys | uniq > $TARGET_DIR/.ssh/authorized_keys
cat $IMPORT_DIR/.ssh/authorized_keys $TARGET_DIR/.ssh/authorized_keys | uniq > tmpfile && mv tmpfile $TARGET_DIR/.ssh/authorized_keys
chmod 0700 $TARGET_DIR/.ssh
chmod 0600 $TARGET_DIR/.ssh/*
fi

View File

@@ -2,7 +2,7 @@
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
if [[ ! -f "$DOKKU_ROOT/HOSTNAME" ]]; then
echo $(hostname -f) > $DOKKU_ROOT/HOSTNAME
hostname -f > $DOKKU_ROOT/HOSTNAME
fi
if [[ ! -f "$DOKKU_ROOT/VHOST" ]]; then

View File

@@ -14,7 +14,7 @@ case "$1" in
: | pluginhook backup-export 1 $BACKUP_DIR | tar -cf $BACKUP_TMP_FILE --files-from -
pushd $BACKUP_DIR > /dev/null
ls -d */ | grep -oE '[^/]+' > "$BACKUP_TMP_DIR/.dokku_backup_apps"
find . -maxdepth 1 -type d -not -name . | sed 's:./::g' > "$BACKUP_TMP_DIR/.dokku_backup_apps"
popd > /dev/null
# we want to insert the files in the root of the tar

View File

@@ -56,15 +56,15 @@ sleep $WAIT
# --location Follow redirects
CURL_OPTIONS="-q --compressed --fail --location --max-time 30"
cat "$FILENAME" | while read PATHNAME EXPECTED ; do
while read PATHNAME EXPECTED < "$FILENAME"; do
# Ignore empty lines and lines starting with #
[[ -z "$PATHNAME" || "$PATHNAME" =~ ^\# ]] && continue
[[ -z "$PATHNAME" || "$PATHNAME" =~ ^# ]] && continue
URL="http://$HOSTNAME:$PORT$PATHNAME"
echo "checking with: curl $CURL_OPTIONS $URL"
HTML=$(curl $CURL_OPTIONS $URL)
if [[ -n "$EXPECTED" && ! "$HTML" =~ "$EXPECTED" ]] ; then
if [[ -n "$EXPECTED" && ! "$HTML" =~ $EXPECTED ]] ; then
echo -e "\033[31m\033[1m$URL: expected to but did not find: \"$EXPECTED\"\033[0m"
exit 1
else

View File

@@ -15,21 +15,21 @@ config_styled_hash () {
longest=""
while read -r word; do
KEY=`echo $word | cut -d"=" -f1`
KEY=$(echo $word | cut -d"=" -f1)
if [ ${#KEY} -gt ${#longest} ]; then
longest=$KEY
fi
done <<< "$vars"
while read -r word; do
KEY=`echo $word | cut -d"=" -f1`
VALUE=`echo $word | cut -d"=" -f2- | sed -e "s/^'//" -e "s/'$//"`
KEY=$(echo $word | cut -d"=" -f1)
VALUE=$(echo $word | cut -d"=" -f2- | sed -e "s/^'//" -e "s/'$//")
num_zeros=$((${#longest} - ${#KEY}))
zeros=" "
while [ $num_zeros -gt 0 ]; do
zeros="$zeros "
num_zeros=$(($num_zeros - 1))
num_zeros=$((num_zeros - 1))
done
echo "$prefix$KEY:$zeros$VALUE"
done <<< "$vars"
@@ -68,7 +68,7 @@ case "$1" in
config_create
[[ ! -s $ENV_FILE ]] && echo "$APP has no config vars" && exit 1
VARS=`cat $ENV_FILE | grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" | cut -d" " -f2-`
VARS=$(grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" $ENV_FILE | cut -d" " -f2-)
for var in "$@"; do
if [[ "$var" == "--shell" ]]; then
@@ -99,7 +99,7 @@ case "$1" in
KEY="$3"
cat $ENV_FILE | grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" | grep "^export $KEY=" | cut -d"=" -f2- | sed -e "s/^'//" -e "s/'$//"
grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" $ENV_FILE | grep "^export $KEY=" | cut -d"=" -f2- | sed -e "s/^'//" -e "s/'$//"
;;
config:set)
@@ -115,7 +115,7 @@ case "$1" in
config_create
ENV_ADD=""
ENV_TEMP=`cat "${ENV_FILE}"`
ENV_TEMP=$(cat "${ENV_FILE}")
RESTART_APP=false
shift 2
@@ -128,8 +128,8 @@ case "$1" in
done
for var; do
KEY=`echo ${var} | cut -d"=" -f1`
VALUE=`echo ${var} | cut -d"=" -f2-`
KEY=$(echo ${var} | cut -d"=" -f1)
VALUE=$(echo ${var} | cut -d"=" -f2-)
if [[ $KEY =~ [a-zA-Z_][a-zA-Z0-9_]* ]]; then
RESTART_APP=true
@@ -162,7 +162,7 @@ ${var}"
fi
config_create
ENV_TEMP=`cat "${ENV_FILE}"`
ENV_TEMP=$(cat "${ENV_FILE}")
VARS="${*:3}"
for var in $VARS; do

View File

@@ -57,7 +57,7 @@ EOF
chmod +x $PRERECEIVE_HOOK
fi
args=$@
args=$*
git-shell -c "$args"
;;

View File

@@ -9,6 +9,6 @@ TARGET_DIR="$3"
cd $IMPORT_DIR
for file in */tls/server.*; do
mkdir -p $(dirname $TARGET_DIR$file)
mkdir -p "$(dirname $TARGET_DIR$file)"
cp $file $TARGET_DIR$file
done

View File

@@ -95,7 +95,7 @@ EOF
[[ -t 0 ]] && echo "Tar archive containing server.crt and server.key expected on stdin" && exit 1
APP="$2"
TEMP_DIR=`mktemp -d`
TEMP_DIR=$(mktemp -d)
cd $TEMP_DIR
tar xvf - <&0
[[ ! -f "$TEMP_DIR/server.crt" ]] && echo "Tar archive missing server.crt" && exit 1

63
tests.mk Normal file
View File

@@ -0,0 +1,63 @@
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
ci-dependencies: shellcheck bats
setup-deploy-tests:
# echo "-----> Enabling tracing"
# mkdir -p /home/dokku
# echo "export DOKKU_TRACE=1" >> /home/dokku/dokkurc
@echo "Setting dokku.me in /etc/hosts"
sudo /bin/bash -c "[[ `ping -c1 dokku.me > /dev/null 2>&1; echo $$?` -eq 0 ]] || echo \"127.0.0.1 dokku.me *.dokku.me\" >> /etc/hosts"
@echo "-----> Generating keypair..."
mkdir -p /root/.ssh
rm -f /root/.ssh/dokku_test_rsa*
echo -e "y\n" | ssh-keygen -f /root/.ssh/dokku_test_rsa -t rsa -N ''
chmod 600 /root/.ssh/dokku_test_rsa*
@echo "-----> Setting up ssh config..."
ifeq ($(shell ls /root/.ssh/config > /dev/null 2>&1 ; echo $$?),0)
ifeq ($(shell grep dokku.me /root/.ssh/config),)
echo "Host dokku.me \\r\\n RequestTTY yes \\r\\n IdentityFile /root/.ssh/dokku_test_rsa" >> /root/.ssh/config
endif
else
echo "Host dokku.me \\r\\n RequestTTY yes \\r\\n IdentityFile /root/.ssh/dokku_test_rsa" >> /root/.ssh/config
endif
@echo "-----> Installing SSH public key..."
sudo sshcommand acl-remove dokku test
cat /root/.ssh/dokku_test_rsa.pub | sudo sshcommand acl-add dokku test
@echo "-----> Intitial SSH connection to populate known_hosts..."
ssh -o StrictHostKeyChecking=no dokku@dokku.me help > /dev/null
bats:
git clone https://github.com/sstephenson/bats.git /tmp/bats
cd /tmp/bats && sudo ./install.sh /usr/local
rm -rf /tmp/bats
lint:
# these are disabled due to their expansive existence in the codebase. we should clean it up though
# SC2034: VAR appears unused - https://github.com/koalaman/shellcheck/wiki/SC2034
# 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 SC2034,SC2086
unit-tests:
@echo running unit tests...
@$(QUIET) bats tests/unit
deploy-tests:
@echo running deploy tests...
# @$(QUIET) bats tests/deploy
cd tests && ./test_deploy ./apps/go dokku.me
test: lint setup-deploy-tests unit-tests deploy-tests

View File

@@ -9,7 +9,7 @@ test_url () {
path="$1"
expected_output="$2"
url="$base_url$path"
output="$(curl -s $url)"
echo $output
output="$(curl -s "$url")"
echo "$output"
test "$output" == "$expected_output"
}
}

View File

@@ -4,5 +4,5 @@ set -ex;
REMOTE=$1
REPO=$2
ssh $REMOTE config:set $REPO CONFTEST=config-test HELLO=\"Hello world\"
ssh "$REMOTE" config:set "$REPO" CONFTEST=config-test HELLO=\"Hello world\"

View File

@@ -1 +1 @@
web: node node-js-sample/web.js
web: node node-js-sample/index.js

View File

@@ -1,2 +1,5 @@
#!/bin/bash
set -e; output="$(curl -s $1)"; echo $output; test "$output" == "Hello World!"
set -ex
echo "curl -s $1"
curl -s -S $1
output="$(curl -s $1)"; echo $output; test "$output" == "Hello World!"

View File

@@ -1,2 +1,2 @@
#!/bin/bash
set -e; test "$(curl -s $1)" == "go"
set -e; test "$(curl -s "$1")" == "go"

View File

@@ -1,2 +1,2 @@
#!/bin/bash
set -e; curl -s $1 | grep -q "Heroku Multi Buildpack on Dokku"
set -e; curl -s "$1" | grep -q "Heroku Multi Buildpack on Dokku"

View File

@@ -1,2 +1,2 @@
#!/bin/bash
set -e; output="$(curl -s $1)"; echo $output; test "$output" == "nodejs/express"
set -e; output="$(curl -s "$1")"; echo "$output"; test "$output" == "nodejs/express"

View File

@@ -1,2 +1,2 @@
#!/bin/bash
set -e; output="$(curl -s $1)"; echo $output; test "$output" == "<html><h3>php</h3></html>"
set -e; output="$(curl -s "$1")"; echo "$output"; test "$output" == "<html><h3>php</h3></html>"

View File

@@ -1,2 +1,2 @@
#!/bin/bash
set -e; output="$(curl -s $1)"; echo $output; test "$output" == "python/flask"
set -e; output="$(curl -s "$1")"; echo "$output"; test "$output" == "python/flask"

View File

@@ -1,2 +1,2 @@
#!/bin/bash
set -e; output="$(curl -s $1)"; echo $output; test "$output" == "<html><h3>Static Page</h3></html>"
set -e; output="$(curl -s "$1")"; echo "$output"; test "$output" == "<html><h3>Static Page</h3></html>"

View File

@@ -22,7 +22,8 @@ if [[ $2 == *dokku* ]]; then
echo "-----> Generating keypair..."
echo -e "y\n" | ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''
echo "-----> Installing SSH public key..."
cat /root/.ssh/id_rsa.pub | sudo sshcommand acl-add dokku test
PUBLIC_KEY=$(< /root/.ssh/id_rsa.pub)
echo $PUBLIC_KEY | sudo sshcommand acl-add dokku test
echo "-----> Intitial SSH connection to populate known_hosts..."
ssh -o StrictHostKeyChecking=no dokku@dokku.me help > /dev/null
echo "-----> Running tests"

11
tests/deploy/config.bats Normal file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bats
load ../unit/test_helper
@test "deploy config app" {
skip "ssh is doing something odd with quoting... ref: #820"
run bash -c "cd tests && ./test_deploy ./apps/config dokku.me"
echo "output: "$output
echo "status: "$status
assert_success
}

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bats
load ../unit/test_helper
@test "deploy gitsubmodules app" {
run bash -c "cd tests && ./test_deploy ./apps/gitsubmodules dokku.me"
echo "output: "$output
echo "status: "$status
assert_success
}

View File

@@ -4,7 +4,7 @@ KEYNAME="$1"
indent() { sed "s/^/ /"; }
echo "-----> Booting EC2 instance..."
start=$(ec2-run-instances -k $1 ami-f3d1bb9a 2>&1 )
if [[ $? > 0 ]]; then
if [[ $? -gt 0 ]]; then
echo "$start" | indent
exit 3
fi
@@ -34,9 +34,10 @@ while [[ ! $(echo | nc $PUBLIC_IP 22) ]]; do
done
set -e
echo "-----> Connecting and running bootstrap script..."
cat ../bootstrap.sh | ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "HOSTNAME=$PUBLIC_IP sudo bash" 2>&1 | indent
ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "HOSTNAME=\$PUBLIC_IP sudo bash" < ../bootstrap.sh 2>&1 | indent
echo "-----> Installing SSH public keys..."
cat ~/.ssh/id_rsa.pub | ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "sudo sshcommand acl-add dokku test" > /dev/null
PUBLIC_KEY=$(< ~/.ssh/id_rsa.pub)
echo $PUBLIC_KEY | ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "sudo sshcommand acl-add dokku test" > /dev/null
for app_path in apps/*; do
app=$(basename $app_path)
echo "-----> Running test deploy of $app..."

View File

@@ -1,23 +1,26 @@
#!/usr/bin/env bash
set -eo pipefail
SELF=`which $0`
SELF=$(which $0)
VAGRANT_SSH_PORT=${VAGRANT_SSH_PORT:-"2222"}
PUBLIC_KEY=${PUBLIC_KEY:-"$HOME/.ssh/id_rsa.pub"}
FORWARDED_PORT=${FORWARDED_PORT:-":8080"}
indent() { sed "s/^/ /"; }
if [[ ! $(cat ~/.ssh/config 2>/dev/null | grep dokku.me) ]]; then
if ! grep dokku.me ~/.ssh/config 2>/dev/null; then
echo "-----> Configuring SSH to use $VAGRANT_SSH_PORT for dokku.me..."
touch ~/.ssh/config
echo "Host dokku.me" >> ~/.ssh/config
echo " Port $VAGRANT_SSH_PORT" >> ~/.ssh/config
echo " RequestTTY yes" >> ~/.ssh/config
{
echo "Host dokku.me"
echo " Port $VAGRANT_SSH_PORT"
echo " RequestTTY yes"
} >> ~/.ssh/config
fi
echo "-----> Ensuring Vagrant is running..."
pushd $PWD > /dev/null
cd "$(dirname $SELF)/.." && vagrant up | indent
cd "$(dirname $SELF)"
popd > /dev/null
echo "-----> Installing SSH public keys..."
cat $PUBLIC_KEY | ssh -o "StrictHostKeyChecking=no" -i ~/.vagrant.d/insecure_private_key vagrant@dokku.me "sudo sshcommand acl-add dokku test"
ssh -o "StrictHostKeyChecking=no" -i ~/.vagrant.d/insecure_private_key vagrant@dokku.me "sudo sshcommand acl-add dokku test" < $PUBLIC_KEY
for app_path in apps/*; do
app=$(basename $app_path)

View File

@@ -1,12 +1,22 @@
#!/usr/bin/env bash
set -exo pipefail
SELF=`which $0`; APP="$1"; TARGET="$2"; FORWARDED_PORT="$3"
SELF=$(which $0); APP="$1"; TARGET="$2"; FORWARDED_PORT="$3"
REMOTE="dokku@$TARGET"
REPO="test-$(basename $APP)-$RANDOM"
destroy_app(){
echo $REPO | ssh $REMOTE apps:destroy $REPO
}
failed(){
echo "************ $1 failed ************"
# destroy_app
exit 1
}
TMP=$(mktemp -d -t "$TARGET.XXXXX")
trap "rm -rf $TMP" EXIT
rmdir $TMP && cp -r $(dirname $SELF)/$APP $TMP
rmdir $TMP && cp -r "$(dirname "$SELF")"/$APP $TMP
cd $TMP
git init
git config user.email "robot@example.com"
@@ -19,13 +29,21 @@ git add .
[[ -x pre-commit ]] && ./pre-commit $REMOTE $REPO
git commit -m 'initial commit'
git push target master
[[ -x post-deploy ]] && ./post-deploy $REMOTE $REPO
if [[ -x post-deploy ]]; then
./post-deploy $REMOTE $REPO || failed post-deploy
fi
URL=$(ssh $REMOTE url $REPO)$FORWARDED_PORT
sleep 2
./check_deploy $URL && echo "-----> Deploy success!" || {
if (./check_deploy $URL); then
echo "-----> Deploy success!"
else
sleep 4
./check_deploy $URL && echo "-----> Deploy success!"
}
if (./check_deploy $URL); then
echo "-----> Deploy success!"
else
failed check-deploy
fi
fi
ssh $REMOTE delete $REPO
destroy_app

26
tests/unit/apps.bats Executable file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bats
load test_helper
APP=lifecycle-app
@test "apps:create" {
run dokku apps:create $APP
echo "output: "$output
echo "status: "$status
assert_success
}
@test "apps" {
run bash -c "dokku apps | grep $APP"
echo "output: "$output
echo "status: "$status
assert_output $APP
}
@test "apps:destroy" {
run bash -c "echo $APP | dokku apps:destroy $APP"
echo "output: "$output
echo "status: "$status
assert_success
}

20
tests/unit/backup.bats Normal file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bats
# load test_helper
# setup() {
# create_app
# backup_file=$(mktemp /tmp/backup.XXXXXX)
# rm $backup_file
# }
# teardown() {
# destroy_app
# }
# @test "backup:export" {
# run dokku backup:export $backup_file
# echo "output: "$output
# echo "status: "$status
# assert_success
# }

44
tests/unit/config.bats Normal file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bats
load test_helper
setup() {
create_app
}
teardown() {
destroy_app
}
@test "config:set" {
run dokku config:set $TEST_APP test_var=true test_var2='hello world'
echo "output: "$output
echo "status: "$status
assert_success
}
@test "config:get" {
run dokku config:set $TEST_APP test_var=true test_var2='hello world'
echo "output: "$output
echo "status: "$status
run dokku config:get $TEST_APP test_var2
echo "output: "$output
echo "status: "$status
assert_output 'hello world'
}
@test "config:unset" {
run dokku config:set $TEST_APP test_var=true test_var2='hello world'
echo "output: "$output
echo "status: "$status
run dokku config:get $TEST_APP test_var
echo "output: "$output
echo "status: "$status
run dokku config:unset $TEST_APP test_var
echo "output: "$output
echo "status: "$status
run dokku config:get $TEST_APP test_var
echo "output: "$output
echo "status: "$status
assert_output ""
}

View File

@@ -0,0 +1,86 @@
# constants
TEST_APP=my-cool-guy-test-app
# test functions
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_failure() {
if [ "$status" -eq 0 ]; then
flunk "expected failed exit 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"
}
assert_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
assert_equal "$2" "${lines[$1]}"
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then return 0; fi
done
flunk "expected line \`$1'"
fi
}
refute_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
local num_lines="${#lines[@]}"
if [ "$1" -lt "$num_lines" ]; then
flunk "output has $num_lines lines"
fi
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then
flunk "expected to not find line \`$line'"
fi
done
fi
}
assert() {
if ! "$@"; then
flunk "failed: $@"
fi
}
# dokku functions
create_app() {
dokku apps:create $TEST_APP
}
destroy_app() {
echo $TEST_APP | dokku apps:destroy $TEST_APP
}

22
wercker.yml Normal file
View File

@@ -0,0 +1,22 @@
# box: ruudk/ubuntu14.04@1.0.0
# box: jparyani/docker@1.0.1
box: wercker-labs/docker
build:
steps:
- script:
name: install os requirements
code: |-
sudo apt-get update
sudo apt-get install -y make software-properties-common git wget man-db
docker version
- script:
name: ci dependencies
code: make -e ci-dependencies
- script:
name: install dokku
code: sudo -E CI=true DOCKER_VERSION=1.4.0 make -e install
- script:
name: test dokku
code: |-
docker version
sudo -E make -e test