diff --git a/.travis.yml b/.travis.yml index 1781ad5..80da27f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/Makefile b/Makefile index 0c3b7bf..4afa8c6 100644 --- a/Makefile +++ b/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 \ No newline at end of file + sha256sum wesher-* > wesher.sha256sums + +e2e: + tests/e2e.sh \ No newline at end of file diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000..f2d5430 --- /dev/null +++ b/tests/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/tests/e2e.sh b/tests/e2e.sh new file mode 100755 index 0000000..2261257 --- /dev/null +++ b/tests/e2e.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 '\