示例#1
0
func TestControllerWrapping(t *testing.T) {
	wrapped, err := controller.Wrap(&TestController{}, "Test")

	if err != nil {
		t.Error(err)
	}

	r, _ := http.NewRequest("GET", "/", nil)

	response := wrapped(r)

	_, ok := response.(noxuhttp.TextResponse)

	assert.True(t, ok)
}
示例#2
0
func TestControllerWrappingTextResponseExecution(t *testing.T) {
	wrapped, err := controller.Wrap(&TestController{}, "Test")

	if err != nil {
		t.Error(err)
	}

	r, _ := http.NewRequest("GET", "/", nil)

	response := wrapped(r)

	textResponse, ok := response.(noxuhttp.TextResponse)

	assert.True(t, ok)

	w := httptest.NewRecorder()
	textResponse.Respond(w, r)

	bodyContents, _ := ioutil.ReadAll(w.Body)
	assert.Equal(t, []byte("text"), bodyContents)
}