MCPcopy Create free account
hub / github.com/exercism/cli / TestDo

Function TestDo

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

Source from the content-addressed store, hash-verified

54}
55
56func TestDo(t *testing.T) {
57 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
58 assert.Equal(t, "GET", r.Method)
59
60 fmt.Fprint(w, `{"hello": "world"}`)
61 }))
62 defer ts.Close()
63
64 type payload struct {
65 Hello string `json:"hello"`
66 }
67
68 client := &Client{}
69
70 req, err := client.NewRequest("GET", ts.URL, nil)
71 assert.NoError(t, err)
72
73 res, err := client.Do(req)
74 assert.NoError(t, err)
75
76 var body payload
77 err = json.NewDecoder(res.Body).Decode(&body)
78 assert.NoError(t, err)
79
80 assert.Equal(t, "world", body.Hello)
81}

Callers

nothing calls this directly

Calls 2

NewRequestMethod · 0.95
DoMethod · 0.95

Tested by

no test coverage detected