(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…