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/integration contains 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 items array and a string next_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_cursor after 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_km and includes distant restaurants.
  • Your tests detect an implementation that ignores the requested limit and 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_cursor until 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_URL as the API base URL and TEST_MYSQL_DSN as 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_DSN and 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 different TEST_API_URL values.

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_cursor as 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-After instead 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:

bash
cd backend && make up
cd backend && make test W=W2B8

Read the first failing assertion in the test output. It identifies which observable behaviour your suite missed or which contract assumption needs correcting.

Finished Exercise 2.19?

Restaurant list test suite

2 items

  • 2.18HTTP integration tests with MySQL fixturesnot completed
  • 2.19Restaurant list integration suitenot completed

Restaurant API capacity

Up next · Module 8 · 1 items · about 50 min

Start module 8

Implementation

Run locally

Write the code in your editor inside zomato-prep, then work through this list.

  1. Create the Go integration package in backend/integration.
  2. Connect to the API and MySQL using the two environment variables.
  3. Insert fixture restaurants and register cleanup.
  4. Test complete pagination walks, filtering and cursor validation.
  5. Handle HTTP 429 responses using Retry-After.
  6. Pass against a correct API and detect all seven supplied regressions.

Commands

terminal
cd backend && make up
terminal
cd backend && make test W=W2B8

Tests

  1. 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_URL pointing to your API and the configured MySQL test database.

    Expected At least 3 tests pass, 0 tests fail, and the package compiles successfully.

    TestW2B8_YourIntegrationTestsPassAgainstYourAPI in backend/e2e/w2_capstone_test.go