Added more HTTP methods
This commit is contained in:
@ -39,23 +39,39 @@ func TestRouter(t *testing.T) {
|
||||
return ctx.String("Hello")
|
||||
})
|
||||
|
||||
s.Post("/", func(ctx server.Context) error {
|
||||
return ctx.String("Post")
|
||||
})
|
||||
|
||||
s.Delete("/", func(ctx server.Context) error {
|
||||
return ctx.String("Delete")
|
||||
})
|
||||
|
||||
s.Put("/", func(ctx server.Context) error {
|
||||
return ctx.String("Put")
|
||||
})
|
||||
|
||||
tests := []struct {
|
||||
Method string
|
||||
URL string
|
||||
Status int
|
||||
Body string
|
||||
}{
|
||||
{URL: "/", Status: http.StatusOK, Body: "Hello"},
|
||||
{URL: "/blog/post", Status: http.StatusOK, Body: "Hello"},
|
||||
{URL: "/error", Status: http.StatusUnauthorized, Body: "Not logged in"},
|
||||
{URL: "/error2", Status: http.StatusUnauthorized, Body: "Not logged in\nMissing auth token"},
|
||||
{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"},
|
||||
{Method: "GET", URL: "/", Status: http.StatusOK, Body: "Hello"},
|
||||
{Method: "GET", URL: "/blog/post", Status: http.StatusOK, Body: "Hello"},
|
||||
{Method: "GET", URL: "/error", Status: http.StatusUnauthorized, Body: "Not logged in"},
|
||||
{Method: "GET", URL: "/error2", Status: http.StatusUnauthorized, Body: "Not logged in\nMissing auth token"},
|
||||
{Method: "GET", URL: "/not-found", Status: http.StatusNotFound, Body: http.StatusText(http.StatusNotFound)},
|
||||
{Method: "GET", URL: "/reader", Status: http.StatusOK, Body: "Hello"},
|
||||
{Method: "GET", URL: "/string", Status: http.StatusOK, Body: "Hello"},
|
||||
{Method: "POST", URL: "/", Status: http.StatusOK, Body: "Post"},
|
||||
{Method: "DELETE", URL: "/", Status: http.StatusOK, Body: "Delete"},
|
||||
{Method: "PUT", URL: "/", Status: http.StatusOK, Body: "Put"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("example.com"+test.URL, func(t *testing.T) {
|
||||
request := httptest.NewRequest(http.MethodGet, test.URL, nil)
|
||||
request := httptest.NewRequest(test.Method, test.URL, nil)
|
||||
response := httptest.NewRecorder()
|
||||
s.ServeHTTP(response, request)
|
||||
|
||||
|
Reference in New Issue
Block a user