-
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.
Without this commit, you have to provide the --init argument to Docker. See moby/moby#2838 (comment) This also adds a test that verifies that this works.
- Loading branch information
Showing
6 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Common functions used for our tests | ||
|
||
# use this instead of echo inside tests | ||
log() { | ||
local BLUE='\033[0;34m' | ||
local RESET='\033[0m' | ||
echo -e "$BLUE"[test] "$*""$RESET" | ||
} | ||
|
||
container-running() { | ||
[ "$(docker inspect -f '{{.State.Running}}' "$1")" = "true" ] | ||
} | ||
|
||
container-stop() { | ||
# ignore if there is an error (which means that the container is already stopped) | ||
docker stop "$1" 2>&1>/dev/null || true | ||
} | ||
|
||
containers-stop() { | ||
[ -n "${TONARI:-}" ] && container-stop "$TONARI" | ||
[ -n "${MONGO:-}" ] && container-stop "$MONGO" | ||
} | ||
|
||
containers-run() { | ||
export TONARI_SOURCE_ID=${TONARI_SOURCE_ID:-00000000000000000000000000000000} | ||
export TONARI_IMAGE_URL_PREFIX=${TONARI_IMAGE_URL_PREFIX:-https://tonari.app/api/images/} | ||
export TONARI_IMAGE_PATH=${TONARI_IMAGE_PATH:-/images} | ||
export TONARI_DATABASE_NAME=${TONARI_DATABASE_NAME:-tonari} | ||
export ROCKET_DATABASES=${ROCKET_DATABASES:-'{sanitary_facilities={url="mongodb://localhost:27017/sanitary_facilities"}}'} | ||
export ROCKET_PORT=${ROCKET_PORT:-8000} | ||
ROCKET_SECRET_KEY_DEFAULT=$(openssl rand -base64 32) | ||
export ROCKET_SECRET_KEY=${ROCKET_SECRET_KEY:-$ROCKET_SECRET_KEY_DEFAULT} | ||
export MONGO=$(docker run -d -p 27017:27017 mongo --wiredTigerCacheSizeGB 1.5) | ||
export TONARI=$(docker run -d -eTONARI_{SOURCE_ID,IMAGE_URL_PREFIX,IMAGE_PATH} -eROCKET_{DATABASES,PORT} --network=host tonari/backend) | ||
} | ||
|
||
# bats setup | ||
setup() { | ||
containers-run | ||
} | ||
|
||
# bats teardown | ||
teardown() { | ||
containers-stop | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bats | ||
|
||
load framework | ||
|
||
# Test if a SIGINT signal stops the Docker container | ||
@test "SIGINT stops Docker container" { | ||
# wait so that the container is stopped if there are any startup problems | ||
sleep 1 | ||
|
||
if ! container-running $TONARI; then | ||
log Tonari failed to start: | ||
docker logs $TONARI | ||
echo Tonari is running > /dev/null | ||
return 1 | ||
fi | ||
|
||
docker kill --signal=SIGINT $TONARI > /dev/null | ||
sleep 4 | ||
if container-running $TONARI; then | ||
log Tonari failed to be killed | ||
false | ||
fi | ||
} |