예제 #1
0
// 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
}
예제 #2
0
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())
	}
}
예제 #3
0
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())
	}
}
예제 #4
0
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())
	}
}