e2e-rest

command module
v0.0.0-...-691959d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

e2e-rest

Build Status Coverage Status License Go Report Card Docker Hub Go

End to end sample application implemented in Go using REST APIs and PostgreSQL for persistency

Used libraries

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

Data Model

DatModel

Test execution

Using docker-compose (fast)

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

Manual (slow)

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 ./...

Explore

Using docker-compose (fast)

Start command:

docker-compose up 

Stop command:

docker-compose down 

Manual (slow)

Start:

docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -d postgres
go run main.go

Create user

POST to http://127.0.0.1:8080/users

with payload:

{
	"name":"John Smith",
	"email":"john.smith@mymail.local", 
	"password": "secret007"
}

Get token

POST to http://127.0.0.1:8080/login

with payload:

{
	"email":"john.smith@mymail.local", 
	"password": "secret007"
}

Get all users

GET to http://127.0.0.1:8080/users

using authentication with Bearer Token

Get single user

GET to http://127.0.0.1:8080/users/{id}

using authentication with Bearer Token

Update user

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 user

DELETE http://127.0.0.1:8080/users/{id}

using authentication with Bearer Token

...

Use the same schema and for all other objects.

Acknowledgements

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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL