From 7ca6dd84bd8d91e426343a1b3091af0cf6723497 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 15 Jan 2018 01:56:52 -0600 Subject: [PATCH] fix test --- app/rest/server.go | 12 +++++------- app/rest/server_test.go | 12 +++++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/rest/server.go b/app/rest/server.go index 30f2e6db..c44f983e 100644 --- a/app/rest/server.go +++ b/app/rest/server.go @@ -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 { diff --git a/app/rest/server_test.go b/app/rest/server_test.go index 6bf83f78..018998f0 100644 --- a/app/rest/server_test.go +++ b/app/rest/server_test.go @@ -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) {