feed.Fetch parses and matches many fields
This commit is contained in:
@@ -2,8 +2,10 @@ package feeds_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"show-rss/src/feeds"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -14,6 +16,9 @@ func TestFeedFetch(t *testing.T) {
|
||||
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t.Logf("%s", r.URL.String())
|
||||
|
||||
b, _ := os.ReadFile("testdata/slashdot.rss")
|
||||
w.Write(b)
|
||||
}))
|
||||
t.Cleanup(s.Close)
|
||||
|
||||
@@ -29,7 +34,7 @@ func TestFeedFetch(t *testing.T) {
|
||||
Created: created,
|
||||
URL: s.URL,
|
||||
Cron: "* * * * *",
|
||||
Pattern: "matches",
|
||||
Pattern: ".*",
|
||||
},
|
||||
Execution: feeds.Execution{
|
||||
Executed: created.Add(-2 * time.Second),
|
||||
@@ -41,9 +46,25 @@ func TestFeedFetch(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed fetch: %v", err)
|
||||
}
|
||||
|
||||
if len(items) != 2 {
|
||||
t.Fatalf("expected 2 items but got %+v", items)
|
||||
for i, item := range items {
|
||||
t.Logf("[%d] %+v", i, item)
|
||||
}
|
||||
|
||||
if len(items) != 15 {
|
||||
t.Fatalf("expected 15 items but got %d", len(items))
|
||||
}
|
||||
|
||||
if items[0].Body == "" {
|
||||
t.Errorf("no body")
|
||||
}
|
||||
items[0].Body = ""
|
||||
|
||||
expect := feeds.Item{
|
||||
Title: `Cheap 'Transforming' Electric Truck Announced by Jeff Bezos-Backed Startup`,
|
||||
Links: []string{`https://tech.slashdot.org/story/25/04/26/0425259/cheap-transforming-electric-truck-announced-by-jeff-bezos-backed-startup?utm_source=rss1.0mainlinkanon&utm_medium=feed`},
|
||||
Preview: `It's a pickup truck "that can change into whatever...`,
|
||||
}
|
||||
if fmt.Sprintf("%+v", items[0]) != fmt.Sprintf("%+v", expect) {
|
||||
t.Errorf("expected\n\t%+v but got \n\t%+v", expect, items[0])
|
||||
}
|
||||
t.Errorf("check items")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user