| 1 | package goji |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestHandle(t *testing.T) { |
| 9 | t.Parallel() |
| 10 | |
| 11 | m := NewMux() |
| 12 | called := false |
| 13 | fn := func(w http.ResponseWriter, r *http.Request) { |
| 14 | called = true |
| 15 | } |
| 16 | m.Handle(boolPattern(true), http.HandlerFunc(fn)) |
| 17 | |
| 18 | w, r := wr() |
| 19 | m.ServeHTTP(w, r) |
| 20 | if !called { |
| 21 | t.Error("expected handler to be called") |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | func TestHandleFunc(t *testing.T) { |
| 26 | t.Parallel() |
| 27 | |
| 28 | m := NewMux() |
| 29 | called := false |
| 30 | fn := func(w http.ResponseWriter, r *http.Request) { |
| 31 | called = true |
| 32 | } |
| 33 | m.HandleFunc(boolPattern(true), fn) |
| 34 | |
| 35 | w, r := wr() |
| 36 | m.ServeHTTP(w, r) |
| 37 | if !called { |
| 38 | t.Error("expected handler to be called") |
| 39 | } |
| 40 | } |