Exemple #1
0
func mustCaptureHanlder(t *testing.T, m *mux.Mux, captures map[string]string) http.Handler {
	var h httpcontext.ContextHandler = &captureHanlder{
		t:        t,
		captures: captures,
	}
	return httpcontext.MakeHandler(context.Background(), m, h)
}
Exemple #2
0
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
			}
		}
	}
}