End to end sample application implemented in Go using REST APIs and PostgreSQL for persistency
GORM - ORM library for Golang
gorilla/mux - HTTP request multiplexer, part of Gorilla web toolkit
jwt-go - Implementation of JSON Web Tokens
wait-for-it - used in docker-compose
Start command:
make e2e-test
This will execute following sequence using docker-compose:
- prepare docker image with sources and tests
- start of postgre in container
- execute tests against postgre in container
- tear down all started docker images
Start test postgre instance:
docker run --name postgres_test -p 5433:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -d postgres
Start tests:
go test ./...
Start command:
docker-compose up
Stop command:
docker-compose down
Start:
docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -d postgres
go run main.go
POST
to http://127.0.0.1:8080/users
with payload:
{
"name":"John Smith",
"email":"john.smith@mymail.local",
"password": "secret007"
}
POST
to http://127.0.0.1:8080/login
with payload:
{
"email":"john.smith@mymail.local",
"password": "secret007"
}
GET
to http://127.0.0.1:8080/users
using authentication with Bearer Token
GET
to http://127.0.0.1:8080/users/{id}
using authentication with Bearer Token
PUT
to http://127.0.0.1:8080/users/{id}
with payload:
{
"name":"John Smith2",
"email":"john.smith@mymail.local",
"password": "secret007"
}
using authentication with Bearer Token
DELETE
http://127.0.0.1:8080/users/{id}
using authentication with Bearer Token
...
Use the same schema and for all other objects.
Article "CRUD RESTful API with Go, GORM, JWT, Postgres, Mysql, and Testing" by Steven Victor
Article "Integration Testing in Go" by George Shaw, that prove this was doable
Docker compose detailed documentation