--- title: "ADR 0076: The GitHub test server mounts the API under /api/v3 and serves GraphQL itself" --- * Status: accepted * Code: [`pkg/test/github/github.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/test/github/github.go) ## Context Unit tests across the provider code build a GitHub client against an `httptest` server through `SetupGH`. The helper is adapted from the go-github test suite (its doc says so) and refers to go-github issue 752, about clients that drop the base URL path when an endpoint URL is absolute instead of relative. ## Decision * `SetupGH` serves the test `mux` under the prefix `/api/v3` (`githubBaseURLPath`) using `http.StripPrefix`, and points the client at `server.URL + "/api/v3/"`. * Any request outside that prefix and outside `/api/graphql` hits a fallback handler that prints the offending URL to stderr and returns HTTP 500, so a test using an absolute endpoint fails loudly. * `/api/graphql` is forwarded to the same `mux` without the prefix, because GraphQL is not under `/api/v3`. * The tree helper registers one `/api/graphql` handler per mux, only when called with `recursive == false` and only if the directory holds at least one file. It walks the whole directory first so one handler answers for every file. * The handler accepts POST only. It reads aliases and `ref:path` expressions out of the query text line by line, looks the path up in the file map, and falls back to matching a suffix `"/"+path`. ## Consequences * Tests that register their own `/api/graphql` on the same mux alongside this helper would conflict; the code does not show whether that occurs. * The query parsing depends on the line layout the production GraphQL batch query emits; a change to that layout breaks the fake without any compile error. * The suffix fallback can match a different file than the real API would; the code gives no reason for it.