Skip to content

Commit

Permalink
Merge pull request #92 from HumorBaby/fix-refactor-tests
Browse files Browse the repository at this point in the history
Fix broken CI testing, including from `conf.d`
  • Loading branch information
SISheogorath authored Aug 8, 2019
2 parents 446ac31 + a457e8b commit aa148ab
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .dockerfilelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rules:
from_first: off
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ script:
# Initial build with default parameters
- docker build --build-arg VERSION="${INSP_VERSION}" -t inspircd:testing .
# Run all tests from test directory
- for file in tests/*.sh; do $file; done
- ./run_tests.sh

after_success:
# Push successful builds of the master branch to Docker Hub
Expand Down
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ USER inspircd
EXPOSE 6667 6697 7000 7001

WORKDIR /
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]

HEALTHCHECK \
--interval=1s \
--timeout=3s \
--start-period=60s \
--retries=3 \
CMD \
/usr/bin/nc -z localhost 6667
6 changes: 3 additions & 3 deletions conf/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ cat <<EOF
EOF

# Include custom configurations if conf.d exists
if [ -d conf.d ]; then
find conf.d/*.conf | while read -r file; do echo "<include file=\"$file\">"; done
if [ -d "${INSPIRCD_ROOT}"/conf.d ]; then
find "${INSPIRCD_ROOT}"/conf.d -name '*.conf' | while read -r file; do echo "<include file=\"$file\">"; done
fi

# Include custom configurations from docker secrets. (For example for further oper configs)
if [ -d /run/secrets ]; then
find /run/secrets/*.conf | while read -r file; do echo "<include file=\"$file\">"; done
find /run/secrets -name '*.conf' | while read -r file; do echo "<include file=\"$file\">"; done
fi

# Space for further configs
9 changes: 7 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ time_stamping_key
EOF
/usr/bin/certtool --generate-privkey --bits 4096 --sec-param normal --outfile $INSPIRCD_ROOT/conf/key.pem
/usr/bin/certtool --generate-self-signed --load-privkey $INSPIRCD_ROOT/conf/key.pem --outfile $INSPIRCD_ROOT/conf/cert.pem --template /tmp/cert.template
/usr/bin/certtool --generate-dh-params --sec-param normal --outfile $INSPIRCD_ROOT/conf/dhparams.pem
rm /tmp/cert.template
fi

exec $INSPIRCD_ROOT/bin/inspircd --nofork $@
# Make sure dhparams are present
if [ ! -e $INSPIRCD_ROOT/conf/dhparams.pem ]; then
/usr/bin/certtool --generate-dh-params --sec-param normal --outfile $INSPIRCD_ROOT/conf/dhparams.pem
fi

cd $INSPIRCD_ROOT
exec env INSPIRCD_ROOT=$INSPIRCD_ROOT $INSPIRCD_ROOT/bin/inspircd --nofork $@
47 changes: 47 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

export INSP_VERSION

clean_up() {
local ret_val="$?"

# Clean up any remaining containers (e.g., due to fast-failing test)
local inspircd_containers="$(docker ps -q -a -f "ancestor=inspircd:testing")"
if [[ -n "${inspircd_containers}" ]]; then
docker rm -fv ${inspircd_containers}
fi

# Exit with ultimate exit code
exit "${ret_val}"
}
trap clean_up EXIT

# Make sure test-tracking file exists
touch ok_tests.txt
pad=$(printf '.%.0s' {1..100})

for test_file in tests/*.sh; do
printf "%.35s " "${test_file} ${pad}"

# Check if test already passed.
grep -w -q "$(sha1sum "${test_file}")" ok_tests.txt \
&& { printf "0 ( OK )\n"; continue; } \
|| true

# Run test, capturing all output to log variable
test_log=$(sh "${test_file}" 2>&1)
[[ $? -eq 0 ]] \
&& {
echo "0 ( OK )"
sha1sum "${test_file}" >> ok_tests.txt
} \
|| {
ret=$?
echo "${ret} (FAIL)"
# Print full output of test script
echo "${test_log}"
exit ${ret}
}
done
# Remove test-tracking cache on successful tests.
rm ok_tests.txt
2 changes: 1 addition & 1 deletion tests/customBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mkdir -p "$TESTDIR"

cp -r . "$TESTDIR"

wget -O "$TESTDIR/modules/m_timedstaticquit.cpp" "https://raw.githubusercontent.com/inspircd/inspircd-extras/master/3.0/m_timedstaticquit.cpp"
wget -O "$TESTDIR/modules/m_timedstaticquit.cpp" "https://raw.githubusercontent.com/inspircd/inspircd-contrib/master/3.0/m_timedstaticquit.cpp"

[ ! -e "$TESTDIR/modules/m_timedstaticquit.cpp" ] && sleep 10

Expand Down
2 changes: 1 addition & 1 deletion tests/extras.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set -e
TESTMODULE="m_svsoper"

# Create directory for testing
mkdir /tmp/test-extras/
mkdir -p /tmp/test-extras/

docker build --build-arg EXTRASMODULES="$TESTMODULE" .

Expand Down
4 changes: 2 additions & 2 deletions tests/linking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ set -e
DOCKERNETWORK=$(docker network create linkingTestNet)

# Run first instance of InspIRCd to connect to.
DOCKERCONTAINER1=$(docker run -d --name test1 --network linkingTestNet -e INSP_SERVER_NAME="test1.example.com" -e INSP_LINK1_NAME="test2.example.com" -e INSP_LINK1_PASSWORD="test" -e INSP_LINK1_IPADDR="test2" inspircd:testing)
DOCKERCONTAINER1=$(docker run -d --name test1 --network linkingTestNet -e INSP_SERVER_NAME="test1.example.com" -e INSP_LINK1_NAME="test2.example.com" -e INSP_LINK1_PASSWORD="test" -e INSP_LINK1_IPADDR="test2" inspircd:testing --debug)

sleep 5

# Run seconds InspIRCd instance
DOCKERCONTAINER2=$(docker run -d --name test2 --network linkingTestNet -e INSP_SERVER_NAME="test2.example.com" -e INSP_LINK1_NAME="test1.example.com" -e INSP_LINK1_PASSWORD="test" -e INSP_LINK1_IPADDR="test1" inspircd:testing)
DOCKERCONTAINER2=$(docker run -d --name test2 --network linkingTestNet -e INSP_SERVER_NAME="test2.example.com" -e INSP_LINK1_NAME="test1.example.com" -e INSP_LINK1_PASSWORD="test" -e INSP_LINK1_IPADDR="test1" inspircd:testing --debug)

sleep 10

Expand Down
2 changes: 1 addition & 1 deletion tests/mountConfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -e
. "$(dirname "$0")/.portconfig.sh"

# Create config directory for testing
mkdir /tmp/test-mountConfig/ && sudo chown 10000 /tmp/test-mountConfig/
mkdir -p /tmp/test-mountConfig/ && sudo chown 10000 /tmp/test-mountConfig/

# Create docker container with our test parameters
DOCKERCONTAINER=$(docker run -d -v /tmp/test-mountConfig/:/inspircd/conf -p "127.0.0.1:${CLIENT_PORT}:6667" -p "127.0.0.1:${TLS_CLIENT_PORT}:6697" inspircd:testing)
Expand Down
2 changes: 1 addition & 1 deletion tests/secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SECRETKEY=$(docker secret create test-secrets-key /tmp/test-secrets-key.pem)
DOCKERSERVICE=$(docker service create -q -d -p "${CLIENT_PORT}:6667" -p "${TLS_CLIENT_PORT}:6697" --secret source=test-secrets-key,target=inspircd.key --secret source=test-secrets-cert,target=inspircd.crt inspircd:testing)
sleep 35
# Make sure TLS is working
TLSCHECK=$(echo quit | timeout 10 openssl s_client -ign_eof -connect "localhost:${TLS_CLIENT_PORT}" 2>/dev/null | grep -c "OU=Secret Server Admins")
TLSCHECK=$(echo quit | timeout 10 openssl s_client -ign_eof -connect "localhost:${TLS_CLIENT_PORT}" 2>/dev/null | grep -c "OU\s*=\s*Secret Server Admins")
[ "$TLSCHECK" -gt 0 ] || exit 1

sleep 5
Expand Down

0 comments on commit aa148ab

Please sign in to comment.