serveSchemas points schema downloads at a local server. A file missing from files gets a 404.
(t *testing.T, files map[string]string)
| 19 | // serveSchemas points schema downloads at a local server. A file missing from |
| 20 | // files gets a 404. |
| 21 | func serveSchemas(t *testing.T, files map[string]string) { |
| 22 | t.Helper() |
| 23 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 24 | body, ok := files[r.URL.Path] |
| 25 | if !ok { |
| 26 | http.NotFound(w, r) |
| 27 | return |
| 28 | } |
| 29 | _, _ = io.WriteString(w, body) |
| 30 | })) |
| 31 | t.Cleanup(srv.Close) |
| 32 | |
| 33 | oldClient, oldGraphQL, oldREST := downloadClient, graphQLSource.url, restSource.url |
| 34 | t.Cleanup(func() { downloadClient, graphQLSource.url, restSource.url = oldClient, oldGraphQL, oldREST }) |
| 35 | downloadClient = srv.Client() |
| 36 | graphQLSource.url = srv.URL + "/schema.graphql" |
| 37 | restSource.url = srv.URL + "/rest.json" |
| 38 | } |
| 39 | |
| 40 | // useCacheDir gives a test its own cache folder and returns ghmock's folder |
| 41 | // inside it. |
no test coverage detected