2021-11-10 19:06:12 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeader(t *testing.T) {
|
|
|
|
req, _ := http.NewRequest("GET", "/user-agent", nil)
|
|
|
|
req.Header.Set("User-Agent", "test")
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
app.ServeHTTP(w, req)
|
|
|
|
|
|
|
|
assert.Equal(t, 200, w.Code)
|
|
|
|
assert.Equal(t, contentType.text, w.Header().Get("Content-Type"))
|
|
|
|
assert.Equal(t, "test", w.Body.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeaders(t *testing.T) {
|
|
|
|
expected := `Header1: value1
|
|
|
|
Header2: value21
|
|
|
|
Header2: value22
|
|
|
|
Header3: value3
|
|
|
|
Host:
|
|
|
|
`
|
|
|
|
|
|
|
|
req, _ := http.NewRequest("GET", "/headers", nil)
|
2021-11-30 15:19:45 +00:00
|
|
|
req.Header = map[string][]string{
|
|
|
|
"Header1": {"value1"},
|
|
|
|
"Header2": {"value21", "value22"},
|
|
|
|
"Header3": {"value3"},
|
|
|
|
}
|
2021-11-10 19:06:12 +00:00
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
app.ServeHTTP(w, req)
|
|
|
|
|
|
|
|
assert.Equal(t, 200, w.Code)
|
|
|
|
assert.Equal(t, contentType.text, w.Header().Get("Content-Type"))
|
|
|
|
assert.Equal(t, expected, w.Body.String())
|
|
|
|
}
|