This repo illustrates the usage of TDD to build an API dealing with Quotes.
go run .
# or
go run main.go
# or build it and then run it.
go build
./tdd-quotes-api
# all tests
go test ./... # this could just be go test
# all tests with verbosity
go test -v
# all specific sub tests
go test -run TestHandleQuotes/post -v
# a specific sub tests
go test -run TestHandleQuotes/post_no_body -v
go test -bench=. -run Bench
➜ tdd-quotes-api git:(bench) ✗ go test -bench=. -run Bench
goos: darwin
goarch: arm64
pkg: github.com/montybeatnik/tutorials/tdd-quotes-api
BenchmarkCreateQuote-10 3380576 324.2 ns/op
PASS
ok github.com/montybeatnik/tutorials/tdd-quotes-api 1.569s
# POST
curl -X POST -d '{
"author": "Sandi Metz",
"message": "Design is the art of arranging code that needs to work today, and to be easy to change forever."
}' http://localhost:8000
# GET all quotes
curl -X GET http://localhost:8000
# GET a specific quote
curl -X GET http://localhost:8000/1
export QUOTES_TEST_DSN='postgres://postgres:password@localhost:5432/quotes_db?sslmode=disable'