Add some tests and drone to run them
This commit is contained in:
parent
65b9cd0f1b
commit
af49bee4e5
29
.drone.yml
Normal file
29
.drone.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: test
|
||||||
|
|
||||||
|
workspace:
|
||||||
|
base: "/app"
|
||||||
|
path: "."
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
image: python:3-alpine
|
||||||
|
commands:
|
||||||
|
- apk add bash shellcheck make gcc musl-dev libffi-dev openssl-dev
|
||||||
|
- pip install docker-compose
|
||||||
|
- make all
|
||||||
|
|
||||||
|
- name: notify
|
||||||
|
image: drillster/drone-email
|
||||||
|
settings:
|
||||||
|
host:
|
||||||
|
from_secret: SMTP_HOST # pragma: whitelist secret
|
||||||
|
username:
|
||||||
|
from_secret: SMTP_USER # pragma: whitelist secret
|
||||||
|
password:
|
||||||
|
from_secret: SMTP_PASS # pragma: whitelist secret
|
||||||
|
from: drone@iamthefij.com
|
||||||
|
when:
|
||||||
|
status: [changed, failure]
|
21
Makefile
Normal file
21
Makefile
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
.PHONY: all test clean
|
||||||
|
|
||||||
|
all: test shellcheck
|
||||||
|
|
||||||
|
test: test-negative test-positive
|
||||||
|
|
||||||
|
.PHONY: shellcheck
|
||||||
|
shellcheck:
|
||||||
|
shellcheck *.sh
|
||||||
|
|
||||||
|
.PHONY: test-positive
|
||||||
|
test-positive:
|
||||||
|
@echo "Check valid compose file."
|
||||||
|
./compose-check.sh tests/docker-compose.yml || { echo 'fail'; exit 1; }
|
||||||
|
|
||||||
|
.PHONY: test-negative
|
||||||
|
test-negative:
|
||||||
|
@echo "Check bad file. Should error."
|
||||||
|
./compose-check.sh tests/docker-compose.bad.yml && { echo 'fail'; exit 1; } || echo 'ok'
|
||||||
|
@echo "Check multiple files. Should error."
|
||||||
|
./compose-check.sh tests/docker-compose* && { echo 'fail'; exit 1; } || echo 'ok'
|
@ -6,15 +6,16 @@ check_file() {
|
|||||||
local file=$1
|
local file=$1
|
||||||
docker-compose -f "$file" config -q 2>&1 \
|
docker-compose -f "$file" config -q 2>&1 \
|
||||||
| sed "/variable is not set. Defaulting/d"
|
| sed "/variable is not set. Defaulting/d"
|
||||||
return ${PIPESTATUS[0]}
|
return "${PIPESTATUS[0]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_files() {
|
check_files() {
|
||||||
local all_files=$@
|
local all_files=( "$@" )
|
||||||
has_error=0
|
has_error=0
|
||||||
for file in $all_files ; do
|
for file in "${all_files[@]}" ; do
|
||||||
if [[ -f "$file" ]]; then
|
if [[ -f "$file" ]]; then
|
||||||
if ! check_file "$file" ; then
|
if ! check_file "$file" ; then
|
||||||
|
echo "ERROR: $file"
|
||||||
has_error=1
|
has_error=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -22,7 +23,7 @@ check_files() {
|
|||||||
return $has_error
|
return $has_error
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! check_files $@ ; then
|
if ! check_files "$@" ; then
|
||||||
echo "To ignore, use --no-verify"
|
echo "To ignore, use --no-verify"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
1
tests/docker-compose.bad.yml
Normal file
1
tests/docker-compose.bad.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
not: valid
|
6
tests/docker-compose.yml
Normal file
6
tests/docker-compose.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
version: '2'
|
||||||
|
|
||||||
|
services:
|
||||||
|
main:
|
||||||
|
image: busybox
|
Loading…
Reference in New Issue
Block a user