From 4ac0a437537890fe04c561c6f6fbb6e356a743f8 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Sat, 2 May 2015 16:22:12 -0700 Subject: [PATCH 1/3] travis: Lint all shell files. Signed-off-by: Andrea Luzzardi --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f6eb3d1e01..10da2d8099 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,8 +24,8 @@ script: - script/validate-gofmt - go vet ./... - fgt golint ./... - # Lint our test files and make sure they are not space indented. - - fgt find test -type f -exec grep -Hn -e "^ " {} \; + # Lint shell files and make sure they are not space indented. + - fgt find test/ -type f \( -name "*.sh" -or -name "*.bash" -or -name "*.bats" \) -exec grep -Hn -e "^ " {} \; - go test -v -race ./... - script/coverage - goveralls -service=travis-ci -coverprofile=goverage.report From 2600c8823b31e3394d86d9082705725b5ac316b5 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 1 May 2015 19:07:14 -0700 Subject: [PATCH 2/3] integration tests: Support for running within Docker. Signed-off-by: Andrea Luzzardi --- test/integration/Dockerfile | 33 ++++++++++++++++++++++++++ test/integration/README.md | 13 ++++++---- test/integration/run.sh | 28 ++++++++++++++++++++++ test/integration/test_runner.sh | 42 +++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 test/integration/Dockerfile create mode 100755 test/integration/run.sh create mode 100755 test/integration/test_runner.sh diff --git a/test/integration/Dockerfile b/test/integration/Dockerfile new file mode 100644 index 0000000000..81442a755b --- /dev/null +++ b/test/integration/Dockerfile @@ -0,0 +1,33 @@ +# Dockerfile for swarm integration test environment. +# Use with run_in_docker.sh + +FROM dockerswarm/dind:1.6.0 + +# Install dependencies. +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + file \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Install golang +ENV GO_VERSION 1.4.2 +RUN curl -sSL https://golang.org/dl/go${GO_VERSION}.src.tar.gz | tar -v -C /usr/local -xz \ + && mkdir -p /go/bin +ENV PATH /go/bin:/usr/local/go/bin:$PATH +ENV GOPATH /go +RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1 + +# Go dependencies +RUN go get github.com/tools/godep + +# install bats +RUN cd /usr/local/src/ \ + && git clone https://github.com/sstephenson/bats.git \ + && cd bats \ + && ./install.sh /usr/local + +RUN mkdir -p /go/src/github.com/docker/swarm +WORKDIR /go/src/github.com/docker/swarm/test/integration +ENV GOPATH /go/src/github.com/docker/swarm/Godeps/_workspace:$GOPATH + +ENTRYPOINT ["/dind"] diff --git a/test/integration/README.md b/test/integration/README.md index 10bfbd4b99..5be9affd5c 100644 --- a/test/integration/README.md +++ b/test/integration/README.md @@ -17,15 +17,20 @@ Integration tests are written in *bash* using the ## Running integration tests -Start by [installing] -(https://github.com/sstephenson/bats#installing-bats-from-source) *bats* on -your system. +The easiest way to run integration tests is with Docker: +``` +$ test/integration/run.sh +``` + +Alternatively, you can run integration tests directly on your host: -In order to run all integration tests, pass *bats* the test path: ``` $ bats test/integration ``` +In order to do that, you will need to setup a full development environmnet plus +[bats](https://github.com/sstephenson/bats#installing-bats-from-source) + > **Note**: There are known issues running the integration tests using > **devicemapper** as a storage driver, make sure that your docker daemon > is using **aufs** if you want to successfully run the integration tests. diff --git a/test/integration/run.sh b/test/integration/run.sh new file mode 100755 index 0000000000..8216e8f9c5 --- /dev/null +++ b/test/integration/run.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -e + +cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" + +# Root directory of Swarm. +SWARM_ROOT=$(cd ../..; pwd -P) + +# Image containing the integration tests environment. +INTEGRATION_IMAGE=${INTEGRATION_IMAGE:-dockerswarm/swarm-test-env} + +# Make sure we upgrade the integration environment. +#docker pull $INTEGRATION_IMAGE + +# Start the integration tests in a Docker container. +ID=$(docker run -d -t --privileged \ + -v ${SWARM_ROOT}:/go/src/github.com/docker/swarm \ + -e "DOCKER_IMAGE=$DOCKER_IMAGE" \ + -e "DOCKER_VERSION=$DOCKER_VERSION" \ + -e "STORAGE_DRIVER=$STORAGE_DRIVER" \ + -e "EXEC_DRIVER=$EXEC_DRIVER" \ + ${INTEGRATION_IMAGE} \ + ./test_runner.sh "$@") + +# Clean it up when we exit. +trap "docker rm -f -v $ID > /dev/null" EXIT + +docker logs -f $ID diff --git a/test/integration/test_runner.sh b/test/integration/test_runner.sh new file mode 100755 index 0000000000..2ec564fe30 --- /dev/null +++ b/test/integration/test_runner.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -e + +cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" + +# Load the helpers. +. helpers.bash + +function execute() { + >&2 echo "++ $@" + eval "$@" +} + +# Tests to run. Defaults to all. +TESTS=${@:-.} + +# Start the docker engine. +execute docker --daemon --log-level=panic \ + --storage-driver="$STORAGE_DRIVER" --exec-driver="$EXEC_DRIVER" & +DOCKER_PID=$! + +# Wait for it to become reachable. +tries=10 +until docker version &> /dev/null; do + (( tries-- )) + if [ $tries -le 0 ]; then + echo >&2 "error: daemon failed to start" + exit 1 + fi + sleep 1 +done + +# Pre-fetch the test image. +execute time docker pull ${DOCKER_IMAGE}:${DOCKER_VERSION} > /dev/null + +# Run the tests. +execute time bats -p $TESTS + +# Cleanup. +execute kill $DOCKER_PID +execute wait $DOCKER_PID +execute ps faxw From c236e2f11d25c70204d89086a8cb7c2da3f6c7eb Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Mon, 4 May 2015 13:59:33 -0700 Subject: [PATCH 3/3] integration runner: run tests on a fresh binary. Signed-off-by: Andrea Luzzardi --- test/integration/test_runner.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/integration/test_runner.sh b/test/integration/test_runner.sh index 2ec564fe30..c9d8a3bd75 100755 --- a/test/integration/test_runner.sh +++ b/test/integration/test_runner.sh @@ -14,6 +14,12 @@ function execute() { # Tests to run. Defaults to all. TESTS=${@:-.} +# Generate a temporary binary for the tests. +export SWARM_BINARY=`mktemp` + +# Build Swarm. +execute go build -o "$SWARM_BINARY" ../.. + # Start the docker engine. execute docker --daemon --log-level=panic \ --storage-driver="$STORAGE_DRIVER" --exec-driver="$EXEC_DRIVER" &