Restaurant list integration suite
You build a Go integration suite for GET /v1/restaurants that reads TEST_API_URL and TEST_MYSQL_DSN, inserts fixtures and checks HTTP responses. The suite must pass against another correct implementation and detect all seven supplied regressions.
Ticket
Build a Go integration test suite in backend/integration for GET /v1/restaurants. Your tests read TEST_API_URL for a running API and TEST_MYSQL_DSN for its MySQL database. Insert fixture restaurants through the database, call the endpoint over HTTP and verify the returned pages.
The restaurant list already has geographic filtering and keyset pagination. Your suite must verify that these behaviours work together against real MySQL, not just against mocked data. You will not write application code.
The grader runs your suite against your API, another correct implementation and seven implementations with deliberate bugs. Your tests must distinguish contract violations without depending on undocumented implementation details.
Acceptance criteria
- Your Go package in
backend/integrationcontains at least three integration tests, and all pass against your running API. - All tests also pass against a different correct implementation of
GET /v1/restaurants, even when it uses a different cursor format. Do not assume an ordering that the API contract does not guarantee. - Valid listing requests are checked for HTTP 200, an
itemsarray and a stringnext_cursor. - A complete pagination walk detects an implementation that drops the last restaurant from every full page.
- A complete pagination walk detects an implementation that repeats the last restaurant of a page at the beginning of the next page.
- A complete pagination walk detects an implementation that returns an empty
next_cursorafter the first page when more matching restaurants remain. - Your tests detect an implementation that includes inactive restaurants.
- Your tests detect an implementation that ignores
radius_kmand includes distant restaurants. - Your tests detect an implementation that ignores the requested
limitand returns up to 50 restaurants instead. - Your tests detect an implementation that accepts a forged cursor instead of returning HTTP 400 with
error: "invalid_cursor". - Following
next_cursoruntil it is empty visits every expected matching restaurant exactly once, without omissions or duplicates. - Expected restaurant IDs are derived from the fixtures your tests insert or the database records they query. Do not assume an empty table or fixed auto-increment IDs.
Constraints
- Write the tests as a Go package in
backend/integration. Do not change the application code. - Read
TEST_API_URLas the API base URL andTEST_MYSQL_DSNas the database connection string. - The database already contains seeded restaurants and may contain rows from other tests. Your tests must work alongside this existing data.
- Insert fixtures through
TEST_MYSQL_DSNand remove only your own fixtures during cleanup. Use test isolation to keep repeated runs independent. - Handle HTTP 429 responses by reading
Retry-After, waiting for the specified duration and retrying. - The grader runs
go test -count=1 -p 1 ./integration/...repeatedly with differentTEST_API_URLvalues.
Design direction
Keep the HTTP client, database fixtures and test cases separate.
A useful layout is:
backend/integration: holds the tests and shared helpers.- HTTP client helper: builds listing URLs, sends requests, decodes responses and handles rate limiting.
- Fixture helper: connects through
TEST_MYSQL_DSN, inserts restaurants, records their generated IDs and registers cleanup. - Test cases: prepare fixtures, call the public endpoint and compare the returned IDs with the expected database results.
Any layout that meets the contract passes.
Think about these trade-offs:
- Contract versus implementation: Treat
next_cursoras an opaque value. Pass it unchanged to the next request. Compare restaurant IDs as sets when ordering is not guaranteed. - Coverage versus complexity: Choose fixtures that expose individual failures. For pagination, create enough matching restaurants to require several pages. Include inactive and out-of-radius fixtures in the filtering test.
- Reliability versus speed: Keep fixture sets small, clean them up even when a test fails and respect
Retry-Afterinstead of treating rate limiting as an endpoint failure.
How to check your work
From the repository root, start the services and run the W2B8 tests:
cd backend && make up
cd backend && make test W=W2B8Read the first failing assertion in the test output. It identifies which observable behaviour your suite missed or which contract assumption needs correcting.
The reference solution passes every check for this exercise. Try the hints first; reading the answer before you have struggled with the problem teaches much less.
Restaurant list test suite
2 items
- 2.18HTTP integration tests with MySQL fixturesnot completed
- 2.19Restaurant list integration suitenot completed
Up next · Module 8 · 1 items · about 50 min
Implementation
Run locally
Write the code in your editor inside zomato-prep, then work through this list.
- Create the Go integration package in
backend/integration. - Connect to the API and MySQL using the two environment variables.
- Insert fixture restaurants and register cleanup.
- Test complete pagination walks, filtering and cursor validation.
- Handle HTTP 429 responses using
Retry-After. - Pass against a correct API and detect all seven supplied regressions.
Commands
cd backend && make upcd backend && make test W=W2B8Tests
Your integration tests compile and at least three tests pass against your running API, with no failures.
Input Run your integration suite using
TEST_API_URLpointing to your API and the configured MySQL test database.Expected At least 3 tests pass, 0 tests fail, and the package compiles successfully.
TestW2B8_YourIntegrationTestsPassAgainstYourAPIinbackend/e2e/w2_capstone_test.go