(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestMuxBasic(t *testing.T) { |
| 17 | var count uint64 |
| 18 | countermw := func(next http.Handler) http.Handler { |
| 19 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 20 | count++ |
| 21 | next.ServeHTTP(w, r) |
| 22 | }) |
| 23 | } |
| 24 | |
| 25 | usermw := func(next http.Handler) http.Handler { |
| 26 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 27 | ctx := r.Context() |
| 28 | ctx = context.WithValue(ctx, ctxKey{"user"}, "peter") |
| 29 | r = r.WithContext(ctx) |
| 30 | next.ServeHTTP(w, r) |
| 31 | }) |
| 32 | } |
| 33 | |
| 34 | exmw := func(next http.Handler) http.Handler { |
| 35 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 36 | ctx := context.WithValue(r.Context(), ctxKey{"ex"}, "a") |
| 37 | r = r.WithContext(ctx) |
| 38 | next.ServeHTTP(w, r) |
| 39 | }) |
| 40 | } |
| 41 | |
| 42 | logbuf := bytes.NewBufferString("") |
| 43 | logmsg := "logmw test" |
| 44 | logmw := func(next http.Handler) http.Handler { |
| 45 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 46 | logbuf.WriteString(logmsg) |
| 47 | next.ServeHTTP(w, r) |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | cxindex := func(w http.ResponseWriter, r *http.Request) { |
| 52 | ctx := r.Context() |
| 53 | user := ctx.Value(ctxKey{"user"}).(string) |
| 54 | w.WriteHeader(200) |
| 55 | w.Write([]byte(fmt.Sprintf("hi %s", user))) |
| 56 | } |
| 57 | |
| 58 | ping := func(w http.ResponseWriter, r *http.Request) { |
| 59 | w.WriteHeader(200) |
| 60 | w.Write([]byte(".")) |
| 61 | } |
| 62 | |
| 63 | headPing := func(w http.ResponseWriter, r *http.Request) { |
| 64 | w.Header().Set("X-Ping", "1") |
| 65 | w.WriteHeader(200) |
| 66 | } |
| 67 | |
| 68 | createPing := func(w http.ResponseWriter, r *http.Request) { |
| 69 | // create .... |
| 70 | w.WriteHeader(201) |
| 71 | } |
| 72 | |
| 73 | pingAll := func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected