MCPcopy Create free account
hub / github.com/kataras/iris / TestFromStdWithNext

Function TestFromStdWithNext

core/handlerconv/from_std_test.go:41–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestFromStdWithNext(t *testing.T) {
42 basicauth := "secret"
43 passed := "ok"
44
45 type contextKey string
46 stdWNext := func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
47 if username, password, ok := r.BasicAuth(); ok &&
48 username == basicauth && password == basicauth {
49 ctx := stdContext.WithValue(r.Context(), contextKey("key"), "ok")
50 next.ServeHTTP(w, r.WithContext(ctx))
51 return
52 }
53 w.WriteHeader(iris.StatusForbidden)
54 }
55
56 h := handlerconv.FromStdWithNext(stdWNext)
57 next := func(ctx *context.Context) {
58 ctx.WriteString(ctx.Request().Context().Value(contextKey("key")).(string))
59 }
60
61 app := iris.New()
62 app.Get("/handlerwithnext", h, next)
63
64 e := httptest.New(t, app)
65
66 e.GET("/handlerwithnext").
67 Expect().Status(iris.StatusForbidden)
68
69 e.GET("/handlerwithnext").WithBasicAuth(basicauth, basicauth).
70 Expect().Status(iris.StatusOK).Body().IsEqual(passed)
71}

Callers

nothing calls this directly

Calls 13

FromStdWithNextFunction · 0.92
NewFunction · 0.92
ContextMethod · 0.80
WriteHeaderMethod · 0.80
WriteStringMethod · 0.80
RequestMethod · 0.80
NewMethod · 0.80
StatusMethod · 0.80
contextKeyTypeAlias · 0.70
ServeHTTPMethod · 0.65
GetMethod · 0.65
BodyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…