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