diff --git a/.gitignore b/.gitignore index 6391f24c..73ee3d56 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # Test binary, build with `go test -c` *.test +!Dockerfile.test # Output of the go coverage tool, specifically when used with LiteIDE *.out diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 336b5107..7e6fce57 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -7,10 +7,11 @@ Athens uses [Go Modules](https://golang.org/cmd/go/#hdr-Modules__module_versions See our [Contributing Guide](CONTRIBUTING.md) for tips on how to submit a pull request when you are ready. ### Go version -Athens is developed on Go1.11+. +Athens is developed on Go 1.11+. -To point Athens to a different version of Go set the following environment variable -``` +To point Athens to a different version of Go set the following environment variable: + +```console GO_BINARY_PATH=go1.11.X # or whichever binary you want to use with athens ``` @@ -51,19 +52,59 @@ Note that `make dev` only runs the minimum amount of dependencies needed for thi # Run unit tests -In order to run unit tests, services they depend on must be running first: +There are two methods for running unit tests: + +## Completely In Containers + +This method uses [Docker Compose](https://docs.docker.com/compose/) to set up and run all the unit tests completely inside Docker containers. + +**We highly recommend you use this approach to run unit tests on your local machine.** + +It's nice because: + +- You don't have to set up anything in advance or clean anything up +- It's completely isolated +- All you need is to have [Docker Compose](https://docs.docker.com/compose/) installed + +To run unit tests in this manner, use this command: + +```console +make test-unit-docker +``` + +## On the Host + +This method uses Docker Compose to set up all the dependencies of the unit tests (databases, etc...), but runs the unit tests directly on your host, not in a Docker container. This is a nice approach because you can keep all the dependency services running at all times, and you can run the actual unit tests very quickly. + +To run unit tests in this manner, first run this command to set up all the dependencies: ```console make alldeps ``` -then you can run the unit tests: +Then run this to execute the unit tests themselves: ```console make test-unit ``` -# Run the docs +And when you're done with unit tests and want to clean up all the dependencies, run this command: + +```console +make dev-teardown +``` + +# Run End to End Tests + +End to end tests ensure that the Athens server behaves as expected from the `go` CLI tool. These tests run exclusively inside Docker containers using [Docker Compose](https://docs.docker.com/compose/), so you'll have to have those dependencies installed. To run the tests, execute this command: + +```console +make test-e2e-docker +``` + +This will create the e2e test containers, run the tests themselves, and then shut everything down. + +# Build the Docs To get started with developing the docs we provide a docker image, which runs [Hugo](https://gohugo.io/) to render the docs. Using the docker image, we mount the `/docs` directory into the container. To get it up and running, from the project root run: diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 00000000..7d597de5 --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,7 @@ +FROM golang:1.11 + +RUN mkdir -p /athens/tests + +WORKDIR /athens/tests + +COPY . . diff --git a/Makefile b/Makefile index 6bdca9b9..95cfd61f 100644 --- a/Makefile +++ b/Makefile @@ -35,10 +35,20 @@ test: test-unit: ./scripts/test_unit.sh +.PHONY: test-unit-docker +test-unit-docker: + docker-compose -p athensunit up --exit-code-from=testunit --build testunit + docker-compose -p athensunit down + .PHONY: test-e2e test-e2e: ./scripts/test_e2e.sh +.PHONY: test-e2e-docker +test-e2e-docker: + docker-compose -p athense2e up --build --exit-code-from=teste2e teste2e + docker-compose -p athense2e down + .PHONY: docker docker: proxy-docker diff --git a/docker-compose.yml b/docker-compose.yml index fa5bea4a..70c2742e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,24 @@ version: '3' services: + testunit: + build: + context: . + dockerfile: Dockerfile.test + command: ["./scripts/test_unit.sh"] + environment: + - GO_ENV=test + - ATHENS_MINIO_ENDPOINT=minio:9000 + - ATHENS_MONGO_STORAGE_URL=mongodb://mongo:27017 + - TIMEOUT=20 # in case the mongo dependency takes longer to start up + - ATHENS_STORAGE_TYPE=mongo + depends_on: + - mongo + - minio + teste2e: + build: + context: . + dockerfile: Dockerfile.test + command: ["./scripts/test_e2e.sh"] mongo: image: mongo:3.7.9-jessie ports: