File: handler_test.go

package info (click to toggle)
golang-github-vulcand-oxy 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 728 kB
  • sloc: makefile: 14
file content (32 lines) | stat: -rw-r--r-- 721 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package utils

import (
	"bytes"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestDefaultHandlerErrors(t *testing.T) {
	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		h := w.(http.Hijacker)
		conn, _, _ := h.Hijack()
		conn.Close()
	}))
	t.Cleanup(srv.Close)

	request, err := http.NewRequest(http.MethodGet, srv.URL, strings.NewReader(""))
	require.NoError(t, err)

	_, err = http.DefaultTransport.RoundTrip(request)

	w := NewBufferWriter(NopWriteCloser(&bytes.Buffer{}), &NoopLogger{})

	DefaultHandler.ServeHTTP(w, nil, err)

	assert.Equal(t, http.StatusBadGateway, w.Code)
}