Added server tests
This commit is contained in:
@ -20,20 +20,35 @@ func TestRequest(t *testing.T) {
|
||||
return ctx.String(fmt.Sprintf("%s %s %s %s", method, scheme, host, path))
|
||||
})
|
||||
|
||||
response := s.Request("GET", "http://example.com/request?x=1", nil)
|
||||
response := s.Request("GET", "http://example.com/request?x=1", []web.Header{{"Accept", "*/*"}}, nil)
|
||||
assert.Equal(t, response.Status(), 200)
|
||||
assert.Equal(t, string(response.Body()), "GET http example.com /request")
|
||||
}
|
||||
|
||||
func TestRequestHeader(t *testing.T) {
|
||||
s := web.NewServer()
|
||||
|
||||
s.Get("/", func(ctx web.Context) error {
|
||||
accept := ctx.Request().Header("Accept")
|
||||
empty := ctx.Request().Header("")
|
||||
return ctx.String(accept + empty)
|
||||
})
|
||||
|
||||
response := s.Request("GET", "/", []web.Header{{"Accept", "*/*"}}, nil)
|
||||
assert.Equal(t, response.Status(), 200)
|
||||
assert.Equal(t, string(response.Body()), "*/*")
|
||||
}
|
||||
|
||||
func TestRequestParam(t *testing.T) {
|
||||
s := web.NewServer()
|
||||
|
||||
s.Get("/blog/:article", func(ctx web.Context) error {
|
||||
article := ctx.Request().Param("article")
|
||||
return ctx.String(article)
|
||||
empty := ctx.Request().Param("")
|
||||
return ctx.String(article + empty)
|
||||
})
|
||||
|
||||
response := s.Request("GET", "/blog/my-article", nil)
|
||||
response := s.Request("GET", "/blog/my-article", nil, nil)
|
||||
assert.Equal(t, response.Status(), 200)
|
||||
assert.Equal(t, string(response.Body()), "my-article")
|
||||
}
|
||||
|
Reference in New Issue
Block a user