- sudo apt-get install git
- cd
Checkout directory - Install MySQL
sudo apt-get install mysql-server - Install Workbench
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -sudo apt-get install -y nodejsnpm installnpm run buildexport MYSQL_HOST=localhost && node src/server/init.js(For first initialization)
export MYSQL_HOST=localhost && npm start
- MASONS_ENV=TEST
- Create masons_test schema and user in accordane with
conf(it is easier via MySQL Workbench) - user interface=bdd
- test directory=
Checkout directory/tests
First, run database container.
docker network create mynet
docker run -d -p 3306:3306 \
--env "MYSQL_ROOT_PASSWORD=<PASSWORD>" \
--env "MYSQL_HOST=<CONTAINER NAME>" \
--name <CONTAINER NAME> \
--volume <LOCAL PATH>:/var/lib/mysql \
--net mynet \
osboo/masonsmafia-db
If <LOCAL PATH> contains data then the container works with it. If there is a need in first database initialization (fresh install or running in testing envrironment) then following command should be executed:
docker exec -it <DB CONTAINER NAME> node src/server/init.js
Before each Mocha tests run the database should be initialized. Please also note that the container volume should be stateless so it must be cleaned after each test run. Command to inititialize the database in test env:
docker exec -it -e MASONS_ENV=TEST <DB CONTAINER NAME> node src/server/init.js
Then run container in user defined network (mynet in this example):
docker run -p 3000:3000 \
--name <APP CONTAINER NAME> \
--env "MYSQL_HOST=<DB CONTAINER NAME>" \
--net mynet \
osboo/masonsmafia-app
Create docker-compose.yml file with following:
version: '3'
services:
db:
image: osboo/masonsmafia-db
container_name: <DB CONTAINER NAME>
volumes:
- <LOCAL PATH>:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: <PASSWORD>
MYSQL_HOST: db
app:
depends_on:
- db
image: osboo/masonsmafia-app
container_name: <APP CONTAINER NAME>
ports:
- "3000:3000"
environment:
MYSQL_HOST: db
Then run:
docker-compose up
Before the first run the database should be initialized by app-required schema and user settings.
Aliases <DB CONTAINER NAME> and <APP CONTAINER NAME> will define the name of containers to apply initialization command (by default docker creates containers with random unpredictable names).
Make docker-compose.test.yml with following configuration:
version: '3'
services:
db:
image: osboo/masonsmafia-db
container_name: testdb
volumes:
- <TEMPORARY LOCAL STORAGE>:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: mypassword
MYSQL_HOST: db
app:
depends_on:
- db
image: osboo/masonsmafia-app
container_name: testapp
ports:
- "3000:3000"
environment:
MYSQL_HOST: db
MASONS_ENV: TEST
Then spin up containers:
docker-compose -f docker-compose.test.yml up -d
Then initialize the fresh local store see above.
And restart containers again (first run is unsuccessfull as database it not initialized):
docker-compose -f docker-compose.test.yml restart
- For unit-tests call:
docker exec -it testapp ./node_modules/mocha/bin/mocha -u bdd ./tests/unit-tests - For integration tests (db):
docker exec -it testapp ./node_modules/mocha/bin/mocha -u bdd ./tests/dbtest - For integration tests (add new games):
docker exec -it testapp ./node_modules/mocha/bin/mocha -u bdd ./tests/personal_statistics_test