aboutsummaryrefslogtreecommitdiffstats
path: root/internal/importer/import_format_test.go
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-14 09:42:14 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-14 09:42:14 -0800
commit6fa13a06411048f3217397f4285b3e64e7b9ee58 (patch)
treeaf5ec83884bb45a10d51cf5be3ae895ebf1bcff8 /internal/importer/import_format_test.go
parent23947045c011e84149bc1b9d48805e57bb0bb3ba (diff)
downloadneko-6fa13a06411048f3217397f4285b3e64e7b9ee58.tar.gz
neko-6fa13a06411048f3217397f4285b3e64e7b9ee58.tar.bz2
neko-6fa13a06411048f3217397f4285b3e64e7b9ee58.zip
feature: implement full OPML and Text import/export (fixing NK-r6nhj0)
Diffstat (limited to 'internal/importer/import_format_test.go')
-rw-r--r--internal/importer/import_format_test.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/internal/importer/import_format_test.go b/internal/importer/import_format_test.go
new file mode 100644
index 0000000..9176383
--- /dev/null
+++ b/internal/importer/import_format_test.go
@@ -0,0 +1,97 @@
+package importer
+
+import (
+ "strings"
+ "testing"
+
+ "path/filepath"
+
+ "adammathes.com/neko/config"
+ "adammathes.com/neko/models"
+ "adammathes.com/neko/models/feed"
+)
+
+func TestImportOPML(t *testing.T) {
+ config.Config.DBFile = filepath.Join(t.TempDir(), "test.db")
+ models.InitDB()
+ defer models.DB.Close()
+
+ opmlContent := `<?xml version="1.0" encoding="UTF-8"?>
+<opml version="2.0">
+ <head>
+ <title>testing import</title>
+ </head>
+ <body>
+ <outline text="Tech">
+ <outline type="rss" text="Ars Technica" title="Ars Technica" xmlUrl="https://arstechnica.com/feed/" htmlUrl="https://arstechnica.com"/>
+ <outline type="rss" text="The Verge" title="The Verge" xmlUrl="https://www.theverge.com/rss/index.xml" htmlUrl="https://www.theverge.com"/>
+ </outline>
+ <outline type="rss" text="XKCD" title="XKCD" xmlUrl="https://xkcd.com/rss.xml" htmlUrl="https://xkcd.com"/>
+ </body>
+</opml>`
+
+ err := ImportOPML(strings.NewReader(opmlContent))
+ if err != nil {
+ t.Fatalf("ImportOPML failed: %v", err)
+ }
+
+ feeds, err := feed.All()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if len(feeds) != 3 {
+ t.Errorf("Expected 3 feeds, got %d", len(feeds))
+ }
+
+ foundArs := false
+ foundXKCD := false
+ for _, f := range feeds {
+ if f.Url == "https://arstechnica.com/feed/" {
+ foundArs = true
+ if f.Category != "Tech" {
+ t.Errorf("Expected category 'Tech' for Ars, got %q", f.Category)
+ }
+ }
+ if f.Url == "https://xkcd.com/rss.xml" {
+ foundXKCD = true
+ if f.Category != "" {
+ t.Errorf("Expected empty category for XKCD, got %q", f.Category)
+ }
+ }
+ }
+
+ if !foundArs {
+ t.Error("Did not find Ars Technica in imported feeds")
+ }
+ if !foundXKCD {
+ t.Error("Did not find XKCD in imported feeds")
+ }
+}
+
+func TestImportText(t *testing.T) {
+ config.Config.DBFile = filepath.Join(t.TempDir(), "test.db")
+ models.InitDB()
+ defer models.DB.Close()
+
+ textContent := `
+https://example.com/feed1
+# comment
+https://example.com/feed2
+ https://example.com/feed3
+`
+
+ err := ImportText(strings.NewReader(textContent))
+ if err != nil {
+ t.Fatalf("ImportText failed: %v", err)
+ }
+
+ feeds, err := feed.All()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if len(feeds) != 3 {
+ t.Errorf("Expected 3 feeds, got %d", len(feeds))
+ }
+}