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,13 +1,22 @@
package feeds_test package feeds_test
import ( import (
"context"
"net/http"
"net/http/httptest"
"show-rss/src/feeds" "show-rss/src/feeds"
"testing" "testing"
"time" "time"
) )
func TestFeed(t *testing.T) { func TestFeedFetch(t *testing.T) {
t.Run("fetch", func(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) created := time.Now().Add(-4 * time.Second)
feed := feeds.Feed{ feed := feeds.Feed{
Entry: feeds.Entry{ Entry: feeds.Entry{
@ -18,7 +27,7 @@ func TestFeed(t *testing.T) {
}, },
Version: feeds.Version{ Version: feeds.Version{
Created: created, Created: created,
URL: "url", URL: s.URL,
Cron: "* * * * *", Cron: "* * * * *",
Pattern: "matches", Pattern: "matches",
}, },
@ -27,6 +36,14 @@ func TestFeed(t *testing.T) {
Version: created, Version: created,
}, },
} }
_ = feed
}) 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")
} }