aboutsummaryrefslogtreecommitdiffstats
path: root/crawler/crawler_test.go
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-13 18:43:03 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-13 18:43:03 -0800
commit21b4eec6c1e096573bcd5f2079bc21e23a960621 (patch)
tree58c8fe2e86aef9859debd05344084e9060dc38c9 /crawler/crawler_test.go
parent01d4bbe4b2842cb8c2e4319b6cf03d3050f38d06 (diff)
downloadneko-21b4eec6c1e096573bcd5f2079bc21e23a960621.tar.gz
neko-21b4eec6c1e096573bcd5f2079bc21e23a960621.tar.bz2
neko-21b4eec6c1e096573bcd5f2079bc21e23a960621.zip
refactor(backend): improve testability and add tests (NK-6q9nyg)
Diffstat (limited to 'crawler/crawler_test.go')
-rw-r--r--crawler/crawler_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/crawler/crawler_test.go b/crawler/crawler_test.go
index f0cff9a..e0c4c6b 100644
--- a/crawler/crawler_test.go
+++ b/crawler/crawler_test.go
@@ -1,8 +1,10 @@
package crawler
import (
+ "log"
"net/http"
"net/http/httptest"
+ "strings"
"testing"
"adammathes.com/neko/config"
@@ -231,3 +233,46 @@ func TestCrawl(t *testing.T) {
t.Errorf("Expected 1 item after crawl, got %d", count)
}
}
+
+func TestCrawlFeedWithExtensions(t *testing.T) {
+ setupTestDB(t)
+
+ rssContent := `<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
+ <channel>
+ <title>Extension Feed</title>
+ <item>
+ <title>Extension Article</title>
+ <link>https://example.com/ext</link>
+ <description>Short description</description>
+ <content:encoded><![CDATA[Much longer content that should be used as description]]></content:encoded>
+ </item>
+ </channel>
+</rss>`
+
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(200)
+ w.Write([]byte(rssContent))
+ }))
+ defer ts.Close()
+
+ f := &feed.Feed{Url: ts.URL, Title: "Extension Test"}
+ f.Create()
+
+ ch := make(chan string, 1)
+ CrawlFeed(f, ch)
+ <-ch
+
+ var itemTitle, itemDesc string
+ err := models.DB.QueryRow("SELECT title, description FROM item WHERE feed_id = ?", f.Id).Scan(&itemTitle, &itemDesc)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ if itemTitle != "Extension Article" {
+ t.Errorf("Expected title 'Extension Article', got %q", itemTitle)
+ }
+ if !strings.Contains(itemDesc, "Much longer content") {
+ t.Errorf("Expected description to contain encoded content, got %q", itemDesc)
+ }
+}