arnaucube
arnaucube/blogoPublic Self-hosted repository
blogo/rss_test.go
rss_test.goRaw
 1package main
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8func TestJoinURL(t *testing.T) {
 9	got := joinURL("https://example.com/", "/blog/", "post.html")
10	if got != "https://example.com/blog/post.html" {
11		t.Fatalf("unexpected URL: %s", got)
12	}
13}
14
15func TestRSSDate(t *testing.T) {
16	got, err := rssDate("2026-07-31")
17	if err != nil {
18		t.Fatal(err)
19	}
20	if got != "Fri, 31 Jul 2026 00:00:00 +0000" {
21		t.Fatalf("unexpected RSS date: %s", got)
22	}
23
24	if _, err := rssDate("July 31"); err == nil {
25		t.Fatal("expected invalid date to return an error")
26	}
27}
28
29func TestMarkdownTitle(t *testing.T) {
30	if got := markdownTitle("## A post title\n\nBody"); got != "A post title" {
31		t.Fatalf("unexpected title: %s", got)
32	}
33}
34
35func TestAddRSSDiscovery(t *testing.T) {
36	oldConfig := config
37	config = Config{Title: "Example & Blog", AbsoluteUrl: "https://example.com", RelativePath: "/notes"}
38	defer func() { config = oldConfig }()
39
40	got := addRSSDiscovery("<html><head></head><body></body></html>")
41	if !strings.Contains(got, `rel="alternate"`) || !strings.Contains(got, `href="https://example.com/notes/rss.xml"`) {
42		t.Fatalf("RSS discovery link missing: %s", got)
43	}
44	if !strings.Contains(got, `title="Example &amp; Blog RSS"`) {
45		t.Fatalf("RSS title was not escaped: %s", got)
46	}
47}