(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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 | |
| 66 | func TestClient_Option(t *testing.T) { |
| 67 | t.Parallel() |
nothing calls this directly
no test coverage detected