Implemented io.Reader for requests
All checks were successful
/ test (push) Successful in 18s

This commit is contained in:
Eduard Urbach 2025-06-12 17:44:28 +02:00
parent 0442fc1e2e
commit 9a781d2e64
Signed by: eduard
GPG key ID: 49226B848C78F6C8
4 changed files with 28 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package web_test
import (
"fmt"
"strings"
"testing"
"git.urbach.dev/go/assert"
@ -25,6 +26,25 @@ func TestRequest(t *testing.T) {
assert.Equal(t, string(response.Body()), "GET http example.com /request")
}
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)
if err != nil {
return err
}
return ctx.Bytes(body[:n])
})
response := s.Request("GET", "/", nil, strings.NewReader("Hello"))
assert.Equal(t, response.Status(), 200)
assert.Equal(t, string(response.Body()), "Hello")
}
func TestRequestHeader(t *testing.T) {
s := web.NewServer()