diff --git a/.travis.yml b/.travis.yml index ca35de96e0..0343879f8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ before_script: - buffalo db create - buffalo db migrate up script: - - make verify test-unit + - make verify test-unit test-e2e after_success: - if [ "${CODE_COV}" == "1" ]; then curl -s https://codecov.io/bash -o codecov && bash codecov -X fix; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3ea3027856..95d13e4582 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,3 +6,9 @@ as checking that the standard go formatting is applied, linting, etc. ## Unit Tests Run `make test-unit` to run the unit tests. + +## End-to-End Tests +End-to-End tests (e2e) are tests from the user perspective that validate that +everything works when running real live servers, and using `go` with GOPROXY set. + +Run `make test-e2e` to run the end-to-end tests. diff --git a/Makefile b/Makefile index e793c13463..5f0dd1a785 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,10 @@ test: test-unit: ./scripts/test_unit.sh +.PHONY: test-e2e +test-e2e: + ./scripts/test_e2e.sh + .PHONY: olympus-docker olympus-docker: docker build -t gopackages/olympus -f cmd/olympus/Dockerfile . diff --git a/scripts/test_e2e.sh b/scripts/test_e2e.sh new file mode 100755 index 0000000000..e0042c35af --- /dev/null +++ b/scripts/test_e2e.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# test_e2e.sh +# Execute end-to-end (e2e) tests to verify that everything is working right +# from the end user perpsective +set -xeuo pipefail + +REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/.." + +# Use a version of Go that supports Go Modules +export GO111MODULES=on +GOMOD_CACHE=$(go env GOPATH)/src/mod +GO_SOURCE=${GO_SOURCE:=$(go env GOPATH)/src/golang.org/x/go} +export GOROOT=${GO_SOURCE} +export PATH=${GO_SOURCE}/bin:${PATH} +go version + +clearGoModCache () { + # The sudo is a necessary workaround until go is fixed + sudo rm -fr ${GOMOD_CACHE} +} + +teardown () { + # Cleanup after our tests + pkill buffalo || true + popd 2> /dev/null || true +} +trap teardown EXIT + +# Start the proxy in the background and wait for it to be ready +export GO_BINARY_PATH=${GO_SOURCE}/bin/go +cd $REPO_DIR/cmd/proxy +pkill buffalo || true # cleanup old buffalos +buffalo dev & +while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:3000)" != "200" ]]; do sleep 5; done + +# Clone our test repo +TEST_SOURCE=${TMPDIR}go-depmgmt-testrepo +rm -fr ${TEST_SOURCE} 2> /dev/null || true +git clone https://github.com/carolynvs/go-depmgmt-testrepo.git ${TEST_SOURCE} +pushd ${TEST_SOURCE} + +clearGoModCache + +# Make sure that our test repo works without the GOPROXY first +unset GOPROXY +go run main.go + +clearGoModCache + +# Verify that the test works against the proxy +export GOPROXY=http://localhost:3000 +go run main.go