make sure last returns [] list #262

This commit is contained in:
Umputun
2019-01-25 23:20:30 -06:00
parent f7de26ef4b
commit 440beb3303
2 changed files with 7 additions and 2 deletions
+2 -1
View File
@@ -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)
+5 -1
View File
@@ -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)