From 08c6669473a73fc81ff732edb4c1939b84ac7239 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Wed, 16 Mar 2016 15:55:57 -0700 Subject: [PATCH] Add integration tests that build the docker images and the client binary Signed-off-by: Ying Li --- .build/integrationtest.sh | 39 +++++++++++++++++++++++++++++ .build/testclient.sh | 52 +++++++++++++++++++++++++++++++++++++++ Makefile | 3 +++ circle.yml | 5 +++- 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100755 .build/integrationtest.sh create mode 100755 .build/testclient.sh diff --git a/.build/integrationtest.sh b/.build/integrationtest.sh new file mode 100755 index 0000000000..9f73eec2b4 --- /dev/null +++ b/.build/integrationtest.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + + + +set -e +set -x + +function finish { + docker-compose stop + if [[ -n "${COMPOSE_PID}" ]]; then + kill "${COMPOSE_PID}" || true + fi + if [[ -n "${TEST_PID}" ]]; then + kill "${TEST_PID}" || true + fi +} + +docker-compose stop + +# if we're in CircleCI, we cannot remove any containers +if [[ -z "${CIRCLECI}" ]]; then + docker-compose rm -f +fi + +docker-compose build +docker-compose up --abort-on-container-exit >> /dev/null & +COMPOSE_PID=$! + + +.build/testclient.sh & +TEST_PID=$! + +set +x + +wait ${TEST_PID} + +(docker-compose logs &) + +trap finish SIGINT SIGTERM EXIT diff --git a/.build/testclient.sh b/.build/testclient.sh new file mode 100755 index 0000000000..d60c396670 --- /dev/null +++ b/.build/testclient.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +set -e + +RANDOMSTRING="$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)" +HOST="${REMOTE_SERVER_URL:-https://localhost:4443}" + +OPTS="-c cmd/notary/config.json -d /tmp/${RANDOMSTRING}" +if [[ -n "${DOCKER_HOST}" ]]; then + if [[ "$(resolveip -s notary-server)" == *"${DOCKER_HOST}"* ]]; then + echo "This test is going to fail since the client doesn't have a trusted CA root for ${HOST}" + exit 1 + fi + HOST="${REMOTE_SERVER_URL:-https://notary-server:4443}" + OPTS="$OPTS -s ${HOST}" +fi + +REPONAME="docker.com/notary/${RANDOMSTRING}" + +export NOTARY_ROOT_PASSPHRASE=ponies +export NOTARY_TARGETS_PASSPHRASE=ponies +export NOTARY_SNAPSHOT_PASSPHRASE=ponies + +echo "Notary Host: ${HOST}" +echo "Repo Name: ${REPONAME}" + +echo + +rm -rf "/tmp/${RANDOMSTRING}" + +iter=0 +until curl -k "${HOST}" +do + ((iter++)) + if (( iter > 30 )); then + echo "notary service failed to come up within 30 seconds" + exit 1; + fi + echo "waiting for notary service to come up." + sleep 1 +done + +set -x + +make client + +bin/notary ${OPTS} init ${REPONAME} +bin/notary ${OPTS} delegation add ${REPONAME} targets/releases fixtures/secure.example.com.crt --all-paths +bin/notary ${OPTS} add ${REPONAME} readmetarget README.md +bin/notary ${OPTS} publish ${REPONAME} +bin/notary ${OPTS} delegation list ${REPONAME} | grep targets/releases +cat README.md | bin/notary ${OPTS} verify $REPONAME readmetarget > /dev/null diff --git a/Makefile b/Makefile index a818dc5b85..2b500bbc5a 100644 --- a/Makefile +++ b/Makefile @@ -125,6 +125,9 @@ test-full: vet lint @echo go test -tags "${NOTARY_BUILDTAGS}" $(TESTOPTS) -v $(PKGS) +integration: + .build/integrationtest.sh + protos: @protoc --go_out=plugins=grpc:. proto/*.proto diff --git a/circle.yml b/circle.yml index 6b98a161f1..58dc98aa96 100644 --- a/circle.yml +++ b/circle.yml @@ -8,6 +8,9 @@ machine: # Install many go versions - gvm install go1.6 -B --name=stable + services: + - docker + environment: # Convenient shortcuts to "common" locations CHECKOUT: /home/ubuntu/$CIRCLE_PROJECT_REPONAME @@ -70,7 +73,7 @@ test: override: # Test stable, and report # hacking this to be parallel - - case $CIRCLE_NODE_INDEX in 0) gvm use stable && NOTARY_BUILDTAGS=pkcs11 make ci ;; 1) gvm use stable && NOTARY_BUILDTAGS=none make ci ;; esac: + - case $CIRCLE_NODE_INDEX in 0) gvm use stable && NOTARY_BUILDTAGS=pkcs11 make ci ;; 1) gvm use stable && NOTARY_BUILDTAGS=none make ci ;; 2) gvm use stable && make integration ;; esac: parallel: true timeout: 600 pwd: $BASE_STABLE