forked from martini-contrib/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_test.go
41 lines (38 loc) · 859 Bytes
/
web_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package web
import (
"github.com/go-martini/martini"
"net/http"
"net/http/httptest"
"testing"
)
func TestWriteString(t *testing.T) {
str := "Hello World!"
m := martini.Classic()
m.Use(ContextWithCookieSecret("secret"))
m.Get("/", func(ctx *Context) {
ctx.WriteString(str)
})
res := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
m.ServeHTTP(res, req)
if res.Body.String() != str {
t.Errorf("WriteString Error")
}
}
func TestAbort(t *testing.T) {
str := "Hello World!"
m := martini.Classic()
m.Use(ContextWithCookieSecret("secret"))
m.Get("/", func(ctx *Context) {
ctx.Abort(401, str)
})
res := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
m.ServeHTTP(res, req)
if res.Code != 401 {
t.Error("Response Code Error")
}
if res.Body.String() != str {
t.Error("Abort Content Error")
}
}