mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
Adding ability to run all tests inside docker containers (#973)
* Adding ability to run all tests inside docker containers * Adding test dockerfile * Small changes to the testing sections
This commit is contained in:
committed by
Michal Pristas
parent
c3d1d14d23
commit
c2647da423
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
# Test binary, build with `go test -c`
|
# Test binary, build with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
!Dockerfile.test
|
||||||
|
|
||||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
*.out
|
*.out
|
||||||
|
|||||||
+47
-6
@@ -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.
|
See our [Contributing Guide](CONTRIBUTING.md) for tips on how to submit a pull request when you are ready.
|
||||||
|
|
||||||
### Go version
|
### 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
|
GO_BINARY_PATH=go1.11.X
|
||||||
# or whichever binary you want to use with athens
|
# 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
|
# 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
|
```console
|
||||||
make alldeps
|
make alldeps
|
||||||
```
|
```
|
||||||
|
|
||||||
then you can run the unit tests:
|
Then run this to execute the unit tests themselves:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
make test-unit
|
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:
|
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:
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
FROM golang:1.11
|
||||||
|
|
||||||
|
RUN mkdir -p /athens/tests
|
||||||
|
|
||||||
|
WORKDIR /athens/tests
|
||||||
|
|
||||||
|
COPY . .
|
||||||
@@ -35,10 +35,20 @@ test:
|
|||||||
test-unit:
|
test-unit:
|
||||||
./scripts/test_unit.sh
|
./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
|
.PHONY: test-e2e
|
||||||
test-e2e:
|
test-e2e:
|
||||||
./scripts/test_e2e.sh
|
./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
|
.PHONY: docker
|
||||||
docker: proxy-docker
|
docker: proxy-docker
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,24 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
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:
|
mongo:
|
||||||
image: mongo:3.7.9-jessie
|
image: mongo:3.7.9-jessie
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
Reference in New Issue
Block a user