add end-to-end tests
This commit is contained in:
17
tests/Dockerfile
Normal file
17
tests/Dockerfile
Normal file
@ -0,0 +1,17 @@
|
||||
# pushed as costela/wesher-test to speed up testing
|
||||
|
||||
FROM golang:1.12-alpine
|
||||
|
||||
RUN apk update && apk add git make gcc
|
||||
RUN go get -d golang.zx2c4.com/wireguard \
|
||||
&& cd /go/src/golang.zx2c4.com/wireguard \
|
||||
&& rm donotuseon_linux.go \
|
||||
&& make install
|
||||
|
||||
ENV WG_I_PREFER_BUGGY_USERSPACE_TO_POLISHED_KMOD=1
|
||||
|
||||
COPY entrypoint.sh /
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
60
tests/e2e.sh
Executable file
60
tests/e2e.sh
Executable file
@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ ! -x ./wesher ]; then
|
||||
echo "Building wesher for e2e tests"
|
||||
# build inside container to ensure same libc (image is alpine-based)
|
||||
docker run --rm -v $(pwd):/app -v ${GOPATH}/pkg/mod:/go/pkg/mod --entrypoint="" costela/wesher-test go build
|
||||
fi
|
||||
|
||||
declare -A started_containers
|
||||
|
||||
cleanup() {
|
||||
if [ ! -z "${started_containers[@]}" ]; then
|
||||
echo "Stopping all remaining containers: ${started_containers[@]}"
|
||||
docker container rm -f ${started_containers[@]}
|
||||
fi
|
||||
echo "Removing shared network"
|
||||
docker network rm wesher_test
|
||||
}
|
||||
|
||||
docker network create wesher_test
|
||||
trap cleanup EXIT
|
||||
|
||||
run_test_container() {
|
||||
local name=$1
|
||||
echo "Starting $name"
|
||||
shift
|
||||
local hostname=$1
|
||||
shift
|
||||
docker run -d --cap-add=NET_ADMIN --name ${name} --hostname ${hostname} -v $(pwd):/app --network=wesher_test costela/wesher-test "$@"
|
||||
started_containers[$name]=$name
|
||||
}
|
||||
|
||||
stop_test_container() {
|
||||
echo "Stopping $1"
|
||||
docker container rm -f $1
|
||||
unset started_containers[$1]
|
||||
}
|
||||
|
||||
test_3_node_up() {
|
||||
run_test_container test1-orig test1 --init
|
||||
run_test_container test2-orig test2 --join test1-orig
|
||||
run_test_container test3-orig test3 --join test1-orig
|
||||
|
||||
sleep 3
|
||||
|
||||
docker exec test1-orig ping -c1 -W1 test2 || (docker logs test1-orig; docker logs test2-orig; false)
|
||||
docker exec test1-orig ping -c1 -W1 test3 || (docker logs test1-orig; docker logs test3-orig; false)
|
||||
|
||||
stop_test_container test3-orig
|
||||
stop_test_container test2-orig
|
||||
stop_test_container test1-orig
|
||||
}
|
||||
|
||||
for test_func in $(declare -F | grep -Eo '\<test_.*$'); do
|
||||
echo "--- Running $test_func:"
|
||||
$test_func
|
||||
echo "--- OK"
|
||||
done
|
11
tests/entrypoint.sh
Executable file
11
tests/entrypoint.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p /dev/net
|
||||
mknod /dev/net/tun c 10 200
|
||||
|
||||
wireguard-go wgoverlay
|
||||
export WESHER_E2E_TESTS=1
|
||||
|
||||
/app/wesher --log-level debug --cluster-key 'ILICZ3yBMCGAWNIq5Pn0bewBVimW3Q2yRVJ/Be+b1Uc=' "$@"
|
Reference in New Issue
Block a user