MCPcopy Index your code
hub / github.com/cli/cli / TestGraphQL

Function TestGraphQL

api/client_test.go:22–45  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20}
21
22func TestGraphQL(t *testing.T) {
23 http := &httpmock.Registry{}
24 client := newTestClient(http)
25
26 vars := map[string]interface{}{"name": "Mona"}
27 response := struct {
28 Viewer struct {
29 Login string
30 }
31 }{}
32
33 http.Register(
34 httpmock.GraphQL("QUERY"),
35 httpmock.StringResponse(`{"data":{"viewer":{"login":"hubot"}}}`),
36 )
37
38 err := client.GraphQL("github.com", "QUERY", vars, &response)
39 assert.NoError(t, err)
40 assert.Equal(t, "hubot", response.Viewer.Login)
41
42 req := http.Requests[0]
43 reqBody, _ := io.ReadAll(req.Body)
44 assert.Equal(t, `{"query":"QUERY","variables":{"name":"Mona"}}`, string(reqBody))
45}
46
47func TestGraphQLError(t *testing.T) {
48 reg := &httpmock.Registry{}

Callers

nothing calls this directly

Calls 6

RegisterMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
newTestClientFunction · 0.85
GraphQLMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected