Skip to content
File

Blob: gateway/proxy_eof_test.go

go35 lines
1package gateway
2 
3import (
4 "context"
5 "io"
6 "net/http"
7 "net/http/httptest"
8 "testing"
9 
10 "github.com/stretchr/testify/require"
11 "go.uber.org/zap"
12)
13 
14func TestProxyErrorHandlerEOFAndCancellation(t *testing.T) {
15 g := &Gateway{GatewayConfig: GatewayConfig{Logger: zap.NewNop()}}
16 for _, tc := range []struct {
17 name string
18 err error
19 status int
20 body string
21 }{
22 {"EOF", io.EOF, http.StatusBadGateway, "An unexpected error has occurred while attempting to forward to destination."},
23 {"canceled", context.Canceled, 0, ""},
24 } {
25 t.Run(tc.name, func(t *testing.T) {
26 req := httptest.NewRequest(http.MethodGet, "https://app.example.com/", nil)
27 rw := httptest.NewRecorder()
28 rw.Code = 0 // Distinguish an unwritten response from an implicit 200.
29 g.errorHandler(rw, req, tc.err)
30 require.Equal(t, tc.status, rw.Code)
31 require.Equal(t, tc.body, rw.Body.String())
32 })
33 }
34}