Subscribe and post RSS feeds to Bluesky
rss bluesky
at v0.1.0 2.7 kB view raw
1package main 2 3import ( 4 "reflect" 5 "testing" 6) 7 8func TestParseFeedURLs(t *testing.T) { 9 tests := []struct { 10 name string 11 input string 12 expected []string 13 }{ 14 { 15 name: "single feed", 16 input: "https://example.com/feed.xml", 17 expected: []string{"https://example.com/feed.xml"}, 18 }, 19 { 20 name: "multiple feeds", 21 input: "https://example.com/feed1.xml,https://example.com/feed2.xml", 22 expected: []string{"https://example.com/feed1.xml", "https://example.com/feed2.xml"}, 23 }, 24 { 25 name: "multiple feeds with spaces", 26 input: "https://example.com/feed1.xml, https://example.com/feed2.xml, https://example.com/feed3.xml", 27 expected: []string{"https://example.com/feed1.xml", "https://example.com/feed2.xml", "https://example.com/feed3.xml"}, 28 }, 29 { 30 name: "feeds with extra whitespace", 31 input: " https://example.com/feed1.xml , https://example.com/feed2.xml ", 32 expected: []string{"https://example.com/feed1.xml", "https://example.com/feed2.xml"}, 33 }, 34 { 35 name: "empty string", 36 input: "", 37 expected: nil, 38 }, 39 { 40 name: "only commas and spaces", 41 input: " , , , ", 42 expected: []string{}, 43 }, 44 { 45 name: "trailing comma", 46 input: "https://example.com/feed1.xml,https://example.com/feed2.xml,", 47 expected: []string{"https://example.com/feed1.xml", "https://example.com/feed2.xml"}, 48 }, 49 { 50 name: "leading comma", 51 input: ",https://example.com/feed1.xml,https://example.com/feed2.xml", 52 expected: []string{"https://example.com/feed1.xml", "https://example.com/feed2.xml"}, 53 }, 54 { 55 name: "mixed RSS and Atom feeds", 56 input: "https://blog.com/rss,https://news.com/atom.xml,https://site.com/feed", 57 expected: []string{"https://blog.com/rss", "https://news.com/atom.xml", "https://site.com/feed"}, 58 }, 59 } 60 61 for _, tt := range tests { 62 t.Run(tt.name, func(t *testing.T) { 63 result := parseFeedURLs(tt.input) 64 if !reflect.DeepEqual(result, tt.expected) { 65 t.Errorf("parseFeedURLs(%q) = %v, want %v", tt.input, result, tt.expected) 66 } 67 }) 68 } 69} 70 71func TestParseFeedURLsCount(t *testing.T) { 72 tests := []struct { 73 name string 74 input string 75 expectedCount int 76 }{ 77 {"one feed", "https://example.com/feed.xml", 1}, 78 {"two feeds", "https://a.com/feed,https://b.com/feed", 2}, 79 {"five feeds", "https://1.com/f,https://2.com/f,https://3.com/f,https://4.com/f,https://5.com/f", 5}, 80 {"empty", "", 0}, 81 } 82 83 for _, tt := range tests { 84 t.Run(tt.name, func(t *testing.T) { 85 result := parseFeedURLs(tt.input) 86 if len(result) != tt.expectedCount { 87 t.Errorf("parseFeedURLs(%q) returned %d feeds, want %d", tt.input, len(result), tt.expectedCount) 88 } 89 }) 90 } 91}