stub feeds http test

main
Bel LaPointe 2025-04-27 12:06:40 -06:00
parent a372df64a5
commit 1fed2d648f
1 changed files with 40 additions and 23 deletions

View File

@ -1,32 +1,49 @@
package feeds_test
import (
"context"
"net/http"
"net/http/httptest"
"show-rss/src/feeds"
"testing"
"time"
)
func TestFeed(t *testing.T) {
t.Run("fetch", func(t *testing.T) {
created := time.Now().Add(-4 * time.Second)
feed := feeds.Feed{
Entry: feeds.Entry{
ID: "id",
Created: created,
Updated: created,
Deleted: time.Time{},
},
Version: feeds.Version{
Created: created,
URL: "url",
Cron: "* * * * *",
Pattern: "matches",
},
Execution: feeds.Execution{
Executed: created.Add(-2 * time.Second),
Version: created,
},
}
_ = feed
})
func TestFeedFetch(t *testing.T) {
ctx := context.Background()
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Logf("%s", r.URL.String())
}))
t.Cleanup(s.Close)
created := time.Now().Add(-4 * time.Second)
feed := feeds.Feed{
Entry: feeds.Entry{
ID: "id",
Created: created,
Updated: created,
Deleted: time.Time{},
},
Version: feeds.Version{
Created: created,
URL: s.URL,
Cron: "* * * * *",
Pattern: "matches",
},
Execution: feeds.Execution{
Executed: created.Add(-2 * time.Second),
Version: created,
},
}
items, err := feed.Fetch(ctx)
if err != nil {
t.Fatalf("failed fetch: %v", err)
}
if len(items) != 2 {
t.Fatalf("expected 2 items but got %+v", items)
}
t.Errorf("check items")
}