mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
306592fcad
`tls.bash` helper was adapted to the new helper scripts location. The `setup.bash` helper saw a bugfix (expanding the array properly) and updates the container default config to configure for IPv4 explicitly. The IPv4 default was added after recent Docker pushes and I saw weird IPv6 related errors in the logs.. now we're sure IPv4 is the default during tests. Added functionality to check if a process is running: - This change adds a helper function to check whether a program is running inside a container or not. - This added the need for a function like `_run_in_container` but allowing for providing an explicit container name. - Future PRs can use this helper function now to check whether a process is running or not. This was done for the tests of Fail2Ban, but can be used for other tests in the future as well. --- chore: Restructured BATS flags in `Makefile` The `Makefile` has seen a bit of a restructuring when it comes to flags: 1. The `MAKEFLAGS` variables is used by `make`, and allows for adding additional flags that can be used within in recursive calls (via `$(MAKE)`) too, thus DRY approach. 2. The flags for calling BATS were adjusted. `--no-parallelize-within-files` has been added as well to ensure tests _inside_ a single file are run sequentially. `dms-test` prefix matching changed to expect a `_` suffix as a delimiter. --- docs: Add a note regarding output from running tests in parallel
75 lines
2.7 KiB
Makefile
75 lines
2.7 KiB
Makefile
SHELL := /bin/bash
|
|
.SHELLFLAGS += -e -u -o pipefail
|
|
|
|
export REPOSITORY_ROOT := $(CURDIR)
|
|
export IMAGE_NAME ?= mailserver-testing:ci
|
|
export NAME ?= $(IMAGE_NAME)
|
|
|
|
MAKEFLAGS += --no-print-directory
|
|
BATS_FLAGS ?= --timing
|
|
BATS_PARALLEL_JOBS ?= 2
|
|
BATS_FLAGS_PARALLEL ?= $(BATS_FLAGS) --no-parallelize-within-files --jobs $(BATS_PARALLEL_JOBS)
|
|
|
|
.PHONY: ALWAYS_RUN
|
|
|
|
# -----------------------------------------------
|
|
# --- Generic Targets ---------------------------
|
|
# -----------------------------------------------
|
|
|
|
all: lint build backup generate-accounts tests clean
|
|
|
|
build:
|
|
@ DOCKER_BUILDKIT=1 docker build \
|
|
--tag $(IMAGE_NAME) \
|
|
--build-arg VCS_VERSION=$(shell git rev-parse --short HEAD) \
|
|
--build-arg VCS_REVISION=$(shell cat VERSION) \
|
|
.
|
|
|
|
generate-accounts: ALWAYS_RUN
|
|
@ cp test/config/templates/postfix-accounts.cf test/config/postfix-accounts.cf
|
|
@ cp test/config/templates/dovecot-masters.cf test/config/dovecot-masters.cf
|
|
|
|
backup:
|
|
# if backup directory exist, clean hasn't been called, therefore
|
|
# we shouldn't overwrite it. It still contains the original content.
|
|
-@ [[ ! -d testconfig.bak ]] && cp -rp test/config testconfig.bak || :
|
|
|
|
clean:
|
|
# remove test containers and restore test/config directory
|
|
-@ [[ -d testconfig.bak ]] && { sudo rm -rf test/config ; mv testconfig.bak test/config ; } || :
|
|
-@ for CONTAINER in $$(docker ps -a --filter name='^dms-test_.*|^mail_.*|^hadolint$$|^eclint$$|^shellcheck$$' | sed 1d | cut -f 1-1 -d ' '); do docker rm -f $${CONTAINER}; done
|
|
-@ while read -r LINE; do [[ $${LINE} =~ test/.+ ]] && sudo rm -rf $${LINE}; done < .gitignore
|
|
|
|
# -----------------------------------------------
|
|
# --- Tests ------------------------------------
|
|
# -----------------------------------------------
|
|
|
|
tests: ALWAYS_RUN
|
|
# See https://github.com/docker-mailserver/docker-mailserver/pull/2857#issuecomment-1312724303
|
|
# on why `generate-accounts` is run before each set (TODO/FIXME)
|
|
@ for DIR in tests/{serial,parallel/set{1,2,3}} ; do $(MAKE) generate-accounts "$${DIR}" ; done
|
|
|
|
tests/serial: ALWAYS_RUN
|
|
@ shopt -s globstar ; ./test/bats/bin/bats $(BATS_FLAGS) test/$@/*.bats
|
|
|
|
tests/parallel/set%: ALWAYS_RUN
|
|
@ shopt -s globstar ; ./test/bats/bin/bats $(BATS_FLAGS_PARALLEL) test/$@/**/*.bats
|
|
|
|
test/%: ALWAYS_RUN
|
|
@ shopt -s globstar nullglob ; ./test/bats/bin/bats $(BATS_FLAGS) test/tests/**/{$*,}.bats
|
|
|
|
# -----------------------------------------------
|
|
# --- Lints -------------------------------------
|
|
# -----------------------------------------------
|
|
|
|
lint: eclint hadolint shellcheck
|
|
|
|
hadolint:
|
|
@ ./test/linting/lint.sh hadolint
|
|
|
|
shellcheck:
|
|
@ ./test/linting/lint.sh shellcheck
|
|
|
|
eclint:
|
|
@ ./test/linting/lint.sh eclint
|