MCPcopy Create free account
hub / github.com/cli/cli / serveSchemas

Function serveSchemas

script/ghmock/schemafiles_test.go:21–38  ·  view source on GitHub ↗

serveSchemas points schema downloads at a local server. A file missing from files gets a 404.

(t *testing.T, files map[string]string)

Source from the content-addressed store, hash-verified

19// serveSchemas points schema downloads at a local server. A file missing from
20// files gets a 404.
21func 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.

Callers 2

TestSchemaSourceLocateFunction · 0.85
TestCmdSchemasFunction · 0.85

Calls 1

HelperMethod · 0.65

Tested by

no test coverage detected