func BenchmarkCapture(b *testing.B) { m := mux.New("/api/", nil) for k, _ := range captureMap { m.Handle(k[0], httpcontext.MakeHandler(context.Background(), m)) } m.Init() b.ResetTimer() var reqs []*http.Request for k, _ := range captureMap { fakeReq, _ := http.NewRequest("whatever", k[1], nil) reqs = append(reqs, fakeReq) } i := 0 for { for _, req := range reqs { m.ServeHTTP(nil, req) i++ if i >= b.N { return } } } }
func TestAmbiguous(t *testing.T) { defer func() { r := recover() if strings.Index(r.(string), "mux: pattern ambiguous") == 0 { } else { t.Error("") } }() m := mux.New("/whatever/", nil) for k, _ := range ambiguousMap { m.Handle(k, nil) } m.Init() }
func TestCapture(t *testing.T) { m := mux.New("/api/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { t.Fatal("not found, url: " + r.URL.Path) })) for k, v := range captureMap { m.Handle(k[0], mustCaptureHanlder(t, m, v)) } m.Init() m.Print() for k, _ := range captureMap { fakeReq, _ := http.NewRequest("whatever", k[1], nil) m.ServeHTTP(nil, fakeReq) fmt.Println("===") } }