Add integration test
This commit is contained in:
parent
a572bd6635
commit
a1ba2060bb
3
.gitignore
vendored
3
.gitignore
vendored
@ -30,3 +30,6 @@ dockron
|
|||||||
dockron-*
|
dockron-*
|
||||||
# deps
|
# deps
|
||||||
vendor/
|
vendor/
|
||||||
|
|
||||||
|
# Test output
|
||||||
|
itest/*_result.txt
|
||||||
|
8
Makefile
8
Makefile
@ -1,4 +1,3 @@
|
|||||||
.PHONY: test all
|
|
||||||
DOCKER_TAG ?= dockron-dev-${USER}
|
DOCKER_TAG ?= dockron-dev-${USER}
|
||||||
GIT_TAG_NAME := $(shell git tag -l --contains HEAD)
|
GIT_TAG_NAME := $(shell git tag -l --contains HEAD)
|
||||||
GIT_SHA := $(shell git rev-parse HEAD)
|
GIT_SHA := $(shell git rev-parse HEAD)
|
||||||
@ -9,6 +8,9 @@ GOFILES = *.go go.mod go.sum
|
|||||||
.PHONY: default
|
.PHONY: default
|
||||||
default: build
|
default: build
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: check test itest
|
||||||
|
|
||||||
# Downloads dependencies into vendor directory
|
# Downloads dependencies into vendor directory
|
||||||
vendor: $(GOFILES)
|
vendor: $(GOFILES)
|
||||||
go mod vendor
|
go mod vendor
|
||||||
@ -25,6 +27,10 @@ test:
|
|||||||
@go tool cover -func=coverage.out | awk -v target=75.0% \
|
@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; } }'
|
'/^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
|
# Installs pre-commit hooks
|
||||||
.PHONY: install-hooks
|
.PHONY: install-hooks
|
||||||
install-hooks:
|
install-hooks:
|
||||||
|
30
itest/docker-compose.yml
Normal file
30
itest/docker-compose.yml
Normal 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
36
itest/itest.sh
Executable 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
|
Loading…
Reference in New Issue
Block a user