MCPcopy
hub / github.com/labstack/echo / TestProxyError

Function TestProxyError

middleware/proxy_test.go:321–358  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

319}
320
321func 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
360func TestClientCancelConnectionResultsHTTPCode499(t *testing.T) {
361 var timeoutStop sync.WaitGroup

Callers

nothing calls this directly

Calls 5

NewRandomBalancerFunction · 0.85
ProxyWithConfigFunction · 0.85
ServeHTTPMethod · 0.80
AddTargetMethod · 0.65
UseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…