This commit is contained in:
parent
9a781d2e64
commit
4c19cd0e99
4 changed files with 65 additions and 18 deletions
|
@ -2,6 +2,8 @@ package web_test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -30,19 +32,39 @@ func TestRequestBody(t *testing.T) {
|
|||
s := web.NewServer()
|
||||
|
||||
s.Get("/", func(ctx web.Context) error {
|
||||
body := make([]byte, 4096)
|
||||
n, err := ctx.Request().Read(body)
|
||||
body, err := io.ReadAll(ctx.Request())
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ctx.Bytes(body[:n])
|
||||
return ctx.Bytes(body)
|
||||
})
|
||||
|
||||
response := s.Request("GET", "/", nil, strings.NewReader("Hello"))
|
||||
body := strings.Repeat("Hello", 1000)
|
||||
headers := []web.Header{{Key: "Content-Length", Value: strconv.Itoa(len(body))}}
|
||||
response := s.Request("GET", "/", headers, strings.NewReader(body))
|
||||
assert.Equal(t, response.Status(), 200)
|
||||
assert.Equal(t, string(response.Body()), "Hello")
|
||||
assert.Equal(t, string(response.Body()), body)
|
||||
}
|
||||
|
||||
func TestRequestBodyMissingLength(t *testing.T) {
|
||||
s := web.NewServer()
|
||||
|
||||
s.Get("/", func(ctx web.Context) error {
|
||||
body, err := io.ReadAll(ctx.Request())
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ctx.Bytes(body)
|
||||
})
|
||||
|
||||
body := strings.Repeat("Hello", 1000)
|
||||
response := s.Request("GET", "/", nil, strings.NewReader(body))
|
||||
assert.Equal(t, response.Status(), 200)
|
||||
assert.Equal(t, string(response.Body()), "")
|
||||
}
|
||||
|
||||
func TestRequestHeader(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue