Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
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)
}
Exemplo n.º 4
0
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")
}
Exemplo n.º 5
0
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")
}