From 440beb3303e790d56c4fa0ae2ce4b04ff6abbacf Mon Sep 17 00:00:00 2001 From: Umputun Date: Fri, 25 Jan 2019 23:20:30 -0600 Subject: [PATCH] make sure last returns [] list #262 --- backend/app/rest/api/rest.go | 3 ++- backend/app/rest/api/rest_public_test.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/app/rest/api/rest.go b/backend/app/rest/api/rest.go index a55f6c37..cfaaabe7 100644 --- a/backend/app/rest/api/rest.go +++ b/backend/app/rest/api/rest.go @@ -326,7 +326,8 @@ func encodeJSONWithHTML(v interface{}) ([]byte, error) { return buf.Bytes(), nil } -func filterComments(comments []store.Comment, fn func(c store.Comment) bool) (filtered []store.Comment) { +func filterComments(comments []store.Comment, fn func(c store.Comment) bool) []store.Comment { + filtered := []store.Comment{} for _, c := range comments { if fn(c) { filtered = append(filtered, c) diff --git a/backend/app/rest/api/rest_public_test.go b/backend/app/rest/api/rest_public_test.go index 46eb106d..67624ee4 100644 --- a/backend/app/rest/api/rest_public_test.go +++ b/backend/app/rest/api/rest_public_test.go @@ -199,6 +199,10 @@ func TestRest_Last(t *testing.T) { ts, srv, teardown := startupT(t) defer teardown() + res, code := get(t, ts.URL+"/api/v1/last/2?site=radio-t") + assert.Equal(t, 200, code) + assert.Equal(t, "[]\n", res, "empty last should return empty list") + c1 := store.Comment{Text: "test test #1", ParentID: "p1", Locator: store.Locator{SiteID: "radio-t", URL: "https://radio-t.com/blah1"}} c2 := store.Comment{Text: "test test #2", ParentID: "p1", @@ -209,7 +213,7 @@ func TestRest_Last(t *testing.T) { id1 := addComment(t, c1, ts) id2 := addComment(t, c2, ts) - res, code := get(t, ts.URL+"/api/v1/last/2?site=radio-t") + res, code = get(t, ts.URL+"/api/v1/last/2?site=radio-t") assert.Equal(t, 200, code) comments := []store.Comment{} err := json.Unmarshal([]byte(res), &comments)