From 702ec96821a889b6bb15815b9c8209a1f433411b Mon Sep 17 00:00:00 2001 From: Chad Metcalf Date: Fri, 7 Aug 2020 11:57:15 -0700 Subject: [PATCH] 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 --- Makefile | 7 +++ angular/test.bats | 60 +++++++++++++++++++++++++ apache-php/test.bats | 60 +++++++++++++++++++++++++ aspnet-mssql/test.bats | 60 +++++++++++++++++++++++++ django/test.bats | 60 +++++++++++++++++++++++++ elasticsearch-logstash-kibana/test.bats | 60 +++++++++++++++++++++++++ flask/test.bats | 60 +++++++++++++++++++++++++ gitea-postgres/test.bats | 60 +++++++++++++++++++++++++ lib/test.bats.example | 60 +++++++++++++++++++++++++ lib/test_helper.bash | 28 ++++++++++++ nextcloud-postgres/test.bats | 60 +++++++++++++++++++++++++ nextcloud-redis-mariadb/test.bats | 60 +++++++++++++++++++++++++ nginx-flask-mongo/test.bats | 60 +++++++++++++++++++++++++ nginx-flask-mysql/test.bats | 60 +++++++++++++++++++++++++ nginx-golang-mysql/test.bats | 60 +++++++++++++++++++++++++ nginx-golang-postgres/test.bats | 60 +++++++++++++++++++++++++ nginx-golang/test.bats | 60 +++++++++++++++++++++++++ prometheus-grafana/test.bats | 60 +++++++++++++++++++++++++ react-express-mongodb/test.bats | 60 +++++++++++++++++++++++++ react-express-mysql/test.bats | 60 +++++++++++++++++++++++++ react-java-mysql/test.bats | 60 +++++++++++++++++++++++++ react-rust-postgres/test.bats | 60 +++++++++++++++++++++++++ sparkjava-mysql/test.bats | 60 +++++++++++++++++++++++++ sparkjava/test.bats | 60 +++++++++++++++++++++++++ spring-postgres/test.bats | 60 +++++++++++++++++++++++++ traefik-golang/test.bats | 60 +++++++++++++++++++++++++ vuejs/test.bats | 60 +++++++++++++++++++++++++ wordpress-mysql/test.bats | 60 +++++++++++++++++++++++++ 28 files changed, 1595 insertions(+) create mode 100644 Makefile create mode 100644 angular/test.bats create mode 100644 apache-php/test.bats create mode 100644 aspnet-mssql/test.bats create mode 100644 django/test.bats create mode 100644 elasticsearch-logstash-kibana/test.bats create mode 100644 flask/test.bats create mode 100644 gitea-postgres/test.bats create mode 100644 lib/test.bats.example create mode 100644 lib/test_helper.bash create mode 100644 nextcloud-postgres/test.bats create mode 100644 nextcloud-redis-mariadb/test.bats create mode 100644 nginx-flask-mongo/test.bats create mode 100644 nginx-flask-mysql/test.bats create mode 100644 nginx-golang-mysql/test.bats create mode 100644 nginx-golang-postgres/test.bats create mode 100644 nginx-golang/test.bats create mode 100644 prometheus-grafana/test.bats create mode 100644 react-express-mongodb/test.bats create mode 100644 react-express-mysql/test.bats create mode 100644 react-java-mysql/test.bats create mode 100644 react-rust-postgres/test.bats create mode 100644 sparkjava-mysql/test.bats create mode 100644 sparkjava/test.bats create mode 100644 spring-postgres/test.bats create mode 100644 traefik-golang/test.bats create mode 100644 vuejs/test.bats create mode 100644 wordpress-mysql/test.bats 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 +}