fix test
This commit is contained in:
+5
-7
@@ -288,10 +288,10 @@ func (s *Server) findUserCommentsCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
userID := r.URL.Query().Get("user")
|
||||
siteID := r.URL.Query().Get("site")
|
||||
|
||||
type resp struct {
|
||||
resp := struct {
|
||||
Comments []store.Comment
|
||||
Count int
|
||||
}
|
||||
}{}
|
||||
|
||||
log.Printf("[DEBUG] get comments for userID %s, %s", userID, siteID)
|
||||
|
||||
@@ -300,11 +300,9 @@ func (s *Server) findUserCommentsCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
rc := resp{
|
||||
Comments: comments,
|
||||
Count: count,
|
||||
}
|
||||
return encodeJSONWithHTML(rc)
|
||||
|
||||
resp.Comments, resp.Count = comments, count
|
||||
return encodeJSONWithHTML(resp)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -211,10 +211,16 @@ func TestServer_FindUserComments(t *testing.T) {
|
||||
|
||||
res, code := get(t, fmt.Sprintf("http://127.0.0.1:%d/api/v1/comments?site=radio-t&user=dev", port))
|
||||
assert.Equal(t, 200, code)
|
||||
comments := []store.Comment{}
|
||||
err := json.Unmarshal([]byte(res), &comments)
|
||||
|
||||
resp := struct {
|
||||
Comments []store.Comment
|
||||
Count int
|
||||
}{}
|
||||
|
||||
err := json.Unmarshal([]byte(res), &resp)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, len(comments), "should have 3 comments")
|
||||
assert.Equal(t, 3, len(resp.Comments), "should have 3 comments")
|
||||
assert.Equal(t, 3, resp.Count, "should have 3 count")
|
||||
}
|
||||
|
||||
func TestServer_UserInfo(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user