Testing A Central server running in Docker containers
Steps to run unit and integration tests in a central odk that is running in docker containers
- Install and run docker and central following https://docs.getodk.org/central-install-digital-ocean/#getting-and-setting-up-central . docker ps should resemble the following (except for "CONTAINER ID"s).
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e1139a2642c central_nginx "/bin/bash /scripts/…" 2 months ago Up 4 hours (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp nginx
579babb89351 central_service "docker-entrypoint.s…" 2 months ago Up 4 hours 8383/tcp service
2eaf0f8b461b central_enketo "docker-entrypoint.s…" 2 months ago Up 4 hours 8005/tcp enketo
444b4e46ba88 redis:5 "docker-entrypoint.s…" 2 months ago Up 4 hours 6379/tcp enketo_redis_main
db76c1ee6bb9 postgres:9.6 "docker-entrypoint.s…" 2 months ago Up 4 hours 5432/tcp central_postgres_1
3aa2fad29c89 itsissa/namshi-smtp:4.89-2.deb9u5 "/bin/entrypoint.sh …" 2 months ago Up 4 hours 25/tcp mail
c69105cd822a redis:5 "docker-entrypoint.s…" 2 months ago Up 4 hours 6379/tcp enketo_redis_cache
9d252e105a52 getodk/pyxform-http:v1.3.3 "waitress-serve --po…" 2 months ago Up 4 hours pyxform
-
In file central/config/default.json test database change "host" to "central_postgres_1" from "localhost". I.E, in directory central/server/config, git diff should display.
diff --git a/config/default.json b/config/default.json index e5db0c9..ab27a4b 100644 --- a/config/default.json +++ b/config/default.json @@ -32,7 +32,7 @@ }, "test": { "database": { - "host": "localhost", + "host": "central_postgres_1", "user": "jubilant", "password": "jubilant", "database": "jubilant_test"
-
In central/server directory create file integration-test.dockerfile as follows:
FROM node:12 RUN apt update && apt install -y make WORKDIR /server COPY . . CMD ["make" ,"test-integration"]
-
Create "ti" docker container
docker build -f integration-test.dockerfile -t ti .
-
Figure out the postgres "CONTAINER ID" . In the "docker ps" output, is the 12 character string before "postgres" or just execute:
docker ps | grep postgres | cut -d " " -f1
-
Open a terminal inside the postgres container. Replace <psq> below with the "CONTAINER ID" you found above.
docker exec -it <psq> /bin/bash
-
In the terminal opened above, enter the following, one line at a time. There should be no
errors. This step creates a permanant database inside the postgres container. It only needs to be repeated after each central "docker build".psql odk odk CREATE USER jubilant WITH PASSWORD 'jubilant'; CREATE DATABASE jubilant_test with owner=jubilant encoding=UTF8; \c jubilant; CREATE EXTENSION IF NOT EXISTS CITEXT; CREATE EXTENSION IF NOT EXISTS pg_trgm; \q exit
-
Run the test
docker run --network central_default -t ti
You should see an install of node followed by lots of very detailed reporting. My system reports 756 passing, 2 failing. I have not investigated. To see the log from my system:
wget https://www.dropbox.com/s/mjsifh8a2e4pb4h/2021-07-27-integration-test-docker.log
sudo apt install lnav #ubuntu
lnav 2021-07-27-integration-test-docker.log
lnav tips: Push your "Home" key to see the start of the file; ? shows/hides help
-
run test-unit
docker run -t ti make test-unit
On my system the tally reads "561 passing (4s) 1 pending 1 failing". I have not analyzed those results.
The link to the log file from my system is: https://www.dropbox.com/s/krg2o26dcvx6wvi/2021-08-01-unit-test-docker.log . See previous step for help reading that.