This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
2,317 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: bash | ||
sudo: required | ||
services: | ||
- docker | ||
script: | ||
- make all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
NAME = hardware/mailserver:testing | ||
|
||
all: build-no-cache init fixtures run clean | ||
all-fast: build init fixtures run clean | ||
no-build: init fixtures run clean | ||
|
||
build-no-cache: | ||
docker build --no-cache -t $(NAME) . | ||
|
||
build: | ||
docker build -t $(NAME) . | ||
|
||
init: | ||
# -docker rm -f mariadb redis mailserver_default mailserver_reverse | ||
sleep 2 | ||
|
||
docker run \ | ||
-d \ | ||
--name mariadb \ | ||
-e MYSQL_ROOT_PASSWORD=testpasswd \ | ||
-e MYSQL_DATABASE=postfix \ | ||
-e MYSQL_USER=postfix \ | ||
-e MYSQL_PASSWORD=testpasswd \ | ||
-v "`pwd`/test/config/mariadb":/docker-entrypoint-initdb.d \ | ||
-t mariadb:10.1 | ||
|
||
docker run \ | ||
-d \ | ||
--name redis \ | ||
-t redis:3.2-alpine | ||
|
||
sleep 10 | ||
|
||
docker run \ | ||
-d \ | ||
--name mailserver_default \ | ||
--link mariadb:mariadb \ | ||
--link redis:redis \ | ||
-e DBPASS=testpasswd \ | ||
-e RSPAMD_PASSWORD=testpasswd \ | ||
-e VMAILUID=`id -u` \ | ||
-e VMAILGID=`id -g` \ | ||
-e DISABLE_CLAMAV=true \ | ||
-e ADD_DOMAINS=domain2.tld,domain3.tld \ | ||
-e TESTING=true \ | ||
-v "`pwd`/test/share/tests":/tmp/tests \ | ||
-v "`pwd`/test/share/ssl":/var/mail/ssl \ | ||
-v "`pwd`/test/share/postfix":/var/mail/postfix \ | ||
-h mail.domain.tld \ | ||
-t $(NAME) | ||
|
||
docker run \ | ||
-d \ | ||
--name mailserver_reverse \ | ||
--link mariadb:mariadb \ | ||
--link redis:redis \ | ||
-e FQDN=mail.domain.tld \ | ||
-e DOMAIN=domain.tld \ | ||
-e DBPASS=testpasswd \ | ||
-e RSPAMD_PASSWORD=testpasswd \ | ||
-e VMAILUID=`id -u` \ | ||
-e VMAILGID=`id -g` \ | ||
-e VMAIL_SUBDIR=subdir \ | ||
-e RECIPIENT_DELIMITER=: \ | ||
-e RELAY_NETWORKS="192.168.0.0/16 172.16.0.0/12 10.0.0.0/8" \ | ||
-e DISABLE_CLAMAV=true \ | ||
-e DISABLE_SIEVE=true \ | ||
-e DISABLE_SIGNING=true \ | ||
-e DISABLE_GREYLISTING=true \ | ||
-e DISABLE_RATELIMITING=true \ | ||
-e ENABLE_POP3=true \ | ||
-e OPENDKIM_KEY_LENGTH=4096 \ | ||
-e TESTING=true \ | ||
-v "`pwd`/test/share/tests":/tmp/tests \ | ||
-v "`pwd`/test/share/ssl":/var/mail/ssl \ | ||
-v "`pwd`/test/share/letsencrypt":/etc/letsencrypt \ | ||
-t $(NAME) | ||
|
||
docker exec mailserver_default /bin/sh -c "apt-get update && apt-get install -y -q netcat" | ||
docker exec mailserver_reverse /bin/sh -c "apt-get update && apt-get install -y -q netcat" | ||
|
||
fixtures: | ||
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-user.txt" | ||
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-valid-user-subaddress-with-default-separator.txt" | ||
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-non-existing-user.txt" | ||
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias.txt" | ||
docker exec mailserver_default /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-spam-to-existing-user.txt" | ||
docker exec mailserver_default /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:587 -starttls smtp < /tmp/tests/email-templates/internal-user-to-existing-user.txt" | ||
|
||
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-user.txt" | ||
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-valid-user-subaddress.txt" | ||
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-non-existing-user.txt" | ||
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-to-existing-alias.txt" | ||
docker exec mailserver_reverse /bin/sh -c "nc 0.0.0.0 25 < /tmp/tests/email-templates/external-spam-to-existing-user.txt" | ||
docker exec mailserver_reverse /bin/sh -c "openssl s_client -ign_eof -connect 0.0.0.0:587 -starttls smtp < /tmp/tests/email-templates/internal-user-to-existing-user.txt" | ||
sleep 10 | ||
|
||
run: | ||
./test/bin/bats test/tests.bats | ||
|
||
clean: | ||
docker rm -f mariadb mailserver_default mailserver_reverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
version() { | ||
echo "Bats 0.4.0" | ||
} | ||
|
||
usage() { | ||
version | ||
echo "Usage: bats [-c] [-p | -t] <test> [<test> ...]" | ||
} | ||
|
||
help() { | ||
usage | ||
echo | ||
echo " <test> is the path to a Bats test file, or the path to a directory" | ||
echo " containing Bats test files." | ||
echo | ||
echo " -c, --count Count the number of test cases without running any tests" | ||
echo " -h, --help Display this help message" | ||
echo " -p, --pretty Show results in pretty format (default for terminals)" | ||
echo " -t, --tap Show results in TAP format" | ||
echo " -v, --version Display the version number" | ||
echo | ||
echo " For more information, see https://github.com/sstephenson/bats" | ||
echo | ||
} | ||
|
||
resolve_link() { | ||
$(type -p greadlink readlink | head -1) "$1" | ||
} | ||
|
||
abs_dirname() { | ||
local cwd="$(pwd)" | ||
local path="$1" | ||
|
||
while [ -n "$path" ]; do | ||
cd "${path%/*}" | ||
local name="${path##*/}" | ||
path="$(resolve_link "$name" || true)" | ||
done | ||
|
||
pwd | ||
cd "$cwd" | ||
} | ||
|
||
expand_path() { | ||
{ cd "$(dirname "$1")" 2>/dev/null | ||
local dirname="$PWD" | ||
cd "$OLDPWD" | ||
echo "$dirname/$(basename "$1")" | ||
} || echo "$1" | ||
} | ||
|
||
BATS_LIBEXEC="$(abs_dirname "$0")" | ||
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")" | ||
export BATS_CWD="$(abs_dirname .)" | ||
export PATH="$BATS_LIBEXEC:$PATH" | ||
|
||
options=() | ||
arguments=() | ||
for arg in "$@"; do | ||
if [ "${arg:0:1}" = "-" ]; then | ||
if [ "${arg:1:1}" = "-" ]; then | ||
options[${#options[*]}]="${arg:2}" | ||
else | ||
index=1 | ||
while option="${arg:$index:1}"; do | ||
[ -n "$option" ] || break | ||
options[${#options[*]}]="$option" | ||
let index+=1 | ||
done | ||
fi | ||
else | ||
arguments[${#arguments[*]}]="$arg" | ||
fi | ||
done | ||
|
||
unset count_flag pretty | ||
[ -t 0 ] && [ -t 1 ] && pretty="1" | ||
[ -n "$CI" ] && pretty="" | ||
|
||
for option in "${options[@]}"; do | ||
case "$option" in | ||
"h" | "help" ) | ||
help | ||
exit 0 | ||
;; | ||
"v" | "version" ) | ||
version | ||
exit 0 | ||
;; | ||
"c" | "count" ) | ||
count_flag="-c" | ||
;; | ||
"t" | "tap" ) | ||
pretty="" | ||
;; | ||
"p" | "pretty" ) | ||
pretty="1" | ||
;; | ||
* ) | ||
usage >&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [ "${#arguments[@]}" -eq 0 ]; then | ||
usage >&2 | ||
exit 1 | ||
fi | ||
|
||
filenames=() | ||
for filename in "${arguments[@]}"; do | ||
if [ -d "$filename" ]; then | ||
shopt -s nullglob | ||
for suite_filename in "$(expand_path "$filename")"/*.bats; do | ||
filenames["${#filenames[@]}"]="$suite_filename" | ||
done | ||
shopt -u nullglob | ||
else | ||
filenames["${#filenames[@]}"]="$(expand_path "$filename")" | ||
fi | ||
done | ||
|
||
if [ "${#filenames[@]}" -eq 1 ]; then | ||
command="bats-exec-test" | ||
else | ||
command="bats-exec-suite" | ||
fi | ||
|
||
if [ -n "$pretty" ]; then | ||
extended_syntax_flag="-x" | ||
formatter="bats-format-tap-stream" | ||
else | ||
extended_syntax_flag="" | ||
formatter="cat" | ||
fi | ||
|
||
set -o pipefail execfail | ||
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
count_only_flag="" | ||
if [ "$1" = "-c" ]; then | ||
count_only_flag=1 | ||
shift | ||
fi | ||
|
||
extended_syntax_flag="" | ||
if [ "$1" = "-x" ]; then | ||
extended_syntax_flag="-x" | ||
shift | ||
fi | ||
|
||
trap "kill 0; exit 1" int | ||
|
||
count=0 | ||
for filename in "$@"; do | ||
let count+="$(bats-exec-test -c "$filename")" | ||
done | ||
|
||
if [ -n "$count_only_flag" ]; then | ||
echo "$count" | ||
exit | ||
fi | ||
|
||
echo "1..$count" | ||
status=0 | ||
offset=0 | ||
for filename in "$@"; do | ||
index=0 | ||
{ | ||
IFS= read -r # 1..n | ||
while IFS= read -r line; do | ||
case "$line" in | ||
"begin "* ) | ||
let index+=1 | ||
echo "${line/ $index / $(($offset + $index)) }" | ||
;; | ||
"ok "* | "not ok "* ) | ||
[ -n "$extended_syntax_flag" ] || let index+=1 | ||
echo "${line/ $index / $(($offset + $index)) }" | ||
[ "${line:0:6}" != "not ok" ] || status=1 | ||
;; | ||
* ) | ||
echo "$line" | ||
;; | ||
esac | ||
done | ||
} < <( bats-exec-test $extended_syntax_flag "$filename" ) | ||
offset=$(($offset + $index)) | ||
done | ||
|
||
exit "$status" |
Oops, something went wrong.