diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f9b50a2 --- /dev/null +++ b/Makefile @@ -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 \; diff --git a/angular/test.bats b/angular/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/angular/test.bats @@ -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 +} diff --git a/apache-php/test.bats b/apache-php/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/apache-php/test.bats @@ -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 +} diff --git a/aspnet-mssql/test.bats b/aspnet-mssql/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/aspnet-mssql/test.bats @@ -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 +} diff --git a/django/test.bats b/django/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/django/test.bats @@ -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 +} diff --git a/elasticsearch-logstash-kibana/test.bats b/elasticsearch-logstash-kibana/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/elasticsearch-logstash-kibana/test.bats @@ -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 +} diff --git a/flask/test.bats b/flask/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/flask/test.bats @@ -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 +} diff --git a/gitea-postgres/test.bats b/gitea-postgres/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/gitea-postgres/test.bats @@ -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 +} diff --git a/lib/test.bats.example b/lib/test.bats.example new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/lib/test.bats.example @@ -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 +} diff --git a/lib/test_helper.bash b/lib/test_helper.bash new file mode 100644 index 0000000..2bf0315 --- /dev/null +++ b/lib/test_helper.bash @@ -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 +} diff --git a/nextcloud-postgres/test.bats b/nextcloud-postgres/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/nextcloud-postgres/test.bats @@ -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 +} diff --git a/nextcloud-redis-mariadb/test.bats b/nextcloud-redis-mariadb/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/nextcloud-redis-mariadb/test.bats @@ -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 +} diff --git a/nginx-flask-mongo/test.bats b/nginx-flask-mongo/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/nginx-flask-mongo/test.bats @@ -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 +} diff --git a/nginx-flask-mysql/test.bats b/nginx-flask-mysql/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/nginx-flask-mysql/test.bats @@ -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 +} diff --git a/nginx-golang-mysql/test.bats b/nginx-golang-mysql/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/nginx-golang-mysql/test.bats @@ -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 +} diff --git a/nginx-golang-postgres/test.bats b/nginx-golang-postgres/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/nginx-golang-postgres/test.bats @@ -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 +} diff --git a/nginx-golang/test.bats b/nginx-golang/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/nginx-golang/test.bats @@ -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 +} diff --git a/prometheus-grafana/test.bats b/prometheus-grafana/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/prometheus-grafana/test.bats @@ -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 +} diff --git a/react-express-mongodb/test.bats b/react-express-mongodb/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/react-express-mongodb/test.bats @@ -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 +} diff --git a/react-express-mysql/test.bats b/react-express-mysql/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/react-express-mysql/test.bats @@ -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 +} diff --git a/react-java-mysql/test.bats b/react-java-mysql/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/react-java-mysql/test.bats @@ -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 +} diff --git a/react-rust-postgres/test.bats b/react-rust-postgres/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/react-rust-postgres/test.bats @@ -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 +} diff --git a/sparkjava-mysql/test.bats b/sparkjava-mysql/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/sparkjava-mysql/test.bats @@ -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 +} diff --git a/sparkjava/test.bats b/sparkjava/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/sparkjava/test.bats @@ -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 +} diff --git a/spring-postgres/test.bats b/spring-postgres/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/spring-postgres/test.bats @@ -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 +} diff --git a/traefik-golang/test.bats b/traefik-golang/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/traefik-golang/test.bats @@ -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 +} diff --git a/vuejs/test.bats b/vuejs/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/vuejs/test.bats @@ -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 +} diff --git a/wordpress-mysql/test.bats b/wordpress-mysql/test.bats new file mode 100644 index 0000000..b58d685 --- /dev/null +++ b/wordpress-mysql/test.bats @@ -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 +}