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

Function TestProxyWithNoTargetDoesNotRetry

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

Source from the content-addressed store, hash-verified

518}
519
520func TestProxyWithNoTargetDoesNotRetry(t *testing.T) {
521 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
522 w.WriteHeader(http.StatusOK)
523 }))
524 defer server.Close()
525 targetURL, _ := url.Parse(server.URL)
526
527 balancer := &sequenceBalancer{
528 targets: []*ProxyTarget{
529 nil,
530 {Name: "target", URL: targetURL},
531 },
532 }
533
534 retryFilterCalled := false
535 e := echo.New()
536 e.Use(ProxyWithConfig(ProxyConfig{
537 Balancer: balancer,
538 RetryCount: 1,
539 RetryFilter: func(c *echo.Context, err error) bool {
540 retryFilterCalled = true
541 return true
542 },
543 }))
544
545 req := httptest.NewRequest(http.MethodGet, "/", nil)
546 rec := httptest.NewRecorder()
547
548 e.ServeHTTP(rec, req)
549
550 assert.False(t, retryFilterCalled)
551 assert.Equal(t, 1, balancer.calls)
552 assert.Equal(t, http.StatusBadGateway, rec.Code)
553}
554
555func TestProxyRetries(t *testing.T) {
556 newServer := func(res int) (*url.URL, *httptest.Server) {

Callers

nothing calls this directly

Calls 5

ProxyWithConfigFunction · 0.85
ServeHTTPMethod · 0.80
WriteHeaderMethod · 0.45
CloseMethod · 0.45
UseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…