Add integration test

This commit is contained in:
IamTheFij 2020-08-19 13:04:37 -07:00
parent 9913442526
commit e83d5b6784
4 changed files with 76 additions and 1 deletions

3
.gitignore vendored
View File

@ -30,3 +30,6 @@ dockron
dockron-*
# deps
vendor/
# Test output
itest/*_result.txt

View File

@ -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:

30
itest/docker-compose.yml Normal file
View File

@ -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'

36
itest/itest.sh Executable file
View File

@ -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