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,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
}