MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestChain

Function TestChain

pkg/webmiddleware/webmiddleware_test.go:27–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestChain(t *testing.T) {
28 a := assertions.New(t)
29
30 var trace []string
31 middleware := []MiddlewareFunc{
32 func(next http.Handler) http.Handler {
33 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
34 trace = append(trace, "outer begin")
35 next.ServeHTTP(w, r)
36 trace = append(trace, "outer end")
37 })
38 },
39 func(next http.Handler) http.Handler {
40 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
41 trace = append(trace, "inner begin")
42 next.ServeHTTP(w, r)
43 trace = append(trace, "inner end")
44 })
45 },
46 }
47
48 chain := Chain(middleware, http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
49 trace = append(trace, "handler")
50 }))
51 chain.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(http.MethodGet, "/", nil))
52
53 a.So(trace, should.Resemble, []string{"outer begin", "inner begin", "handler", "inner end", "outer end"})
54}
55
56func TestConditional(t *testing.T) {
57 a := assertions.New(t)

Callers

nothing calls this directly

Calls 3

ChainFunction · 0.85
NewMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected