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

Function TestGraphQL

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

Source from the content-addressed store, hash-verified

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