From e3c379d069ffa9661561d25cdbf2f5894a2f8ee8 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Sat, 14 Feb 2026 08:58:38 -0800 Subject: Refactor: project structure, implement dependency injection, and align v2 UI with v1 --- exporter/exporter.go | 61 ------------------------- exporter/exporter_test.go | 111 ---------------------------------------------- 2 files changed, 172 deletions(-) delete mode 100644 exporter/exporter.go delete mode 100644 exporter/exporter_test.go (limited to 'exporter') diff --git a/exporter/exporter.go b/exporter/exporter.go deleted file mode 100644 index 9172fec..0000000 --- a/exporter/exporter.go +++ /dev/null @@ -1,61 +0,0 @@ -package exporter - -import ( - "adammathes.com/neko/models/feed" - "bytes" - "encoding/json" - "encoding/xml" - "fmt" - "html/template" -) - -func ExportFeeds(format string) string { - feeds, err := feed.All() - if err != nil { - panic(err) - } - - s := "" - switch format { - case "text": - for _, f := range feeds { - s = s + fmt.Sprintf("%s\n", f.Url) - } - - case "opml": - s = s + fmt.Sprintf(`neko feeds`) - s = s + fmt.Sprintf("\n") - for _, f := range feeds { - b, _ := xml.Marshal(f) - s = s + fmt.Sprintf("%s\n", string(b)) - } - s = s + fmt.Sprintf(``) - - case "json": - js, _ := json.Marshal(feeds) - s = fmt.Sprintf("%s\n", js) - - case "html": - htmlTemplateString := ` - -feeds - - - - -` - var bts bytes.Buffer - htmlTemplate, err := template.New("feeds").Parse(htmlTemplateString) - err = htmlTemplate.Execute(&bts, feeds) - if err != nil { - panic(err) - } - s = bts.String() - } - - return s -} diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go deleted file mode 100644 index d4cc994..0000000 --- a/exporter/exporter_test.go +++ /dev/null @@ -1,111 +0,0 @@ -package exporter - -import ( - "encoding/json" - "strings" - "testing" - - "adammathes.com/neko/config" - "adammathes.com/neko/models" -) - -func setupTestDB(t *testing.T) { - t.Helper() - config.Config.DBFile = ":memory:" - models.InitDB() - t.Cleanup(func() { - if models.DB != nil { - models.DB.Close() - } - }) -} - -func seedFeeds(t *testing.T) { - t.Helper() - _, err := models.DB.Exec("INSERT INTO feed(url, web_url, title, category) VALUES(?, ?, ?, ?)", - "https://a.com/feed", "https://a.com", "Alpha Feed", "tech") - if err != nil { - t.Fatal(err) - } - _, err = models.DB.Exec("INSERT INTO feed(url, web_url, title, category) VALUES(?, ?, ?, ?)", - "https://b.com/feed", "https://b.com", "Beta Feed", "news") - if err != nil { - t.Fatal(err) - } -} - -func TestExportText(t *testing.T) { - setupTestDB(t) - seedFeeds(t) - - result := ExportFeeds("text") - if !strings.Contains(result, "https://a.com/feed") { - t.Error("text export should contain feed URL a") - } - if !strings.Contains(result, "https://b.com/feed") { - t.Error("text export should contain feed URL b") - } -} - -func TestExportJSON(t *testing.T) { - setupTestDB(t) - seedFeeds(t) - - result := ExportFeeds("json") - var feeds []interface{} - err := json.Unmarshal([]byte(result), &feeds) - if err != nil { - t.Fatalf("JSON export should be valid JSON: %v", err) - } - if len(feeds) != 2 { - t.Errorf("JSON export should contain 2 feeds, got %d", len(feeds)) - } -} - -func TestExportOPML(t *testing.T) { - setupTestDB(t) - seedFeeds(t) - - result := ExportFeeds("opml") - if !strings.Contains(result, "") { - t.Error("OPML export should close opml tag") - } -} - -func TestExportHTML(t *testing.T) { - setupTestDB(t) - seedFeeds(t) - - result := ExportFeeds("html") - if !strings.Contains(result, "") { - t.Error("HTML export should contain html tag") - } - if !strings.Contains(result, "Alpha Feed") { - t.Error("HTML export should contain feed title") - } -} - -func TestExportUnknownFormat(t *testing.T) { - setupTestDB(t) - seedFeeds(t) - - result := ExportFeeds("unknown") - if result != "" { - t.Errorf("Unknown format should return empty string, got %q", result) - } -} - -func TestExportEmpty(t *testing.T) { - setupTestDB(t) - - result := ExportFeeds("text") - if result != "" { - t.Errorf("Export with no feeds should be empty, got %q", result) - } -} -- cgit v1.2.3