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

Function TestCheckRequest

script/ghmock/checker_test.go:13–439  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestCheckRequest(t *testing.T) {
14 chk := testChecker(t)
15
16 gql := func(query string, variables ...string) loggedRequest {
17 e := loggedRequest{Method: "POST", Host: apiHost, Path: "/graphql", GraphQL: &graphQLRequest{Query: query}}
18 if len(variables) > 0 {
19 e.GraphQL.Variables = json.RawMessage(variables[0])
20 }
21 return e
22 }
23 operation := func(query, name string) loggedRequest {
24 e := gql(query)
25 e.GraphQL.Operation = name
26 return e
27 }
28 rest := func(method, path string) loggedRequest {
29 return loggedRequest{Method: method, Host: apiHost, Path: path}
30 }
31 reply := func(status int, body string) *response {
32 return &response{Status: status, Body: json.RawMessage(body)}
33 }
34 const issueQuery = `query { repository(owner: "o", name: "r") { issue(number: 1) { number title state assignees { login } } } }`
35 const unionQuery = `query { repository(owner: "o", name: "r") { issueOrPullRequest(number: 1) { __typename ... on Issue { title } ... on PullRequest { number } } } }`
36 const aliasUnionQuery = `query { repository(owner: "o", name: "r") { issueOrPullRequest(number: 1) { kind: __typename ... on Issue { title } ... on PullRequest { number } } } }`
37 const twoOperations = `query First { viewer { login } } query Second { viewer { name } }`
38
39 tests := []struct {
40 name string
41 req loggedRequest
42 resp *response
43 want checkResult
44 responseOnly bool
45 wantQueryContains string
46 }{
47 {
48 name: "unknown variable types are reported without coercion",
49 req: gql(`query Bad($x: Missing) { viewer { login name @include(if:$x) } }`),
50 resp: reply(200, `{"data":{"viewer":{"login":"monalisa"}}}`),
51 want: checkResult{queryProblems: []string{
52 `line 1, column 11: Unknown type "Missing".`,
53 `line 1, column 58: Variable "$x" of type "Missing" used in position expecting type "Boolean!".`,
54 }},
55 },
56 {
57 name: "a required GraphQL variable is missing",
58 req: gql(`query($x: Boolean!) { viewer { login name @include(if: $x) } }`),
59 resp: reply(200, `{"data":{"viewer":{"login":"monalisa"}}}`),
60 wantQueryContains: "variable.x",
61 },
62 {
63 name: "a GraphQL variable has the wrong type",
64 req: gql(`query($x: Boolean!) { viewer { login name @include(if: $x) } }`, `{"x":"true"}`),
65 resp: reply(200, `{"data":{"viewer":{"login":"monalisa"}}}`),
66 wantQueryContains: "variable.x",
67 },
68 {
69 name: "variables must be an object",
70 req: gql(`query { viewer { login } }`, `[]`),

Callers

nothing calls this directly

Calls 9

testCheckerFunction · 0.85
replyStruct · 0.85
checkResponseMethod · 0.80
checkRequestMethod · 0.80
ContainsMethod · 0.80
JoinMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected