fix: harden explore dataset collection

This commit is contained in:
2026-07-23 21:34:13 +08:00
parent 3749cf4543
commit 50d8246915
9 changed files with 254 additions and 87 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/url"
"os"
"testing"
"github.com/stretchr/testify/require"
@@ -98,6 +99,29 @@ func TestValidateFeedURLRejectsLocalAddressesAndCredentials(t *testing.T) {
require.NoError(t, validateFeedURL(parsed))
}
func TestLiveFeedCollectionFormats(t *testing.T) {
if os.Getenv("TEST_LIVE_FEEDS") != "1" {
t.Skip("set TEST_LIVE_FEEDS=1 to verify external feeds")
}
fetcher := NewHTTPFeedFetcher()
for _, test := range []struct {
name string
url string
wantFormat string
}{
{name: "JSON Feed", url: "https://bbg.buzzing.cc/feed.json", wantFormat: "json_feed"},
{name: "RSS XML", url: "https://rsshub.ktachibana.party/cls/hot", wantFormat: "rss"},
{name: "second RSS XML", url: "https://rsshub.ktachibana.party/jin10", wantFormat: "rss"},
} {
t.Run(test.name, func(t *testing.T) {
feed, err := fetcher.Fetch(context.Background(), test.url)
require.NoError(t, err)
require.Equal(t, test.wantFormat, feed.Format)
require.NotEmpty(t, feed.Items)
})
}
}
func TestSyncSourcesRecordsFeedFailure(t *testing.T) {
database := newDatasetTestDatabase(t)
user := createDatasetTestUser(t, database, "feed-owner@example.com")