From 654b6ef987b9d51904d6009155f9c935fc919f48 Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Thu, 9 Nov 2023 23:29:13 +0000 Subject: [PATCH] Change to ./test/test.sh --- .github/workflows/ci-master-pr.yml | 20 +- .vscode/tasks.json | 6 +- README.md | 14 +- docker-compose.test.yml | 261 ------------------ .../docker-compose.build.yml | 5 + test/.env | 1 + test/docker-compose.yml | 35 +++ test/test-endpoints.sh | 47 ++++ test/test-external-dns.sh | 26 ++ test/test-internal-dns.sh | 24 ++ test/test-ready.sh | 18 ++ test/test-routes.sh | 47 ++++ test/test-snapshots.sh | 19 ++ test/test.sh | 92 ++++++ 14 files changed, 333 insertions(+), 282 deletions(-) delete mode 100644 docker-compose.test.yml create mode 100644 test/.env create mode 100644 test/docker-compose.yml create mode 100755 test/test-endpoints.sh create mode 100755 test/test-external-dns.sh create mode 100755 test/test-internal-dns.sh create mode 100755 test/test-ready.sh create mode 100755 test/test-routes.sh create mode 100755 test/test-snapshots.sh create mode 100755 test/test.sh diff --git a/.github/workflows/ci-master-pr.yml b/.github/workflows/ci-master-pr.yml index 0ce6e266..c78b8c1b 100644 --- a/.github/workflows/ci-master-pr.yml +++ b/.github/workflows/ci-master-pr.yml @@ -45,20 +45,20 @@ jobs: if: matrix.testenv == 'dev' run: | set -eux - docker compose -f docker-compose.yml -f docker-compose.build.yml up --build -d - docker compose -f docker-compose.test.yml --profile dev up + ./test/test.sh dev 1 1 - - name: Integration test 1 (prod) + - name: Integration test (prod) if: matrix.testenv == 'prod' run: | set -eux - ( - cd docs/full-bf2-stack-example - sed -i '$!N;s@ports:\n - 53:53.*@@;P;D' docker-compose.yml # Remove coredns ports because it conflicts with system-resolved on the host - docker compose -f docker-compose.yml -f docker-compose.build.yml up --build -d - ) - docker compose -f docker-compose.test.yml --profile prod up - docker compose -f docker-compose.test.yml --profile dns up + + # Don't publish coredns ports to prevent conflict with system-resolved on github CI + # sed -i '$!N;s@ports:\n - 53:53.*@@;P;D' docker-compose.yml + + # Make coredns listen on localhost only to prevent conflict with system-resolved on github CI + sed -i 's/- 53:53/- 127.0.0.1:53:53/' docs/full-bf2-stack-example/docker-compose.yml + + ./test/test.sh prod 1 1 build: runs-on: ubuntu-latest diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0e552336..58ec8c43 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,19 +6,19 @@ { "label": "Test (dev)", "type": "shell", - "command": "docker-compose -f docker-compose.test.yml --profile dev up --force-recreate", + "command": "./test/test.sh dev 1", "group": "build" }, { "label": "Test (prod)", "type": "shell", - "command": "docker-compose -f docker-compose.test.yml --profile prod up --force-recreate", + "command": "./test/test.sh prod 1 1", "group": "build" }, { "label": "Test (dns)", "type": "shell", - "command": "docker-compose -f docker-compose.test.yml --profile dns up --force-recreate", + "command": "./test/test.sh dns", "group": "build" }, ] diff --git a/README.md b/README.md index 30d9227f..8497dab0 100644 --- a/README.md +++ b/README.md @@ -46,25 +46,23 @@ docker exec -it $( docker-compose ps -q asp ) ls -al /src/ASP/system/logs # asp - List snapshots docker exec -it $( docker-compose ps -q asp ) ls -alR /src/ASP/system/snapshots/ -# Test routes -docker-compose -f docker-compose.test.yml --profile dev up +# Test +./test/test.sh dev 1 # Test production builds -(cd docs/full-bf2-stack-example && docker-compose -f docker-compose.yml -f docker-compose.build.yml up --build) -docker-compose -f docker-compose.test.yml --profile prod up -docker-compose -f docker-compose.test.yml --profile dns up +./test/test.sh prod 1 1 # Dump the DB -docker exec $( docker-compose ps | grep db | awk '{print $1}' ) mysqldump -uroot -pascent bf2stats | gzip > bf2stats.sql.gz +docker exec $( docker-compose ps -q db ) mysqldump -uroot -pascent bf2stats | gzip > bf2stats.sql.gz # Restore the DB -zcat bf2stats.sql.gz | docker exec -i $( docker-compose ps | grep db | awk '{print $1}' ) mysql -uroot -pascent bf2stats +zcat bf2stats.sql.gz | docker exec -i $( docker-compose ps -q db ) mysql -uroot -pascent bf2stats # Stop docker-compose down # Cleanup -docker-compose down +docker-compose down --remove-orphans docker volume rm asp_backups-volume docker volume rm asp_cache-volume docker volume rm asp_config-volume diff --git a/docker-compose.test.yml b/docker-compose.test.yml deleted file mode 100644 index 4876631a..00000000 --- a/docker-compose.test.yml +++ /dev/null @@ -1,261 +0,0 @@ -version: '2.2' -services: - test-ready: - profiles: - - dev - - prod - - dns - image: alpine:latest - networks: - - bf2-network - stop_signal: SIGKILL - entrypoint: - - /bin/sh - command: - - -c - - | - set -eu - - echo "Waiting for stack to be ready" - s=0 - while true; do - nc -vz -w 1 asp 80 \ - && nc -vz -w 1 asp 9000 \ - && nc -vz -w 1 db 3306 \ - && break || true - s=$$(( $$s + 1 )) - if [ "$$s" -eq 600 ]; then - exit 1 - fi - echo "Retrying in 3 seconds" - sleep 3 - done - - test-routes: - profiles: - - dev - - prod - image: alpine:latest - environment: - URLS: | - http://asp/ 403 - http://asp/.htaccess 401 - http://asp/ASP/ 200 - http://asp/ASP/aspx 401 - http://asp/ASP/bf2statistics.php 403 - http://asp/ASP/frontend 401 - http://asp/ASP/frontend/css/bootstrap.min.css 200 - http://asp/ASP/frontend/images/maps/foo.png 200 - http://asp/ASP/frontend/images/ranks/foo.png 200 - http://asp/ASP/frontend/images/armies/foo.png 200 - http://asp/ASP/frontend/css/bootstrap.min.css 200 - http://asp/ASP/createplayer.aspx 200 - http://asp/ASP/getawardsinfo.aspx 200 - http://asp/ASP/getbackendinfo.aspx 200 - http://asp/ASP/getleaderboard.aspx 200 - http://asp/ASP/getmapinfo.aspx 200 - http://asp/ASP/getplayerid.aspx 200 - http://asp/ASP/getplayerinfo.aspx 200 - http://asp/ASP/getrankinfo.aspx 200 - http://asp/ASP/getunlocksinfo.aspx 200 - http://asp/ASP/ranknotification.aspx 200 - http://asp/ASP/searchforplayers.aspx 200 - http://asp/ASP/selectunlock.aspx 200 - http://asp/ASP/verifyplayer.aspx 200 - http://asp/ASP/index.php 200 - http://asp/ASP/ranknotification.aspx 200 - http://asp/ASP/searchforplayers.aspx 200 - http://asp/ASP/selectunlock.aspx 200 - http://asp/ASP/getplayerinfo.aspx 200 - http://asp/ASP/system 401 - - http://phpmyadmin/ 200 - networks: - - bf2-network - depends_on: - test-ready: - condition: service_completed_successfully - stop_signal: SIGKILL - entrypoint: - - /bin/sh - command: - - -c - - | - set -eu - echo "$$URLS" | awk NF | while read -r i j; do - if wget -q -SO- "$$i" 2>&1 | grep "HTTP/1.1 $$j " > /dev/null; then - echo "PASS: $$i" - else - echo "FAIL: $$i" - exit 1 - fi - done - - test-endpoints: - profiles: - - prod - image: alpine:latest - environment: - ENDPOINTS: | - asp.example.com/ 403 - asp.example.com/.htaccess 401 - asp.example.com/ASP/ 200 - asp.example.com/ASP/aspx 401 - asp.example.com/ASP/bf2statistics.php 403 - asp.example.com/ASP/frontend 401 - asp.example.com/ASP/frontend/css/bootstrap.min.css 200 - asp.example.com/ASP/frontend/images/maps/foo.png 200 - asp.example.com/ASP/frontend/images/ranks/foo.png 200 - asp.example.com/ASP/frontend/images/armies/foo.png 200 - asp.example.com/ASP/frontend/css/bootstrap.min.css 200 - asp.example.com/ASP/createplayer.aspx 200 - asp.example.com/ASP/getawardsinfo.aspx 200 - asp.example.com/ASP/getbackendinfo.aspx 200 - asp.example.com/ASP/getleaderboard.aspx 200 - asp.example.com/ASP/getmapinfo.aspx 200 - asp.example.com/ASP/getplayerid.aspx 200 - asp.example.com/ASP/getplayerinfo.aspx 200 - asp.example.com/ASP/getrankinfo.aspx 200 - asp.example.com/ASP/getunlocksinfo.aspx 200 - asp.example.com/ASP/ranknotification.aspx 200 - asp.example.com/ASP/searchforplayers.aspx 200 - asp.example.com/ASP/selectunlock.aspx 200 - asp.example.com/ASP/verifyplayer.aspx 200 - asp.example.com/ASP/index.php 200 - asp.example.com/ASP/ranknotification.aspx 200 - asp.example.com/ASP/searchforplayers.aspx 200 - asp.example.com/ASP/selectunlock.aspx 200 - asp.example.com/ASP/getplayerinfo.aspx 200 - asp.example.com/ASP/system 401 - network_mode: host - depends_on: - test-ready: - condition: service_completed_successfully - stop_signal: SIGKILL - entrypoint: - - /bin/sh - command: - - -c - - | - set -eu - apk add --no-cache curl - echo "$$ENDPOINTS" | awk NF | while read -r i j; do - d=$$( echo "$$i" | cut -d '/' -f1 ) - if curl --head -skL http://$$i --resolve $$d:80:127.0.0.1 --resolve $$d:443:127.0.0.1 2>&1 | grep -E "^HTTP/(1.1|2) $$j " > /dev/null; then - echo "PASS: $$i" - else - echo "FAIL: $$i" - exit 1 - fi - done - - test-interal-dns: - profiles: - - dns - image: alpine:latest - environment: - DNS: | - battlefield2.available.gamespy.com - battlefield2.master.gamespy.com - battlefield2.ms14.gamespy.com - master.gamespy.com - motd.gamespy.com - gpsp.gamespy.com - gpcm.gamespy.com - gamespy.com - bf2web.gamespy.com - gamestats.gamespy.com - eapusher.dice.se - networks: - - bf2-network - depends_on: - test-ready: - condition: service_completed_successfully - stop_signal: SIGKILL - entrypoint: - - /bin/sh - command: - - -c - - | - set -eu - echo "$$DNS" | awk NF | grep -v '127.0.0' | while read -r h; do - if nslookup $$h | grep -v '127.0.0' | grep -E '^Address: [0-9\.]+$$'; then - echo "PASS: $$h" - else - echo "FAIL: $$h" - exit 1 - fi - done - - test-coredns: - profiles: - - dns - image: alpine:latest - environment: - DNS: | - 192.168.1.100 battlefield2.available.gamespy.com - 192.168.1.100 battlefield2.master.gamespy.com - 192.168.1.100 battlefield2.ms14.gamespy.com - 192.168.1.100 master.gamespy.com - 192.168.1.100 motd.gamespy.com - 192.168.1.100 gpsp.gamespy.com - 192.168.1.100 gpcm.gamespy.com - 192.168.1.100 gamespy.com - 192.168.1.100 bf2web.gamespy.com - 192.168.1.100 gamestats.gamespy.com - 192.168.1.100 eapusher.dice.se - networks: - - bf2-network - depends_on: - test-ready: - condition: service_completed_successfully - stop_signal: SIGKILL - entrypoint: - - /bin/sh - command: - - -c - - | - set -eu - echo "$$DNS" | awk NF | while read -r ip h; do - if nslookup $$h coredns | grep -E "^Address: $$ip" > /dev/null; then - echo "PASS: $$h" - else - echo "FAIL: $$h" - exit 1 - fi - done - - - test-snapshots: - profiles: - - dev - - prod - image: alpine:latest - volumes: - - ./test:/test:ro - networks: - - bf2-network - depends_on: - test-ready: - condition: service_completed_successfully - stop_signal: SIGKILL - entrypoint: - - /bin/sh - command: - - -c - - | - set -eu - apk add --no-cache curl - for i in test/snapshots/daqing_oilfields_20231107_2212.json test/snapshots/dalian_plant_20231107_2211.json; do - RES=$$( set -x; curl -s -A GameSpyHTTP/1.0 -H 'Content-Type: application/json' --data "@$$i" http://asp/ASP/bf2statistics.php ) - echo "$$RES"; echo - if [ "$$( echo "$$RES" | head -c1 )" = 'O' ]; then - echo "PASS: $$i" - else - echo "FAIL: $$i" - exit 1 - fi - done - -networks: - bf2-network: diff --git a/docs/full-bf2-stack-example/docker-compose.build.yml b/docs/full-bf2-stack-example/docker-compose.build.yml index ddd5b67f..ef8433c8 100644 --- a/docs/full-bf2-stack-example/docker-compose.build.yml +++ b/docs/full-bf2-stack-example/docker-compose.build.yml @@ -9,3 +9,8 @@ services: - type=local,src=/tmp/.buildx-cache-asp # cache_to: # - type=local,dest=/tmp/.buildx-cache-asp,mode=max + + db: + volumes: + - ../../src/ASP/system/sql/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro # Seed the DB the first time + - ../../src/ASP/system/sql/data.sql:/docker-entrypoint-initdb.d/02-data.sql:ro # Seed the DB the first time diff --git a/test/.env b/test/.env new file mode 100644 index 00000000..4cc5b70a --- /dev/null +++ b/test/.env @@ -0,0 +1 @@ +COMPOSE_PROJECT_NAME=asp diff --git a/test/docker-compose.yml b/test/docker-compose.yml new file mode 100644 index 00000000..7bbce4e3 --- /dev/null +++ b/test/docker-compose.yml @@ -0,0 +1,35 @@ +version: '2.2' +services: + test-container-networking: + image: alpine:latest + volumes: + - ./:/test:ro + networks: + - gamespy-network + - bf2-network + stop_signal: SIGKILL + working_dir: /test + entrypoint: + - /bin/sh + command: + - -c + - | + sleep infinity + + test-host-networking: + image: alpine:latest + volumes: + - ./:/test:ro + network_mode: host + stop_signal: SIGKILL + working_dir: /test + entrypoint: + - /bin/sh + command: + - -c + - | + sleep infinity + +networks: + bf2-network: + gamespy-network: diff --git a/test/test-endpoints.sh b/test/test-endpoints.sh new file mode 100755 index 00000000..ebc1667b --- /dev/null +++ b/test/test-endpoints.sh @@ -0,0 +1,47 @@ +#!/bin/sh +set -eu + +echo +echo "[test-endpoints]" +ENDPOINTS=" +asp.example.com/ 200 +asp.example.com/.htaccess 401 +asp.example.com/ASP/ 200 +asp.example.com/ASP/aspx 401 +asp.example.com/ASP/bf2statistics.php 403 +asp.example.com/ASP/frontend 401 +asp.example.com/ASP/frontend/css/bootstrap.min.css 200 +asp.example.com/ASP/frontend/images/maps/foo.png 200 +asp.example.com/ASP/frontend/images/ranks/foo.png 200 +asp.example.com/ASP/frontend/images/armies/foo.png 200 +asp.example.com/ASP/frontend/css/bootstrap.min.css 200 +asp.example.com/ASP/createplayer.aspx 200 +asp.example.com/ASP/getawardsinfo.aspx 200 +asp.example.com/ASP/getbackendinfo.aspx 200 +asp.example.com/ASP/getleaderboard.aspx 200 +asp.example.com/ASP/getmapinfo.aspx 200 +asp.example.com/ASP/getplayerid.aspx 200 +asp.example.com/ASP/getplayerinfo.aspx 200 +asp.example.com/ASP/getrankinfo.aspx 200 +asp.example.com/ASP/getunlocksinfo.aspx 200 +asp.example.com/ASP/ranknotification.aspx 200 +asp.example.com/ASP/searchforplayers.aspx 200 +asp.example.com/ASP/selectunlock.aspx 200 +asp.example.com/ASP/verifyplayer.aspx 200 +asp.example.com/ASP/index.php 200 +asp.example.com/ASP/ranknotification.aspx 200 +asp.example.com/ASP/searchforplayers.aspx 200 +asp.example.com/ASP/selectunlock.aspx 200 +asp.example.com/ASP/getplayerinfo.aspx 200 +asp.example.com/ASP/system 401 +" +apk add --no-cache curl +echo "$ENDPOINTS" | awk NF | while read -r i j; do + d=$( echo "$i" | cut -d '/' -f1 ) + if curl --head -skL http://$i --resolve $d:80:127.0.0.1 --resolve $d:443:127.0.0.1 2>&1 | grep -E "^HTTP/(1.1|2) $j " > /dev/null; then + echo "PASS: $i" + else + echo "FAIL: $i" + exit 1 + fi +done diff --git a/test/test-external-dns.sh b/test/test-external-dns.sh new file mode 100755 index 00000000..55c946d4 --- /dev/null +++ b/test/test-external-dns.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -eu + +echo +echo "[test-external-dns]" +DNS=" +192.168.1.100 battlefield2.available.gamespy.com +192.168.1.100 battlefield2.master.gamespy.com +192.168.1.100 battlefield2.ms14.gamespy.com +192.168.1.100 master.gamespy.com +192.168.1.100 motd.gamespy.com +192.168.1.100 gpsp.gamespy.com +192.168.1.100 gpcm.gamespy.com +192.168.1.100 gamespy.com +192.168.1.100 bf2web.gamespy.com +192.168.1.100 gamestats.gamespy.com +192.168.1.100 eapusher.dice.se +" +echo "$DNS" | awk NF | while read -r ip h; do + if nslookup $h coredns | grep -E "^Address: $ip" > /dev/null; then + echo "PASS: $h" + else + echo "FAIL: $h" + exit 1 + fi +done diff --git a/test/test-internal-dns.sh b/test/test-internal-dns.sh new file mode 100755 index 00000000..76916d13 --- /dev/null +++ b/test/test-internal-dns.sh @@ -0,0 +1,24 @@ +#!/bin/sh +set -eu + +echo +echo "[test-internal-dns]" +DNS=" +battlefield2.available.gamespy.com +battlefield2.master.gamespy.com +battlefield2.ms14.gamespy.com +master.gamespy.com +motd.gamespy.com +gpsp.gamespy.com +gpcm.gamespy.com +gamespy.com +bf2web.gamespy.com +" +echo "$DNS" | awk NF | grep -v '127.0.0' | while read -r h; do + if nslookup $h | grep -v '127.0.0' | grep -E '^Address: [0-9\.]+$'; then + echo "PASS: $h" + else + echo "FAIL: $h" + exit 1 + fi +done diff --git a/test/test-ready.sh b/test/test-ready.sh new file mode 100755 index 00000000..fd306cd9 --- /dev/null +++ b/test/test-ready.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -eu + +echo +echo "[test-ready] Waiting for stack to be ready" +s=0 +while true; do + nc -vz -w 1 asp 80 \ + && nc -vz -w 1 asp 9000 \ + && nc -vz -w 1 db 3306 \ + && break || true + s=$(( $s + 1 )) + if [ "$s" -eq 100 ]; then + exit 1 + fi + echo "Retrying in 3 seconds" + sleep 3 +done diff --git a/test/test-routes.sh b/test/test-routes.sh new file mode 100755 index 00000000..30df365c --- /dev/null +++ b/test/test-routes.sh @@ -0,0 +1,47 @@ +#!/bin/sh +set -eu + +echo +echo "[test-routes]" +URLS=" +http://asp/ 200 +http://asp/.htaccess 401 +http://asp/ASP/ 200 +http://asp/ASP/aspx 401 +http://asp/ASP/bf2statistics.php 403 +http://asp/ASP/frontend 401 +http://asp/ASP/frontend/css/bootstrap.min.css 200 +http://asp/ASP/frontend/images/maps/foo.png 200 +http://asp/ASP/frontend/images/ranks/foo.png 200 +http://asp/ASP/frontend/images/armies/foo.png 200 +http://asp/ASP/frontend/css/bootstrap.min.css 200 +http://asp/ASP/createplayer.aspx 200 +http://asp/ASP/getawardsinfo.aspx 200 +http://asp/ASP/getbackendinfo.aspx 200 +http://asp/ASP/getleaderboard.aspx 200 +http://asp/ASP/getmapinfo.aspx 200 +http://asp/ASP/getplayerid.aspx 200 +http://asp/ASP/getplayerinfo.aspx 200 +http://asp/ASP/getrankinfo.aspx 200 +http://asp/ASP/getunlocksinfo.aspx 200 +http://asp/ASP/ranknotification.aspx 200 +http://asp/ASP/searchforplayers.aspx 200 +http://asp/ASP/selectunlock.aspx 200 +http://asp/ASP/verifyplayer.aspx 200 +http://asp/ASP/index.php 200 +http://asp/ASP/ranknotification.aspx 200 +http://asp/ASP/searchforplayers.aspx 200 +http://asp/ASP/selectunlock.aspx 200 +http://asp/ASP/getplayerinfo.aspx 200 +http://asp/ASP/system 401 + +http://phpmyadmin/ 200 +" +echo "$URLS" | awk NF | while read -r i j; do + if wget -q -SO- "$i" 2>&1 | grep "HTTP/1.1 $j " > /dev/null; then + echo "PASS: $i" + else + echo "FAIL: $i" + exit 1 + fi +done diff --git a/test/test-snapshots.sh b/test/test-snapshots.sh new file mode 100755 index 00000000..1c8cd962 --- /dev/null +++ b/test/test-snapshots.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -eu + +SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd ) +cd "$SCRIPT_DIR" + +echo +echo "[test-snapshots]" +apk add --no-cache curl +for i in ./snapshots/*; do + RES=$( set -x; curl -s -A GameSpyHTTP/1.0 -H 'Content-Type: application/json' --data "@$i" http://asp/ASP/bf2statistics.php ) + echo "$RES"; echo + if [ "$( echo "$RES" | head -c1 )" = 'O' ]; then + echo "PASS: $i" + else + echo "FAIL: $i" + exit 1 + fi +done diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 00000000..de4b50b4 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,92 @@ +#!/bin/sh +set -eu + +TEST=${1:-} # Test environment +UP=${2:-} # Whether to docker compose up and down the test stack +CACHE=${3:-} # Whether to override with docker-compose.build.yml + +# Validation and normalization +if ! echo "$TEST" | grep -E '^(dev|prod|dns|snapshots)$' > /dev/null; then + echo "Specify TEST as the first argument. E.g. 'dev', 'prod', 'dns'" + exit 1 +fi +if [ -n "$CACHE" ]; then + CACHE='-f docker-compose.build.yml' +fi + +SCRIPT_DIR=$( cd "$( dirname "$0" )" && pwd ) +ERR= +setup_test() { + cd "$SCRIPT_DIR" + docker compose up -d + if [ -n "$UP" ]; then + setup + fi + run +} +cleanup_test() { + ERR=$? + if [ -n "$UP" ]; then + cleanup + fi + docker compose stop + if [ -z "$ERR" ] || [ "$ERR" = 0 ]; then + echo "All tests succeeded" + else + echo "Some tests failed" + echo "Exit code: $ERR" + exit "$ERR" + fi +} +trap cleanup_test INT TERM EXIT + +echo "Testing..." +seed_database() { + ( + cd .. + docker exec $( docker compose ps -q db ) mysql -h db -uroot -pascent bf2stats -e 'UPDATE stats_provider SET authorized = 1 WHERE id = 1' + docker exec $( docker compose ps -q db ) mysql -h db -uroot -pascent bf2stats -e 'SELECT * FROM stats_provider' + docker exec $( docker compose ps -q db ) mysql -h db -uroot -pascent bf2stats -e "UPDATE stats_provider_auth_ip SET address = '0.0.0.0/0' " + docker exec $( docker compose ps -q db ) mysql -h db -uroot -pascent bf2stats -e 'SELECT * FROM stats_provider_auth_ip' + ) +} +if [ "$TEST" = 'dev' ]; then + setup() { + (cd .. && docker compose -f docker-compose.yml $CACHE up --build -d) + } + run() { + docker exec $( docker compose ps -q test-container-networking ) ./test-ready.sh + seed_database + docker exec $( docker compose ps -q test-container-networking ) ./test-routes.sh + docker exec $( docker compose ps -q test-container-networking ) ./test-snapshots.sh + # docker exec $( docker compose ps -q test-container-networking ) ./test-internal-dns.sh + } + cleanup() { + (cd .. && docker compose stop) + } +fi +if [ "$TEST" = 'prod' ]; then + setup() { + (cd ../docs/full-bf2-stack-example && docker compose -f docker-compose.yml $CACHE up --build -d) + } + run() { + docker exec $( docker compose ps -q test-container-networking ) ./test-ready.sh + seed_database + docker exec $( docker compose ps -q test-container-networking ) ./test-routes.sh + docker exec $( docker compose ps -q test-host-networking ) ./test-endpoints.sh + docker exec $( docker compose ps -q test-container-networking ) ./test-snapshots.sh + docker exec $( docker compose ps -q test-container-networking ) ./test-internal-dns.sh + docker exec $( docker compose ps -q test-container-networking ) ./test-external-dns.sh + } + cleanup() { + (cd ../docs/full-bf2-stack-example && docker compose -f docker-compose.yml $CACHE stop) + } +fi +if [ "$TEST" = 'dns' ]; then + run() { + docker exec $( docker compose ps -q test-container-networking ) ./test-ready.sh + docker exec $( docker compose ps -q test-container-networking ) ./test-internal-dns.sh + docker exec $( docker compose ps -q test-container-networking ) ./test-external-dns.sh + } +fi +setup_test