-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add walthrough for repo and api test suites
- Loading branch information
1 parent
2fe50e1
commit 9d65d39
Showing
9 changed files
with
83 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Go presentation: Beyond unit tests | ||
|
||
A dive into integration and end-to-end testing in Go. | ||
|
||
## Walkthrough | ||
|
||
[app_to_test](./app_to_test) contains very simple web application. It's expense | ||
tracker, with small HTTP API. Don't take too many of these ideas to production 🙃 | ||
You can play with it through [expenses.http](app_to_test%2Fexpenses.http). | ||
|
||
First suite of test to check out is [test_repos](./test_repos). It uses test | ||
containers to spin up Postgres database and checks if repository works as promised. | ||
It's a good tool for more complex SQL queries, or testing against concurrency issues. | ||
|
||
Next one is [test_http_api](test_http_api). It includes database trick from | ||
previous suite, but also spins up API. Explored idea here is how to keep tests | ||
like these easy to read, and not a chore to write (at least, after the first one). | ||
|
||
## Requirements | ||
|
||
- Go 1.21 | ||
- Docker Desktop 24+ | ||
|
||
## Start application | ||
|
||
```shell | ||
docker compose up | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 25 additions & 25 deletions
50
docker-compose-db-only.yaml → test_repos/docker-compose-db-only.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
version: "3.9" | ||
services: | ||
db: | ||
image: "postgres:15.2-alpine" | ||
environment: | ||
POSTGRES_DB: expense_tracker | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: secret123 | ||
healthcheck: | ||
test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ] | ||
interval: 3s | ||
timeout: 60s | ||
retries: 10 | ||
start_period: 5s | ||
ports: | ||
# Random port to avoid collision. Helpful in CI! | ||
- "5432" | ||
|
||
migrate: | ||
build: | ||
context: app_to_test/db | ||
environment: | ||
DB_URL: "postgres://postgres:secret123@db:5432/expense_tracker?sslmode=disable" | ||
depends_on: | ||
db: | ||
version: "3.9" | ||
services: | ||
db: | ||
image: "postgres:15.2-alpine" | ||
environment: | ||
POSTGRES_DB: expense_tracker | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: secret123 | ||
healthcheck: | ||
test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ] | ||
interval: 3s | ||
timeout: 60s | ||
retries: 10 | ||
start_period: 5s | ||
ports: | ||
# Random port to avoid collision. Helpful in CI! | ||
- "5432" | ||
|
||
migrate: | ||
build: | ||
context: ../app_to_test/db | ||
environment: | ||
DB_URL: "postgres://postgres:secret123@db:5432/expense_tracker?sslmode=disable" | ||
depends_on: | ||
db: | ||
condition: service_healthy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters