Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/george-e-shaw-iv/integration-tests-example
An example project showcasing how Ardan Labs writes integration tests
https://github.com/george-e-shaw-iv/integration-tests-example
Last synced: 22 days ago
JSON representation
An example project showcasing how Ardan Labs writes integration tests
- Host: GitHub
- URL: https://github.com/george-e-shaw-iv/integration-tests-example
- Owner: george-e-shaw-iv
- Created: 2018-12-21T23:40:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-09T20:20:03.000Z (almost 4 years ago)
- Last Synced: 2024-07-31T18:18:34.335Z (4 months ago)
- Language: Go
- Homepage: https://www.ardanlabs.com/blog/2019/03/integration-testing-in-go-executing-tests-with-docker.html
- Size: 1.09 MB
- Stars: 116
- Watchers: 2
- Forks: 21
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Integration Tests Example
This project showcases how Ardan Labs handles integration tests in regards
to databases. The patterns and techniques used to write integration tests
with a database can also be applied to other services.This repository runs a simple list daemon (`listd`) that implements a REST API
for lists and items in relation to lists. The daemon uses a postgres database
to persist data.For information regarding the `listd` API, see the `apiary.apib` located in
`./cmd/listd/deploy/`.## Table of Contents
- [Running](#running)
- [Dependencies](#dependencies)
- [Environment Variables](#environment-variables)
- [Make Rule](#make-rule)
- [Testing](#testing)
- [Dependencies](#dependencies-2)
- [Make Rule](#make-rule-2)## Running
### Dependencies
The only dependencies to run the services in this repository are:
- `docker`
- `docker-compose`### Environment Variables
The program looks for the following environment variables:
- `LIST_DAEMON_PORT`: The port that the list daemon listens to/serves from (Default: `3000`).
- `LIST_DB_USER`: The postgres database username that gets used within the postgres connection
string (Default: `root`).
- `LIST_DB_PASS`: The postgres database password that gets used within the postgres connection
string (Default: `root`).
- `LIST_DB_NAME`: The postgres database name that gets used within the postgres connection string
(Default: `list`).
- `LIST_DB_HOST`: The postgres database host name that gets used within the postgres connection
string (Default `db`).
- `LIST_DB_PORT`: The postgres database port that gets used within the postgres connection string
(Default: `5432`).
- `LIST_READ_TIMEOUT`: The time, in seconds, of the read timeout of any outgoing read requests made
by the internal HTTP server (Default: `5`).
- `LIST_WRITE_TIMEOUT`: The time, in seconds, of the read timeout of any outgoing write requests made
by the internal HTTP server (Default: `10`).
- `LIST_SHUTDOWN_TIMEOUT`: The time, in seconds, of the graceful shutdown timeout of the list daemon.
This is the amount of time in between an attempted, non-forceful shutdown and the finishing of open
requests and/or the shutdown of integrated services such as the database (Default: `5`).If the environment variable has a supplied default and none are set within the context of the host
machine, then the default will be used.
To set any given environment variable, simply execute the following
pattern, replacing `[ENV_NAME]` with the name of the environment variable and `[ENV_VALUE]` with the
desired value of the environment variable: `export [ENV_NAME]=[ENV_VALUE]`. To unset any set environment
variable, simply execute the following pattern, replacing `[ENV_NAME]` with the name of the environment
variable: `unset [ENV_NAME]`.### Make Rule
To run the services simply execute the following command:
```shell
make run
```This will stop any containers defined by the compose file if already running
and then rebuild the containers using the compose file. The list daemon (`listd`)
will be available at `localhost:3000` and the postgres instance will be available
at `localhost:5432`.## Testing
### Dependencies
The only dependencies to test the go code in this repository are:
- `docker`
- `docker-compose`### Make Rule
To test the go code in this repository simply execute the following command:
```shell
make test
```This will build the containers in docker-compose.test.yml and run
`GO111MODULE=on go test -mod=vendor ./...` against all testable go code in the
repository.