From e83d5b6784e82f6f0d2269e92364afec9452cb7b Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Wed, 19 Aug 2020 13:04:37 -0700 Subject: [PATCH] Add integration test --- .gitignore | 3 +++ Makefile | 8 +++++++- itest/docker-compose.yml | 30 ++++++++++++++++++++++++++++++ itest/itest.sh | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 itest/docker-compose.yml create mode 100755 itest/itest.sh diff --git a/.gitignore b/.gitignore index 79074fb..b5db829 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ dockron dockron-* # deps vendor/ + +# Test output +itest/*_result.txt diff --git a/Makefile b/Makefile index f3d99de..db257f9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -.PHONY: test all DOCKER_TAG ?= dockron-dev-${USER} GIT_TAG_NAME := $(shell git tag -l --contains HEAD) GIT_SHA := $(shell git rev-parse HEAD) @@ -9,6 +8,9 @@ GOFILES = *.go go.mod go.sum .PHONY: default default: build +.PHONY: all +all: check test itest + # Downloads dependencies into vendor directory vendor: $(GOFILES) go mod vendor @@ -25,6 +27,10 @@ test: @go tool cover -func=coverage.out | awk -v target=75.0% \ '/^total:/ { print "Total coverage: " $$3 " Minimum coverage: " target; if ($$3+0.0 >= target+0.0) print "ok"; else { print "fail"; exit 1; } }' +.PHONY: itest +itest: + ./itest/itest.sh + # Installs pre-commit hooks .PHONY: install-hooks install-hooks: diff --git a/itest/docker-compose.yml b/itest/docker-compose.yml new file mode 100644 index 0000000..29b6311 --- /dev/null +++ b/itest/docker-compose.yml @@ -0,0 +1,30 @@ +--- +version: '3' + +services: + dockron: + build: + context: ../ + dockerfile: ./Dockerfile.multi-stage + command: ["-watch", "10s", "-debug"] + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + + start_echoer: + image: busybox:latest + command: sh -c "echo ok | tee -a /result.txt" + volumes: + - "./start_result.txt:/result.txt" + labels: + # Execute every minute + - 'dockron.schedule=* * * * *' + + exec_echoer: + image: busybox:latest + command: sh -c "tail -f /result.txt" + volumes: + - "./exec_result.txt:/result.txt" + labels: + # Execute every minute + - 'dockron.test.schedule=* * * * *' + - 'dockron.test.command=echo ok >> /result.txt' diff --git a/itest/itest.sh b/itest/itest.sh new file mode 100755 index 0000000..8b62bd1 --- /dev/null +++ b/itest/itest.sh @@ -0,0 +1,36 @@ +#! /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 + # Start containers + echo "Starting containers" + docker-compose up -d --build + echo "Containers started. Sleeping for 70s to let schedules run" + # Schedules run on the shortest interval of a minute. This should allow time + # for the containers to start and execute once + sleep 70 + echo "Stopping containers" + docker-compose stop + + # Validate result shows minimum amount of executions + check_results ./start_result.txt 2 + check_results ./exec_result.txt 1 +} + +main