(t *testing.T)
| 20 | } |
| 21 | |
| 22 | func 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 | |
| 47 | func TestGraphQLError(t *testing.T) { |
| 48 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected