Added Server interface
This commit is contained in:
@ -27,6 +27,11 @@ func TestRouter(t *testing.T) {
|
||||
})
|
||||
|
||||
s.Get("/write", func(ctx server.Context) error {
|
||||
_, err := ctx.Write([]byte("Hello"))
|
||||
return err
|
||||
})
|
||||
|
||||
s.Get("/writestring", func(ctx server.Context) error {
|
||||
_, err := io.WriteString(ctx, "Hello")
|
||||
return err
|
||||
})
|
||||
@ -72,6 +77,10 @@ func TestRouter(t *testing.T) {
|
||||
return ctx.String(missing)
|
||||
})
|
||||
|
||||
s.Get("/scheme", func(ctx server.Context) error {
|
||||
return ctx.String(ctx.Scheme())
|
||||
})
|
||||
|
||||
s.Post("/", func(ctx server.Context) error {
|
||||
return ctx.String("Post")
|
||||
})
|
||||
@ -99,7 +108,9 @@ func TestRouter(t *testing.T) {
|
||||
{Method: "GET", URL: "/response/header", Status: http.StatusOK, Body: "text/plain"},
|
||||
{Method: "GET", URL: "/reader", Status: http.StatusOK, Body: "Hello"},
|
||||
{Method: "GET", URL: "/string", Status: http.StatusOK, Body: "Hello"},
|
||||
{Method: "GET", URL: "/scheme", Status: http.StatusOK, Body: "http"},
|
||||
{Method: "GET", URL: "/write", Status: http.StatusOK, Body: "Hello"},
|
||||
{Method: "GET", URL: "/writestring", Status: http.StatusOK, Body: "Hello"},
|
||||
{Method: "GET", URL: "/blog/testing-my-router", Status: http.StatusOK, Body: "testing-my-router"},
|
||||
{Method: "GET", URL: "/missing-parameter", Status: http.StatusOK, Body: ""},
|
||||
{Method: "POST", URL: "/", Status: http.StatusOK, Body: "Post"},
|
||||
@ -109,7 +120,7 @@ func TestRouter(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("example.com"+test.URL, func(t *testing.T) {
|
||||
request := httptest.NewRequest(test.Method, test.URL, nil)
|
||||
request := httptest.NewRequest(test.Method, "http://example.com"+test.URL, nil)
|
||||
response := httptest.NewRecorder()
|
||||
s.ServeHTTP(response, request)
|
||||
|
||||
@ -141,7 +152,7 @@ func TestMiddleware(t *testing.T) {
|
||||
func TestPanic(t *testing.T) {
|
||||
s := server.New()
|
||||
|
||||
s.Router.Add(http.MethodGet, "/panic", func(ctx server.Context) error {
|
||||
s.Router().Add(http.MethodGet, "/panic", func(ctx server.Context) error {
|
||||
panic("Something unbelievable happened")
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user