Adding a Makefile and basic tests.

This approach uses bats to create a generic docker-compose test. It
checks that images are pullable, projects are buildable, up works, and
if ports are exposed that something is listening.

The tests can be tailored for each example. As long as they are the same
though, you can edit lib/test.bats.example and then `make update-tests`
and all the tests will be synced.

Signed-off-by: Chad Metcalf <chad@docker.com>
This commit is contained in:
Chad Metcalf 2020-08-07 11:57:15 -07:00 committed by Chad Metcalf
parent c47ca78721
commit 702ec96821
No known key found for this signature in database
GPG Key ID: BCA7CAE891B2C9B5
28 changed files with 1595 additions and 0 deletions

7
Makefile Normal file
View File

@ -0,0 +1,7 @@
.phony: test
test:
@bats -T -r .
update-tests:
@find . -maxdepth 1 -type d -not -path '*/\.*' -not -path '.' -not -path './lib' -exec cp ./lib/test.bats.example {}/test.bats \;

60
angular/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
apache-php/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
aspnet-mssql/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
django/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
flask/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
gitea-postgres/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
lib/test.bats.example Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

28
lib/test_helper.bash Normal file
View File

@ -0,0 +1,28 @@
function docker_compose_project_name() {
echo "$(basename ${BATS_TEST_DIRNAME})"
}
# Runs docker ps -a filtered by the current project name
function docker_ps_by_project() {
docker ps -a \
--filter "label=com.docker.compose.project=$(docker_compose_project_name)" \
"${@}"
}
function check_deps() {
# external commands we depend on for testing
local dependancies=(nc)
for i in ${dependancies[@]}; do
if [ ! command -v ${i} &> /dev/null ]; then
echo "${i} could not be found"
exit
fi
done
}
function compose_cleanup() {
docker-compose kill || true
docker-compose rm --force -v || true
docker-compose down --volumes || true
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
nginx-golang/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
sparkjava-mysql/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
sparkjava/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
spring-postgres/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
traefik-golang/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
vuejs/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}

60
wordpress-mysql/test.bats Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bats
load '../lib/test_helper.bash'
cd ${BATS_TEST_DIRNAME}
function setup_file() {
check_deps
compose_cleanup
}
function teardown_file() {
compose_cleanup
}
@test "$(basename ${BATS_TEST_DIRNAME}): pull check" {
run docker-compose pull
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): build check" {
run docker-compose build
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): up check" {
run docker-compose up -d
[ "${status}" -eq 0 ]
}
@test "$(basename ${BATS_TEST_DIRNAME}): ports check" {
for service in $(docker-compose ps -q); do
# simple test to check that any exposed port has something actually listening
# assumes format 22/tcp, 0.0.0.0:3000->3000/tcp
ports_string=$(docker ps --filter="ID=${service}" --format "{{.Ports}}")
OIFS=${IFS}; IFS=','; service_port=($ports_string); IFS=${OIFS}; unset OIFS;
for i in ${service_port[@]}; do
protocol=$(expr match ${i} '.*\(tcp\|udp\)')
# the || true here just makes sure bats doesn't fail the test because a
# port wasn't matched. We will check for empty ports later
port=$(expr match ${i} '.*:\([0-9]*\)->' || true)
if [[ ${protocol} == "tcp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v localhost ${port}
[ "${status}" -eq 0 ]
elif [[ "${protocol}" = "udp" ]] && [[ ! -z ${port} ]]; then
run nc -z -v -u localhost ${port}
[ "${status}" -eq 0 ]
fi
done
done
}