Browse Source

Add some tests and drone to run them

master v1.0.1
IamTheFij 2 years ago
parent
commit
af49bee4e5
  1. 29
      .drone.yml
  2. 21
      Makefile
  3. 9
      compose-check.sh
  4. 1
      tests/docker-compose.bad.yml
  5. 6
      tests/docker-compose.yml

29
.drone.yml

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

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

9
compose-check.sh

@ -6,15 +6,16 @@ check_file() {
local file=$1
docker-compose -f "$file" config -q 2>&1 \
| sed "/variable is not set. Defaulting/d"
return ${PIPESTATUS[0]}
return "${PIPESTATUS[0]}"
}
check_files() {
local all_files=$@
local all_files=( "$@" )
has_error=0
for file in $all_files ; do
for file in "${all_files[@]}" ; do
if [[ -f "$file" ]]; then
if ! check_file "$file" ; then
echo "ERROR: $file"
has_error=1
fi
fi
@ -22,7 +23,7 @@ check_files() {
return $has_error
}
if ! check_files $@ ; then
if ! check_files "$@" ; then
echo "To ignore, use --no-verify"
fi

1
tests/docker-compose.bad.yml

@ -0,0 +1 @@
not: valid

6
tests/docker-compose.yml

@ -0,0 +1,6 @@
---
version: '2'
services:
main:
image: busybox
Loading…
Cancel
Save