add end-to-end tests
This commit is contained in:
parent
f4e61df211
commit
c2d7929f4a
|
@ -10,6 +10,9 @@ go:
|
|||
os:
|
||||
- linux
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- go: "master"
|
||||
|
@ -35,9 +38,11 @@ jobs:
|
|||
include:
|
||||
- stage: cache
|
||||
script: go mod download -json
|
||||
- stage: test
|
||||
script: make e2e
|
||||
- stage: release
|
||||
script: make
|
||||
go: "1.12.1"
|
||||
script: make build
|
||||
go: "1.12.1" # explicit version to ease reproducibility
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
|
|
5
Makefile
5
Makefile
|
@ -6,4 +6,7 @@ build:
|
|||
GOARCH=amd64 go build ${GOFLAGS} -o wesher-amd64 ${OPTS}
|
||||
GOARCH=arm go build ${GOFLAGS} -o wesher-arm ${OPTS}
|
||||
GOARCH=arm64 go build ${GOFLAGS} -o wesher-arm64 ${OPTS}
|
||||
sha256sum wesher-* > wesher.sha256sums
|
||||
sha256sum wesher-* > wesher.sha256sums
|
||||
|
||||
e2e:
|
||||
tests/e2e.sh
|
|
@ -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" ]
|
|
@ -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
|
|
@ -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=' "$@"
|
Loading…
Reference in New Issue