Skip to content

Commit

Permalink
Merge branch 'fix-tests' into 'master'
Browse files Browse the repository at this point in the history
Use the latest run.sh to get the tests back up and running

See merge request ix.ai/openvpn!24
  • Loading branch information
tlex committed Mar 15, 2021
2 parents 8c0c434 + 9bc2770 commit 79398af
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
variables:
ENABLE_ARM64: 'true'
ENABLE_ARMv7: 'true'
Expand Down
154 changes: 115 additions & 39 deletions test/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
#!/usr/bin/env bash
set -Eeuo pipefail

dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"

Expand All @@ -9,7 +9,7 @@ usage() {
cat <<EOUSAGE
usage: $self [-t test ...] image:tag [...]
ie: $self debian:wheezy
ie: $self debian:stretch
$self -t utc python:3
$self -t utc python:3 -t python-hy
Expand All @@ -19,12 +19,13 @@ EOUSAGE
}

# arg handling
opts="$(getopt -o 'ht:c:?' --long 'dry-run,help,test:,config:' -- "$@" || { usage >&2 && false; })"
opts="$(getopt -o 'ht:c:?' --long 'dry-run,help,test:,config:,keep-namespace' -- "$@" || { usage >&2 && false; })"
eval set -- "$opts"

declare -A argTests=()
declare -a configs=()
dryRun=
keepNamespace=
while true; do
flag=$1
shift
Expand All @@ -33,6 +34,7 @@ while true; do
--help|-h|'-?') usage && exit 0 ;;
--test|-t) argTests["$1"]=1 && shift ;;
--config|-c) configs+=("$(readlink -f "$1")") && shift ;;
--keep-namespace) keepNamespace=1 ;;
--) break ;;
*)
{
Expand All @@ -44,7 +46,7 @@ while true; do
esac
done

if [ $# -eq 0 ]; then
if [ "$#" -eq 0 ]; then
usage >&2
exit 1
fi
Expand All @@ -57,10 +59,21 @@ declare -A globalExcludeTests=()
declare -A explicitTests=()

# if there are no user-specified configs, use the default config
if [ ${#configs} -eq 0 ]; then
configs+=("$dir/config.sh")
if [ "${#configs[@]}" -eq 0 ]; then
configs+=( "$dir/config.sh" )
fi

case "$(uname -o)" in
Msys)
# https://stackoverflow.com/a/34386471/433558
# https://github.com/docker/toolbox/blob/6960f28d5b01857d69b2095a02949264f09d3e57/windows/start.sh#L104-L107
docker() {
MSYS_NO_PATHCONV=1 command docker "$@"
}
export -f docker
;;
esac

# load the configs
declare -A testPaths=()
for conf in "${configs[@]}"; do
Expand All @@ -70,7 +83,7 @@ for conf in "${configs[@]}"; do
confDir="$(dirname "$conf")"

for testName in ${globalTests[@]} ${imageTests[@]}; do
[ "${testPaths[$testName]}" ] && continue
[ -n "${testPaths[$testName]:-}" ] && continue

if [ -d "$confDir/tests/$testName" ]; then
# Test directory found relative to the conf file
Expand All @@ -86,69 +99,118 @@ didFail=
for dockerImage in "$@"; do
echo "testing $dockerImage"

if ! docker inspect "$dockerImage" &> /dev/null; then
echo $'\timage does not exist!'
didFail=1
continue
fi

repo="${dockerImage%:*}"
tagVar="${dockerImage#*:}"
#version="${tagVar%-*}"
variant="${tagVar##*-}"

testRepo=$repo
[ -z "${testAlias[$repo]}" ] || testRepo="${testAlias[$repo]}"
case "$tagVar" in
*onbuild*)
# "maven:onbuild-alpine" is still onbuild
# ONCE ONBUILD, ALWAYS ONBUILD
variant='onbuild'
;;
*apache-*)
# lolPHP
variant='apache'
;;
*fpm-*)
# lolPHP
variant='fpm'
;;
*alpine*)
# "alpine3.4", "alpine3.6", "nginx:alpine-perl", etc are still "alpine" variants
variant='alpine'
;;
slim-*|*-slim-*)
# "slim-jessie" is still "slim"
variant='slim'
;;
psmdb-*)
# Percona Server for MongoDB is still "mongo"
variant='psmdb'
;;
*nanoserver*)
# all nanoserver variants are windows
variant='nanoserver'
;;
*windowsservercore*)
# all servercore variants are windows
variant='windowsservercore'
;;
esac

explicitVariant=
if [ \
"${explicitTests[:$variant]}" \
-o "${explicitTests[$repo:$variant]}" \
-o "${explicitTests[$testRepo:$variant]}" \
]; then
explicitVariant=1
testRepo="$repo"
if [ -z "$keepNamespace" ]; then
testRepo="${testRepo##*/}"
fi

for possibleAlias in \
"${testAlias[$repo:$variant]:-}" \
"${testAlias[$repo]:-}" \
"${testAlias[$testRepo:$variant]:-}" \
"${testAlias[$testRepo]:-}" \
; do
if [ -n "$possibleAlias" ]; then
testRepo="$possibleAlias"
break
fi
done

