stub feeds http test
parent
a372df64a5
commit
1fed2d648f
|
|
@ -1,13 +1,22 @@
|
|||
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) {
|
||||
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{
|
||||
|
|
@ -18,7 +27,7 @@ func TestFeed(t *testing.T) {
|
|||
},
|
||||
Version: feeds.Version{
|
||||
Created: created,
|
||||
URL: "url",
|
||||
URL: s.URL,
|
||||
Cron: "* * * * *",
|
||||
Pattern: "matches",
|
||||
},
|
||||
|
|
@ -27,6 +36,14 @@ func TestFeed(t *testing.T) {
|
|||
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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue