-
Notifications
You must be signed in to change notification settings - Fork 32
/
module_test.go
57 lines (44 loc) · 1.06 KB
/
module_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package lion
import (
"net/http"
"testing"
"github.com/celrenheit/htest"
)
type testmodule struct {
base string
}
func (m testmodule) Routes(r *Router) {
}
func (m testmodule) Base() string {
return m.base
}
func (m testmodule) Requires() []string {
return []string{"auth", "jwt"}
}
func (m testmodule) Uses() (mws Middlewares) {
return mws
}
func (m testmodule) Get(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("getmodule"))
}
func TestModule(t *testing.T) {
l := New()
l.DefineFunc("auth", func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("auth", "authmw")
next.ServeHTTP(w, r)
})
})
l.DefineFunc("jwt", func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("token", "jwtmw")
next.ServeHTTP(w, r)
})
})
l.Module(testmodule{"/admin"})
test := htest.New(t, l)
test.Get("/admin").Do().
ExpectHeader("auth", "authmw").
ExpectHeader("token", "jwtmw").
ExpectBody("getmodule")
}