(t *testing.T)
| 241 | } |
| 242 | |
| 243 | func TestDoClientSimpleRequest(t *testing.T) { |
| 244 | simpleServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 245 | w.Header().Set("x-custom-header", "key") |
| 246 | w.Header().Set("x-request-url", r.URL.String()) |
| 247 | w.Header().Set("x-host", r.Host) |
| 248 | |
| 249 | w.WriteHeader(201) |
| 250 | body, err := httputil.DumpRequest(r, true) |
| 251 | assert.Nil(t, err) |
| 252 | w.Write(body) |
| 253 | })) |
| 254 | |
| 255 | var ( |
| 256 | path = "/foo" |
| 257 | client = NewHTTPClient(simpleServer.Listener.Addr().String(), false) |
| 258 | hostname = strings.SplitN(simpleServer.Listener.Addr().String(), ":", 2)[0] |
| 259 | port, _ = strconv.Atoi(strings.SplitN(simpleServer.Listener.Addr().String(), ":", 2)[1]) |
| 260 | req = Request{Route: &Route{Path: []byte(path)}, Target: &Target{Hostname: hostname, Port: port}} |
| 261 | resp = Response{} |
| 262 | config = Config{ |
| 263 | Timeout: 1 * time.Second, |
| 264 | ReadHeaders: true, |
| 265 | ReadBody: true, |
| 266 | } |
| 267 | ) |
| 268 | req.Target.ParseHostHeader() |
| 269 | resp, err := DoClient(client, req, &config) |
| 270 | assert.Nil(t, err) |
| 271 | |
| 272 | // we expect the request uri for the first request to be empty |
| 273 | _ = fmt.Sprintf("%s%s", simpleServer.URL, path) |
| 274 | assert.Equal(t, "", string(resp.URI)) |
| 275 | |
| 276 | // we also expect our headers and body to come back as expected |
| 277 | expected := []*Header{ |
| 278 | {"X-Custom-Header", "key"}, |
| 279 | {"X-Request-Url", "/foo"}, |
| 280 | } |
| 281 | for _, v := range expected { |
| 282 | assert.Contains(t, resp.Headers, v) |
| 283 | } |
| 284 | |
| 285 | assert.NotEqual(t, "", string(resp.Body)) |
| 286 | } |
| 287 | |
| 288 | func TestDoClientRedirectRequest(t *testing.T) { |
| 289 | simpleServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected