-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb45244
commit 5a4e6ac
Showing
4 changed files
with
46 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,25 @@ | ||
#!/bin/bash | ||
|
||
DOCKER_COMPOSE_FILE="${1:-docker-compose.yml}" | ||
DEFAULT_NODE_ENV=${NODE_ENV:-""} | ||
export NODE_ENV=test | ||
DEFAULT_DB_NAME=${DB_NAME:-""} | ||
export DB_NAME=test_${DB_NAME} | ||
|
||
docker-compose -f ${DOCKER_COMPOSE_FILE} stop | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} pull db | ||
echo "Creating Docker containers..." | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} up --no-start | ||
echo "Starting DB..." | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} start db | ||
|
||
# Tests have been flaky in CI, probably due to the DB not being ready | ||
# even if the server is running. In other projects, a 4-second sleep | ||
# safely give the DB time to get ready for input. | ||
sleep 4 | ||
DOCKER_COMPOSE_FILE="${1:-docker-compose.ci.yml}" | ||
|
||
# Need to create test DB separately because TypeORM won't do it for us | ||
docker exec -t productcatalog_db_1 \ | ||
cockroach sql --execute "CREATE DATABASE ${DB_NAME};" --insecure | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} exec -T db \ | ||
cockroach sql --execute "CREATE DATABASE IF NOT EXISTS test;" --insecure | ||
|
||
docker-compose -f ${DOCKER_COMPOSE_FILE} run --rm server \ | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} exec -T server \ | ||
yarn run migration:run -d src/dataSource.ts | ||
|
||
EXIT_CODE=$? | ||
|
||
if [ ${EXIT_CODE} == 0 ] | ||
then | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} run --rm server yarn test:integration | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} exec -T server yarn test:integration | ||
|
||
EXIT_CODE=$? | ||
fi | ||
|
||
# TEST CLEANUP | ||
docker exec -t productcatalog_db_1 \ | ||
cockroach sql --execute "DROP DATABASE IF EXISTS ${DB_NAME};" --insecure | ||
|
||
docker-compose -f ${DOCKER_COMPOSE_FILE} stop | ||
export NODE_ENV=${DEFAULT_NODE_ENV} | ||
export DB_NAME=${DEFAULT_DB_NAME} | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} up -d | ||
docker-compose -f ${DOCKER_COMPOSE_FILE} exec -T db \ | ||
cockroach sql --execute "DROP DATABASE IF EXISTS test;" --insecure | ||
|
||
exit ${EXIT_CODE} |