- build the postgres image. I created some indexes to the postgres.
docker build -t enpal-coding-challenge-db -f build/Dockerfile-db .
- build the app image
docker build -t enpal-coding-challenge -f build/Dockerfile .
Use docker-compose to run the app:
docker-compose up
When the docker compose is running, the port of postgres is listening on :5432
.
Use go test to run tests of mine:
POSTGRES_URL=postgres://postgres:mypassword123!@localhost:5432/coding-challenge?sslmode=disable \
LISTEN_ADDR=:3000 \
go run test ./tests
The first test suit is equal to the test-app
in the challenge description.
WARNING: the testing will change the data in the database.
When the docker compose is running, the port of postgres is listening on :5432
.
Use go test to run benchmarks of mine:
POSTGRES_URL=postgres://postgres:mypassword123!@localhost:5432/coding-challenge?sslmode=disable \
LISTEN_ADDR=:3000 \
go test -bench=. ./tests/
WARNING: this command will change the data in the database.
I get a result in my machine:
goos: darwin
goarch: arm64
pkg: github.com/nanozuki/enpal-home-challege/tests
cpu: Apple M1 Max
BenchmarkCalendarQuery-10 643 1950088 ns/op
It says that the CalendarQuery
function average time is 1.95 ms/op.