MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestClient_Do

Function TestClient_Do

clihttp/client_test.go:16–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestClient_Do(t *testing.T) {
17 t.Parallel()
18 cases := []struct {
19 name string
20 request *http.Request
21 Option []Option
22 }{
23 {
24 "normal",
25 func() *http.Request { r, _ := http.NewRequest("GET", "https://example.com/", nil); return r }(),
26 []Option{},
27 },
28 {
29 "large request",
30 func() *http.Request {
31 r, _ := http.NewRequest("POST", "https://example.com/", strings.NewReader(strings.Repeat("t", 10)))
32 return r
33 }(),
34 []Option{WithRequestLogThreshold(1)},
35 },
36 {
37 "large response",
38 func() *http.Request { r, _ := http.NewRequest("GET", "https://example.com/", nil); return r }(),
39 []Option{WithResponseLogThreshold(1)},
40 },
41 {
42 "error",
43 func() *http.Request { r, _ := http.NewRequest("GET", "https://non-exist-domain.com/", nil); return r }(),
44 []Option{},
45 },
46 }
47 for _, c := range cases {
48 c := c
49 t.Run(c.name, func(t *testing.T) {
50 t.Parallel()
51 tracer := mocktracer.New()
52 client := NewClient(tracer, c.Option...)
53 resp, err := client.Do(c.request)
54 if err != nil {
55 assert.True(t, tracer.FinishedSpans()[0].Tags()["error"].(bool))
56 return
57 }
58 defer resp.Body.Close()
59 assert.NotEmpty(t, tracer.FinishedSpans())
60 byt, _ := ioutil.ReadAll(resp.Body)
61 assert.Len(t, byt, 1256)
62 })
63 }
64}
65
66func TestClient_Option(t *testing.T) {
67 t.Parallel()

Callers

nothing calls this directly

Calls 7

DoMethod · 0.95
WithRequestLogThresholdFunction · 0.85
WithResponseLogThresholdFunction · 0.85
NewClientFunction · 0.85
CloseMethod · 0.80
RunMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected