dockron/itest/itest.sh

48 lines
1.2 KiB
Bash
Raw Normal View History

2020-08-19 20:04:37 +00:00
#! /bin/bash
set -e
# Change to itest dir
cd "$(dirname "$0")"
function check_results() {
local f=$1
local min=$2
awk "/ok/ { count=count+1 } END { print \"$f: Run count\", count; if (count < $min) { print \"Expected > $min\"; exit 1 } }" "$f"
}
function main() {
# Clear and create result files
echo "start" > ./start_result.txt
echo "start" > ./exec_result.txt
# Clean old containers
docker compose down || true
2020-08-19 20:04:37 +00:00
# Start containers
echo "Starting containers"
docker compose up -d --build
2020-08-19 20:04:37 +00:00
# Schedules run on the shortest interval of a minute. This should allow time
# for the containers to start and execute once
local seconds=$((65 - $(date +"%S")))
echo "Containers started. Sleeping for ${seconds}s to let schedules run"
sleep $seconds
2020-08-19 20:04:37 +00:00
echo "Stopping containers"
docker compose stop
2020-08-19 20:04:37 +00:00
# Print logs
docker compose logs
2020-08-19 20:04:37 +00:00
# Validate result shows minimum amount of executions
check_results ./start_result.txt 2
check_results ./exec_result.txt 1
# Check for exec output
if ! (docker compose logs | grep -q "Yay!"); then
echo "Exec output 'Yay!' not found"
exit 1
fi
2020-08-19 20:04:37 +00:00
}
main