Table-driven tests
Make each case explain one behavior.
The idea
A table of inputs and expected outcomes is effective for booking validation. Give each case a meaningful name and isolate state between cases. Add PostgreSQL integration tests for SQL and concurrency behavior that a fake cannot represent. Fiber’s app.Test can exercise routes without opening a public listener.
Follow the flow
Make it concrete
This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.
tests := []struct {
name string
seats int
wantErr bool
}{
{"one seat", 1, false},
{"zero seats", 0, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validateSeats(tt.seats)
if (err != nil) != tt.wantErr { t.Fatal(err) }
})
}Decisions that matter
- Use focused unit cases for rules and real boundary tests for adapters.
- Parallel tests require isolated state and cleanup.
- Race tests find data races, not every logical concurrency bug.
Your turn
A test fake saves bookings correctly, but production omits the tenant predicate. Which test boundary is missing?
Reveal a worked answer
Add an integration test against PostgreSQL that queries a known booking through another tenant and receives no result. Keep the unit test for orchestration, but do not treat it as evidence for adapter SQL.