Added Reader and String

This commit is contained in:
2023-07-19 13:01:51 +02:00
parent bb45def4aa
commit 09d46d5a2a
2 changed files with 27 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"git.akyoto.dev/go/assert"
@ -26,6 +27,14 @@ func TestRouter(t *testing.T) {
return ctx.Error(http.StatusUnauthorized, errors.New("Not logged in"))
})
s.Get("/reader", func(ctx server.Context) error {
return ctx.Reader(strings.NewReader("Hello"))
})
s.Get("/string", func(ctx server.Context) error {
return ctx.String("Hello")
})
tests := []struct {
URL string
Status int
@ -35,6 +44,8 @@ func TestRouter(t *testing.T) {
{URL: "/blog/post", Status: http.StatusOK, Body: "Hello"},
{URL: "/error", Status: http.StatusUnauthorized, Body: "Not logged in"},
{URL: "/not-found", Status: http.StatusNotFound, Body: http.StatusText(http.StatusNotFound)},
{URL: "/reader", Status: http.StatusOK, Body: "Hello"},
{URL: "/string", Status: http.StatusOK, Body: "Hello"},
}
for _, test := range tests {