Golang收到httptest失败的错误消息

时间:2014-01-28 11:35:09

标签: go

当您收到500服务器错误时,如何使用httptest获取错误消息? 注册页面在手动测试时有效,因此这似乎是一些管道问题,但我找不到消息是什么。

func TestSignUp(t *testing.T) {
    var (
        password = "password"
    )

    newUser := entities.User{}
    newUser.Email = "j@doe.co.za"   
    newUser.SetPassword(password, bcrypt.MinCost)

    v := url.Values{}
    v.Add("email_address", newUser.Email)
    v.Add("password", password)     

    res := httptest.NewRecorder()
    req := &http.Request{
        Method: "POST",
        URL:    &url.URL{Path: "/signup"},
        Form:   v,
    }

    m := Martini()
    m.ServeHTTP(res, req)

    assert.Equal(t, 200, res.Code) <<<< res.Code = 500, but where is the error message?
}

1 个答案:

答案 0 :(得分:1)

查看httptest.Recorder(http://golang.org/pkg/net/http/httptest/#example_ResponseRecorder)的示例,看起来res.Body.String()就是您想要的。