explicitVariant=
for possibleExplicit in \
"${explicitTests[:$variant]:-}" \
"${explicitTests[$repo:$variant]:-}" \
"${explicitTests[$repo]:-}" \
"${explicitTests[$testRepo:$variant]:-}" \
"${explicitTests[$testRepo]:-}" \
; do
if [ -n "$possibleExplicit" ]; then
explicitVariant=1
break
fi
done

testCandidates=()
if [ -z "$explicitVariant" ]; then
testCandidates+=( "${globalTests[@]}" )
fi
testCandidates+=(
${imageTests[:$variant]}
${imageTests[:$variant]:-}
)
if [ -z "$explicitVariant" ]; then
testCandidates+=(
${imageTests[$testRepo]}
${imageTests[$testRepo]:-}
)
fi
testCandidates+=(
${imageTests[$testRepo:$variant]}
${imageTests[$testRepo:$variant]:-}
)
if [ "$testRepo" != "$repo" ]; then
if [ -z "$explicitVariant" ]; then
testCandidates+=(
${imageTests[$repo]}
${imageTests[$repo]:-}
)
fi
testCandidates+=(
${imageTests[$repo:$variant]}
${imageTests[$repo:$variant]:-}
)
fi

tests=()
for t in "${testCandidates[@]}"; do
if [ ${#argTests[@]} -gt 0 -a -z "${argTests[$t]}" ]; then
if [ "${#argTests[@]}" -gt 0 ] && [ -z "${argTests[$t]:-}" ]; then
# skipping due to -t
continue
fi

if [ \
! -z "${globalExcludeTests[${testRepo}_$t]}" \
-o ! -z "${globalExcludeTests[${testRepo}:${variant}_$t]}" \
-o ! -z "${globalExcludeTests[:${variant}_$t]}" \
-o ! -z "${globalExcludeTests[${repo}_$t]}" \
-o ! -z "${globalExcludeTests[${repo}:${variant}_$t]}" \
-o ! -z "${globalExcludeTests[:${variant}_$t]}" \
! -z "${globalExcludeTests[${testRepo}_$t]:-}" \
-o ! -z "${globalExcludeTests[${testRepo}:${variant}_$t]:-}" \
-o ! -z "${globalExcludeTests[:${variant}_$t]:-}" \
-o ! -z "${globalExcludeTests[${repo}_$t]:-}" \
-o ! -z "${globalExcludeTests[${repo}:${variant}_$t]:-}" \
-o ! -z "${globalExcludeTests[:${variant}_$t]:-}" \
]; then
# skipping due to exclude
continue
Expand All @@ -157,6 +219,19 @@ for dockerImage in "$@"; do
tests+=( "$t" )
done

# check for zero tests before checking for existing image
# this will make windows variants no longer fail
if [ "${#tests[@]}" -eq '0' ]; then
echo $'\timage has no tests...skipping'
continue
fi

if ! docker inspect "$dockerImage" &> /dev/null; then
echo $'\timage does not exist!'
didFail=1
continue
fi

currentTest=0
totalTest="${#tests[@]}"
for t in "${tests[@]}"; do
Expand All @@ -168,10 +243,11 @@ for dockerImage in "$@"; do
scriptDir="${testPaths[$t]}"
if [ -d "$scriptDir" ]; then
script="$scriptDir/run.sh"
if [ -x "$script" -a ! -d "$script" ]; then
if [ -x "$script" ] && [ ! -d "$script" ]; then
# TODO dryRun logic
if output="$("$script" $dockerImage)"; then
if [ -f "$scriptDir/expected-std-out.txt" ] && ! d="$(echo "$output" | diff -u "$scriptDir/expected-std-out.txt" - 2>/dev/null)"; then
if output="$("$script" "$dockerImage")"; then
output="$(tr -d '\r' <<<"$output")" # Windows gives us \r\n ... :D
if [ -f "$scriptDir/expected-std-out.txt" ] && ! d="$(diff -u "$scriptDir/expected-std-out.txt" - <<<"$output" 2>/dev/null)"; then
echo 'failed; unexpected output:'
echo "$d"
didFail=1
Expand All @@ -197,6 +273,6 @@ for dockerImage in "$@"; do
done
done

if [ "$didFail" ]; then
if [ -n "$didFail" ]; then
exit 1
fi
2 changes: 1 addition & 1 deletion test/tests/revocation/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test -n "${ACTUAL_SERV_IP}" || false
# Test that easy_rsa generate CRLs with 'next publish' set to 3650 days.
#
DATE="$(docker exec $NAME openssl crl -nextupdate -noout -in /etc/openvpn/crl.pem)"
crl_next_update="$(echo ${DATE} | cut -d'=' -f2 | tr -d 'GMT' | xargs)"
crl_next_update="$(echo ${DATE} | cut -d'=' -f2 | sed 's/GMT//g' | xargs)"
crl_next_update="$(date -u -d "$crl_next_update" "+%s")"
now="$(docker exec $NAME date "+%s")"
crl_remain="$(( $crl_next_update - $now ))"
Expand Down

0 comments on commit 79398af

Please sign in to comment.