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

Run E2E tests during CI #363

Merged
merged 8 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
services:
- mongodb
- postgresql
- redis-server
- docker
Copy link
Member

Choose a reason for hiding this comment

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

this escalated quickly 👍

language: go
install: false
go:
Expand All @@ -15,16 +13,17 @@ env:
- MINIO_SECRET_KEY=minio123
- ATHENS_MONGO_STORAGE_URL=mongodb://127.0.0.1:27017
- CODE_COV=1
- GO_BINARY_PATH=vgo
- TMPDIR=/tmp/
- GO_SOURCE=${TMPDIR}go
- GO_BINARY_PATH=${TMPDIR}go/bin/go
before_script:
- make setup-dev-env
- wget "https://dl.minio.io/server/minio/release/linux-amd64/minio"
- chmod +x minio && nohup ./minio server . &
- 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;
Expand Down
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,23 @@ Hurray! We are glad that you want to contribute to our project! 👍
Run `make verify` to run all the same validations that our CI process runs, such
as checking that the standard go formatting is applied, linting, etc.

## Setup your dev environment

Run `make setup-dev-env` to install local developer tools and run necessary
services, such as mongodb, for the end-to-end tests.

## 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.

The first time you run the tests,
you must run `make setup-dev-env` first, otherwise you will see errors like the one below:

```
error connecting to storage (no reachable servers)
```
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ docs:
.PHONY: setup-dev-env
setup-dev-env:
./scripts/get_dev_tools.sh
$(MAKE) dev

.PHONY: verify
verify:
Expand All @@ -30,6 +31,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 .
Expand Down
13 changes: 12 additions & 1 deletion scripts/get_dev_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@ set -xeuo pipefail

go get github.com/golang/lint/golint
go get github.com/golang/dep/cmd/dep
go get -u -v golang.org/x/vgo

GO_VERSION="go1.11beta2"
GO_SOURCE=${GO_SOURCE:=$(go env GOPATH)/src/golang.org/x/go}
mkdir -p $(dirname $GO_SOURCE)
if [[ ! -d $GO_SOURCE ]]; then
git clone https://go.googlesource.com/go $GO_SOURCE
fi
pushd $GO_SOURCE
git checkout $GO_VERSION
cd src && ./make.bash
popd

./scripts/get_buffalo.sh
53 changes: 53 additions & 0 deletions scripts/test_e2e.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

@carolynvs
I do not know what version of bash travisCI uses,
but Bash version 4.3 and older doesn't handle set -u very well in some circumstances(arrays)
But I don't think you are using arrays so, this may be fine

https://github.com/anordal/shellharden/blob/master/how_to_do_things_safely_in_bash.md#how-to-begin-a-bash-script

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to be working fine, and it's super helpful to have the variable checking. Let me know if this is a must fix, otherwise I think it would be good to stick with -u.


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
Copy link
Member

Choose a reason for hiding this comment

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

@carolynvs
In Go1.11beta the location of the module cache is $GOPATH/src/mod
However on tip the location has changed to $GOPATH/pkg/mod[1]

Maybe you could just declare;

clearGoModCache () {
  # The sudo is a necessary workaround until go is fixed
  sudo rm -fr $GOPATH/*
}

ref:

  1. https://go-review.googlesource.com/c/go/+/126755

Copy link

Choose a reason for hiding this comment

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

I think this should be ignored until the change is in an official Go release as we do not work with go from tip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'm explicitly using a tagged release, 1.11beta2 and would prefer to not try to follow tip. Once they tag a new release with that change, then yes we should update this to keep pace with the new location.

I definitely do not want to do a rm -fr $GOPATH/* though, and just stick to nuking the mod cache directory, as this is something that should be safe for a dev to run locally as well as run on Travis.

GO_SOURCE=${GO_SOURCE:=$(go env GOPATH)/src/golang.org/x/go}
export GOROOT=${GO_SOURCE}
export PATH=${GO_SOURCE}/bin:${REPO_DIR}/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
Copy link
Member

Choose a reason for hiding this comment

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

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}
Copy link

Choose a reason for hiding this comment

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

We could consider adding this with #340

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