Added more tests
This commit is contained in:
57
Context_test.go
Normal file
57
Context_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
package web_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/go/assert"
|
||||
"git.akyoto.dev/go/web"
|
||||
)
|
||||
|
||||
func TestBytes(t *testing.T) {
|
||||
s := web.NewServer()
|
||||
|
||||
s.Get("/", func(ctx web.Context) error {
|
||||
return ctx.Bytes([]byte("Hello"))
|
||||
})
|
||||
|
||||
response := s.Request("GET", "/", nil)
|
||||
assert.Equal(t, response.Status(), 200)
|
||||
assert.Equal(t, string(response.Body()), "Hello")
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
s := web.NewServer()
|
||||
|
||||
s.Get("/", func(ctx web.Context) error {
|
||||
return ctx.String("Hello")
|
||||
})
|
||||
|
||||
response := s.Request("GET", "/", nil)
|
||||
assert.Equal(t, response.Status(), 200)
|
||||
assert.Equal(t, string(response.Body()), "Hello")
|
||||
}
|
||||
|
||||
func TestError(t *testing.T) {
|
||||
s := web.NewServer()
|
||||
|
||||
s.Get("/", func(ctx web.Context) error {
|
||||
return ctx.Status(401).Error("Not logged in")
|
||||
})
|
||||
|
||||
response := s.Request("GET", "/", nil)
|
||||
assert.Equal(t, response.Status(), 401)
|
||||
assert.Equal(t, string(response.Body()), "")
|
||||
}
|
||||
|
||||
func TestErrorMultiple(t *testing.T) {
|
||||
s := web.NewServer()
|
||||
|
||||
s.Get("/", func(ctx web.Context) error {
|
||||
return ctx.Status(401).Error("Not logged in", errors.New("Missing auth token"))
|
||||
})
|
||||
|
||||
response := s.Request("GET", "/", nil)
|
||||
assert.Equal(t, response.Status(), 401)
|
||||
assert.Equal(t, string(response.Body()), "")
|
||||
}
|
Reference in New Issue
Block a user