Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set rethink and mysql server DB storage tests to run on circle #824

Merged
merged 8 commits into from
Jul 19, 2016
58 changes: 20 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ COVERPROFILE?=$(COVERDIR)/cover.out
COVERMODE=count
PKGS ?= $(shell go list -tags "${NOTARY_BUILDTAGS}" ./... | grep -v /vendor/ | tr '\n' ' ')

.PHONY: clean all fmt vet lint build test binaries cross cover docker-images notary-dockerfile
.PHONY: clean all lint build test binaries cross cover docker-images notary-dockerfile
.DELETE_ON_ERROR: cover
.DEFAULT: default

all: AUTHORS clean fmt vet fmt lint build test binaries
all: AUTHORS clean lint build test binaries

AUTHORS: .git/HEAD
git log --format='%aN <%aE>' | sort -fu > $@
Expand Down Expand Up @@ -90,41 +90,26 @@ ${PREFIX}/bin/static/notary:
@go build -tags ${NOTARY_BUILDTAGS} -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary
endif

vet:
@echo "+ $@"

# run all lint functionality - excludes Godep directory, vendoring, binaries, python tests, and git files
lint:
@echo "+ $@: golint, go vet, go fmt, misspell, ineffassign"
# golint
@test -z "$(shell find . -type f -name "*.go" -not -path "./vendor/*" -not -name "*.pb.*" -exec golint {} \; | tee /dev/stderr)"
# gofmt
@test -z "$$(gofmt -s -l .| grep -v .pb. | grep -v vendor/ | tee /dev/stderr)"
# govet
ifeq ($(shell uname -s), Darwin)
@test -z "$(shell find . -iname *test*.go | grep -v _test.go | grep -v vendor | xargs echo "This file should end with '_test':" | tee /dev/stderr)"
else
@test -z "$(shell find . -iname *test*.go | grep -v _test.go | grep -v vendor | xargs -r echo "This file should end with '_test':" | tee /dev/stderr)"
endif
@test -z "$$(go tool vet -printf=false . 2>&1 | grep -v vendor/ | tee /dev/stderr)"

fmt:
@echo "+ $@"
@test -z "$$(gofmt -s -l .| grep -v .pb. | grep -v vendor/ | tee /dev/stderr)"

lint:
@echo "+ $@"
@test -z "$(shell find . -type f -name "*.go" -not -path "./vendor/*" -not -name "*.pb.*" -exec golint {} \; | tee /dev/stderr)"

# Requires that the following:
# go get -u github.com/client9/misspell/cmd/misspell
#
# be run first

# misspell target, don't include Godeps, binaries, python tests, or git files
misspell:
@echo "+ $@"
# misspell - requires that the following be run first:
# go get -u github.com/client9/misspell/cmd/misspell
@test -z "$$(find . -name '*' | grep -v vendor/ | grep -v bin/ | grep -v misc/ | grep -v .git/ | xargs misspell | tee /dev/stderr)"

# Requires that the following:
# go get -u github.com/gordonklaus/ineffassign
#
# be run first

# ineffassign target, don't include Godeps, binaries, python tests, or git files
ineffassign:
@echo "+ $@"
# ineffassign - requires that the following be run first:
# go get -u github.com/gordonklaus/ineffassign
@test -z "$(shell find . -type f -name "*.go" -not -path "./vendor/*" -not -name "*.pb.*" -exec ineffassign {} \; | tee /dev/stderr)"

build:
Expand All @@ -140,16 +125,13 @@ test:
@echo
go test -tags "${NOTARY_BUILDTAGS}" $(TESTOPTS) $(PKGS)

test-full: TESTOPTS =
test-full: vet lint
@echo Note: when testing with a yubikey plugged in, make sure to include 'TESTOPTS="-p 1"'
@echo "+ $@"
@echo
go test -tags "${NOTARY_BUILDTAGS}" $(TESTOPTS) -v $(PKGS)

integration: TESTDB = mysql
integration:
buildscripts/integrationtest.sh development.$(TESTDB).yml
buildscripts/integrationtest.sh $(TESTDB)

testdb: TESTDB = mysql
testdb:
buildscripts/dbtests.sh $(TESTDB)

protos:
@protoc --go_out=plugins=grpc:. proto/*.proto
Expand Down
8 changes: 5 additions & 3 deletions buildscripts/circle_parallelism.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ case $CIRCLE_NODE_INDEX in
;;
1) docker run --rm -e NOTARY_BUILDTAGS=none --env-file buildscripts/env.list --user notary notary_client bash -c "make ci && codecov"
;;
2) SKIPENVCHECK=1 make TESTDB=mysql integration
2) SKIPENVCHECK=1 make TESTDB=mysql testdb
SKIPENVCHECK=1 make TESTDB=mysql integration
;;
3) SKIPENVCHECK=1 make TESTDB=rethink integration
3) SKIPENVCHECK=1 make TESTDB=rethink testdb
SKIPENVCHECK=1 make TESTDB=rethink integration
;;
4) docker run --rm -e NOTARY_BUILDTAGS=pkcs11 notary_client make vet lint fmt misspell ineffassign
4) docker run --rm -e NOTARY_BUILDTAGS=pkcs11 notary_client make lint
;;
esac
56 changes: 56 additions & 0 deletions buildscripts/dbtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

db="$1"

case ${db} in
mysql*)
db="mysql"
dbContainerOpts="--name mysql_tests mysql mysqld --innodb_file_per_table"
DBURL="server@tcp(mysql_tests:3306)/notaryserver?parseTime=True"
;;
rethink*)
db="rethink"
dbContainerOpts="--name rethinkdb_tests rdb-01 --bind all --driver-tls-key /tls/key.pem --driver-tls-cert /tls/cert.pem"
DBURL="rethinkdb_tests"
;;
Copy link
Contributor

@riyazdf riyazdf Jul 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking nit: would be nice to have a default error case in case someone tries to run this one-off, something like:

       *)
            echo $"Usage: $0 dbName"
            exit 1

Currently I get the following if I don't provide any arg

...
+ docker-compose -p dbtests_ -f development..yml kill
ERROR: .IOError: [Errno 2] No such file or directory: u'./development..yml'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

*)
echo "Usage: $0 (mysql|rethink)"
exit 1
;;
esac

composeFile="development.${db}.yml"
project=dbtests

function cleanup {
rm -f bin/notary
docker-compose -p "${project}_${db}" -f "${composeFile}" kill
# if we're in CircleCI, we cannot remove any containers
if [[ -z "${CIRCLECI}" ]]; then
docker-compose -p "${project}_${db}" -f "${composeFile}" down -v --remove-orphans
fi
}

clientCmd="make test"
if [[ -z "${CIRCLECI}" ]]; then
BUILDOPTS="--force-rm"
else
clientCmd="make ci && codecov"
fi

set -e
set -x

cleanup

docker-compose -p "${project}_${db}" -f ${composeFile} build ${BUILDOPTS} client

trap cleanup SIGINT SIGTERM EXIT

# run the unit tests that require a DB

docker-compose -p "${project}_${db}" -f "${composeFile}" run --no-deps -d ${dbContainerOpts}
docker-compose -p "${project}_${db}" -f "${composeFile}" run --no-deps \
-e NOTARY_BUILDTAGS="${db}db" -e DBURL="${DBURL}" \
-e PKGS="github.com/docker/notary/server/storage" \
client bash -c "${clientCmd}"
2 changes: 2 additions & 0 deletions buildscripts/env.list
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ WORKSPACE
# TRAVIS_REPO_SLUG
# TRAVIS_COMMIT
# TRAVIS_BUILD_DIR

SKIPENVCHECK=1
28 changes: 22 additions & 6 deletions buildscripts/integrationtest.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
#!/usr/bin/env bash

composeFile="$1"
db="$1"
case ${db} in
mysql*)
db="mysql"
;;
rethink*)
db="rethink"
;;
*)
echo "Usage: $0 (mysql|rethink)"
exit 1
;;
esac

composeFile="development.${db}.yml"
project=integration

function cleanup {
rm -f bin/notary
docker-compose -f $composeFile kill
docker-compose -p "${project}_${db}" -f ${composeFile} kill
# if we're in CircleCI, we cannot remove any containers
if [[ -z "${CIRCLECI}" ]]; then
docker-compose -f $composeFile down -v --remove-orphans
docker-compose -p "${project}_${db}" -f ${composeFile} down -v --remove-orphans
fi
}

Expand All @@ -32,8 +47,9 @@ set -x

cleanup

docker-compose -f $composeFile config
docker-compose -f $composeFile build ${BUILDOPTS} --pull | tee
docker-compose -f $composeFile up --abort-on-container-exit
docker-compose -p "${project}_${db}" -f ${composeFile} config
docker-compose -p "${project}_${db}" -f ${composeFile} build ${BUILDOPTS} --pull | tee

trap cleanupAndExit SIGINT SIGTERM EXIT

docker-compose -p "${project}_${db}" -f ${composeFile} up --abort-on-container-exit
5 changes: 2 additions & 3 deletions development.mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ services:
build:
context: .
dockerfile: Dockerfile
env_file: buildscripts/env.list
command: buildscripts/testclient.sh
volumes:
- ./test_output:/test_output
networks:
- mdb
- srv
depends_on:
- server
volumes:
notary_data:
external: false
networks:
mdb:
external: false
Expand Down
7 changes: 4 additions & 3 deletions development.rethink.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ services:
- rdb-02
- rdb-03
client:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./test_output:/test_output
networks:
- rdb
build:
context: .
dockerfile: Dockerfile
env_file: buildscripts/env.list
links:
- server:notary-server
command: buildscripts/testclient.sh
Expand Down
Loading