func TestJsonErrorHandler(t *testing.T) { req, _ := http.NewRequest("GET", "", nil) w := httptest.NewRecorder() sr := &libs.Subrouter{} handler := libs.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error { return sr.JsonErrorHandler(w, r, errors.New("")) }) handler.ServeHTTP(w, req) assert.Equal(t, http.StatusInternalServerError, w.Code) }
func TestRedirectHandler(t *testing.T) { req, _ := http.NewRequest("GET", "", nil) w := httptest.NewRecorder() sr := &libs.Subrouter{} handler := libs.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error { return sr.RedirectHandler(w, r, "") }) handler.ServeHTTP(w, req) assert.Equal(t, http.StatusFound, w.Code) }
func TestHtmlResponseHandler(t *testing.T) { req, _ := http.NewRequest("GET", "", nil) w := httptest.NewRecorder() tpl := libs.NewTemplate("../") sr := &libs.Subrouter{Template: tpl} handler := libs.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error { return sr.HtmlResponseHandler(w, r, "test", map[string]interface{}{}) }) handler.ServeHTTP(w, req) assert.Equal(t, http.StatusOK, w.Code) }
func (sr *Api) AttachHandlers() { sr.github = libs.NewGithub(sr.Config) sr.Router.Handle("/", libs.HandlerFunc(sr.notFoundHandler)).Methods("GET") sr.Router.Handle("/projects", libs.HandlerFunc(sr.projectsHandler)).Methods("GET") sr.Router.Handle("/contributions", libs.HandlerFunc(sr.contributionsHandler)).Methods("GET") }
func (sr *Index) AttachHandlers() { sr.Router.Handle("/", libs.HandlerFunc(sr.homeHandler)).Methods("GET") sr.Router.Handle("/{redirect:(projects|resume)}", libs.HandlerFunc(sr.redirectHandler)).Methods("GET") }