Example #1
0
func TestListGroups(t *testing.T) {
	h := handlers.ListGroups(mockConfig)
	req, _ := http.NewRequest("GET", "/groups/", nil)
	w := httptest.NewRecorder()

	h(w, req)
	checkValidResponse(http.StatusOK, w, t)
}
Example #2
0
func setupRouter(cfg func() *config.Config, logger func(interface{})) http.Handler {
	ourStats := stats.New()

	router := mux.NewRouter()
	router.HandleFunc("/", handlers.Root)
	router.HandleFunc("/experiments/", handlers.ListExperiments(cfg))
	router.HandleFunc("/groups/", handlers.ListGroups(cfg))
	router.HandleFunc("/features/", handlers.ListFeatures(cfg))
	router.HandleFunc("/participate/", handlers.Participate(cfg, logger))
	router.HandleFunc("/error/", func(w http.ResponseWriter, r *http.Request) { panic("error") })
	router.HandleFunc("/stats/", func(w http.ResponseWriter, r *http.Request) {
		b, _ := json.Marshal(ourStats.Data())
		w.Write(b)
	})

	return gorillahandlers.LoggingHandler(os.Stdout, handlers.ErrorHandler(
		ourStats.Handler(router)))
}