(t *testing.T)
| 319 | } |
| 320 | |
| 321 | func TestProxyError(t *testing.T) { |
| 322 | // Setup |
| 323 | url1, _ := url.Parse("http://127.0.0.1:27121") |
| 324 | url2, _ := url.Parse("http://127.0.0.1:27122") |
| 325 | |
| 326 | targets := []*ProxyTarget{ |
| 327 | { |
| 328 | Name: "target 1", |
| 329 | URL: url1, |
| 330 | }, |
| 331 | { |
| 332 | Name: "target 2", |
| 333 | URL: url2, |
| 334 | }, |
| 335 | } |
| 336 | rb := NewRandomBalancer(nil) |
| 337 | // must add targets: |
| 338 | for _, target := range targets { |
| 339 | assert.True(t, rb.AddTarget(target)) |
| 340 | } |
| 341 | |
| 342 | // must ignore duplicates: |
| 343 | for _, target := range targets { |
| 344 | assert.False(t, rb.AddTarget(target)) |
| 345 | } |
| 346 | |
| 347 | // Random |
| 348 | e := echo.New() |
| 349 | e.Use(ProxyWithConfig(ProxyConfig{Balancer: rb})) |
| 350 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 351 | |
| 352 | // Remote unreachable |
| 353 | rec := httptest.NewRecorder() |
| 354 | req.URL.Path = "/api/users" |
| 355 | e.ServeHTTP(rec, req) |
| 356 | assert.Equal(t, "/api/users", req.URL.Path) |
| 357 | assert.Equal(t, http.StatusBadGateway, rec.Code) |
| 358 | } |
| 359 | |
| 360 | func TestClientCancelConnectionResultsHTTPCode499(t *testing.T) { |
| 361 | var timeoutStop sync.WaitGroup |
nothing calls this directly
no test coverage detected
searching dependent graphs…