(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestNewRequestSetsDefaultHeaders(t *testing.T) { |
| 14 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 15 | fmt.Fprint(w, `ok`) |
| 16 | })) |
| 17 | defer ts.Close() |
| 18 | |
| 19 | UserAgent = "BogusAgent" |
| 20 | |
| 21 | testCases := []struct { |
| 22 | desc string |
| 23 | client *Client |
| 24 | auth string |
| 25 | contentType string |
| 26 | }{ |
| 27 | { |
| 28 | desc: "User defaults", |
| 29 | client: &Client{}, |
| 30 | auth: "", |
| 31 | contentType: "application/json", |
| 32 | }, |
| 33 | { |
| 34 | desc: "Override defaults", |
| 35 | client: &Client{ |
| 36 | Token: "abc123", |
| 37 | APIBaseURL: "http://example.com", |
| 38 | ContentType: "bogus", |
| 39 | }, |
| 40 | auth: "Bearer abc123", |
| 41 | contentType: "bogus", |
| 42 | }, |
| 43 | } |
| 44 | |
| 45 | for _, tc := range testCases { |
| 46 | t.Run(tc.desc, func(t *testing.T) { |
| 47 | req, err := tc.client.NewRequest("GET", ts.URL, nil) |
| 48 | assert.NoError(t, err) |
| 49 | assert.Equal(t, "BogusAgent", req.Header.Get("User-Agent")) |
| 50 | assert.Equal(t, tc.contentType, req.Header.Get("Content-Type")) |
| 51 | assert.Equal(t, tc.auth, req.Header.Get("Authorization")) |
| 52 | }) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func TestDo(t *testing.T) { |
| 57 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected