test with wercker
This commit is contained in:
26
tests/unit/apps.bats
Executable file
26
tests/unit/apps.bats
Executable 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
20
tests/unit/backup.bats
Normal 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
44
tests/unit/config.bats
Normal 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 ""
|
||||
}
|
||||
86
tests/unit/test_helper.bash
Normal file
86
tests/unit/test_helper.bash
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user