// PreDispatch wraps the http.ResponseWriter with a new LoggerWritter // so we can log information about the response. func (l *Logger) PreDispatch(c *yarf.Context) error { c.Response = &LoggerWriter{ Writer: c.Response, } return nil }
func TestResourceHello(t *testing.T) { h := new(Hello) c := new(yarf.Context) c.Request, _ = http.NewRequest("GET", "/", nil) c.Response = httptest.NewRecorder() err := h.Get(c) if err != nil { t.Error(err.Error()) } }
func TestHello(t *testing.T) { h := new(Hello) c := new(yarf.Context) c.Request, _ = http.NewRequest("GET", "/", nil) c.Response = httptest.NewRecorder() err := h.PreDispatch(c) if err != nil { t.Error(err.Error()) } err = h.PostDispatch(c) if err != nil { t.Error(err.Error()) } }
func TestExtra(t *testing.T) { e := new(ExtraMiddleware) c := new(yarf.Context) c.Request, _ = http.NewRequest("GET", "/", nil) c.Response = httptest.NewRecorder() err := e.PreDispatch(c) if err != nil { t.Error(err.Error()) } err = e.PostDispatch(c) if err != nil { t.Error(err.Error()) } }