Пример #1
0
func TestStatus(t *testing.T) {

	req, _ := http.NewRequest("GET", "/status", nil)
	res := httptest.NewRecorder()

	context := eden.Context{}
	context.Request = req
	context.Response = res

	status(&context)

	if res.Code != http.StatusOK {
		t.Errorf("Expected 200 status code instead got %d", res.Code)
	}

	if !strings.Contains(res.Body.String(), "cap'n") {
		t.Errorf("Expected to see \"cap'n\" in the body, instead got: %s", res.Body.String())
	}

}
Пример #2
0
func TestEcho(t *testing.T) {

	req, _ := http.NewRequest("GET", "/echo/Hello there", nil)
	res := httptest.NewRecorder()

	context := eden.Context{}
	context.Request = req
	context.Response = res
	context.Params = make([]httprouter.Param, 1)
	context.Params[0] = httprouter.Param{Key: "phrase", Value: "Hello there"}

	echo(&context)

	if res.Code != http.StatusOK {
		t.Errorf("Expected 200 status code instead got %d", res.Code)
	}

	if !strings.Contains(res.Body.String(), "Hello there") {
		t.Errorf("Expected to see 'Hello there' in the body, instead got: %s", res.Body.String())
	}

}