diff options
| author | Sam Scholten | 2026-08-30 12:50:24 +1000 |
|---|---|---|
| committer | Sam Scholten | 2026-08-30 12:52:39 +1000 |
| commit | 96ab2fcb2ff442698465389d75390afa91629165 (patch) | |
| tree | b36ef45dccaa791b0fce4dcad99d564635663c10 /cmds/rss_test.go | |
| download | fluxrec-96ab2fcb2ff442698465389d75390afa91629165.tar.gz fluxrec-96ab2fcb2ff442698465389d75390afa91629165.zip | |
fluxrec: personal Miniflux article recommender
Diffstat (limited to 'cmds/rss_test.go')
| -rw-r--r-- | cmds/rss_test.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/cmds/rss_test.go b/cmds/rss_test.go new file mode 100644 index 0000000..406f853 --- /dev/null +++ b/cmds/rss_test.go @@ -0,0 +1,73 @@ +// Golden test for the RSS renderer: fixed runs in, exact XML out. Also +// pins batch ordering (newest first) and XML escaping of item text. +package cmds + +import ( + "testing" + "time" + + "fluxrec/core" +) + +func TestRenderRSSGolden(t *testing.T) { + at := func(day, h, m int) time.Time { + return time.Date(2024, 3, day, h, m, 0, 0, time.UTC) + } + runs := []core.RunRow{ + { + RanAt: at(1, 6, 0), EntriesSeen: 40, + Kept: []core.KeptItem{ + {EntryID: 101, URL: "https://example.com/a?x=1&y=2", Title: "Alpha & Omega", + FeedTitle: "Feed A", PublishedAt: at(1, 5, 0), + Content: "x < y", Score: 0.9, Kind: core.KindRanked}, + {EntryID: 102, URL: "https://example.com/b", Title: "Beta", + FeedTitle: "Feed B", PublishedAt: at(1, 5, 30), + Content: "second body", Score: 0.2, Kind: core.KindRandom}, + }, + }, + { + RanAt: at(1, 12, 0), EntriesSeen: 12, + Kept: []core.KeptItem{ + {EntryID: 103, URL: "https://example.com/c", Title: "Gamma", + FeedTitle: "Feed A", PublishedAt: at(1, 11, 0), + Content: "", Score: 0.8, Kind: core.KindRunnerUp}, + }, + }, + } + + got, err := RenderRSS(runs) + if err != nil { + t.Fatalf("RenderRSS: %v", err) + } + want := `<?xml version="1.0" encoding="UTF-8"?> +<rss version="2.0"> + <channel> + <title>fluxrec recommendations</title> + <description>Top-scored Miniflux entries, refreshed on a schedule.</description> + <item> + <title>Gamma</title> + <link>https://example.com/c</link> + <guid isPermaLink="false">mf:103</guid> + <pubDate>Fri, 01 Mar 2024 11:00:00 +0000</pubDate> + <description>Feed A</description> + </item> + <item> + <title>Alpha & Omega</title> + <link>https://example.com/a?x=1&y=2</link> + <guid isPermaLink="false">mf:101</guid> + <pubDate>Fri, 01 Mar 2024 05:00:00 +0000</pubDate> + <description>Feed A

x < y</description> + </item> + <item> + <title>Beta</title> + <link>https://example.com/b</link> + <guid isPermaLink="false">mf:102</guid> + <pubDate>Fri, 01 Mar 2024 05:30:00 +0000</pubDate> + <description>Feed B

second body</description> + </item> + </channel> +</rss>` + if string(got) != want { + t.Errorf("RSS mismatch.\ngot:\n%s", got) + } +} |
