aboutsummaryrefslogtreecommitdiffstats
path: root/vlog
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-12 19:55:05 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-12 19:55:05 -0800
commit16186a344a7b61633cb7342aac37ac56ad83d261 (patch)
tree739556a9dc80457d072a6f3ab1db4226fa25a9f5 /vlog
parent39ed5fcfe9327ab4eb81c4863d9e6353f08f6c07 (diff)
downloadneko-16186a344a7b61633cb7342aac37ac56ad83d261.tar.gz
neko-16186a344a7b61633cb7342aac37ac56ad83d261.tar.bz2
neko-16186a344a7b61633cb7342aac37ac56ad83d261.zip
Add comprehensive test suite — 81% cross-package coverage
Bug fixes: - config: remove unused log import - item: fix Printf format %d->%t for boolean ReadState - util: update stale config.Read -> config.Init, remove config.Config.DBServer Test files added: - config/config_test.go: Init, readConfig, addDefaults (100%) - vlog/vlog_test.go: Printf, Println verbose/silent (100%) - models/db_test.go: InitDB tests - models/feed/feed_test.go: CRUD, filter, Categories, NewFeed, ResolveFeedURL (87%) - models/item/item_test.go: CRUD, Filter with category/search/starred, rewriteImages (71%) - exporter/exporter_test.go: all export formats (91%) - importer/importer_test.go: InsertIItem, ImportJSON (90%) - crawler/crawler_test.go: GetFeedContent, CrawlFeed, CrawlWorker, Crawl (89%) - web/web_test.go: auth, login/logout, stream, item, feed, category, export, crawl, imageProxy handlers (77%) Remaining 0% functions require HTTP/rice.MustFindBox/main entry and can't be unit tested without refactoring (see tickets NK-gqkh96, NK-6q9nyg).
Diffstat (limited to 'vlog')
-rw-r--r--vlog/vlog_test.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/vlog/vlog_test.go b/vlog/vlog_test.go
new file mode 100644
index 0000000..9def0f0
--- /dev/null
+++ b/vlog/vlog_test.go
@@ -0,0 +1,78 @@
+package vlog
+
+import (
+ "bytes"
+ "fmt"
+ "os"
+ "testing"
+)
+
+func captureStdout(f func()) string {
+ old := os.Stdout
+ r, w, _ := os.Pipe()
+ os.Stdout = w
+
+ f()
+
+ w.Close()
+ os.Stdout = old
+
+ var buf bytes.Buffer
+ buf.ReadFrom(r)
+ return buf.String()
+}
+
+func TestPrintfVerbose(t *testing.T) {
+ VERBOSE = true
+ defer func() { VERBOSE = false }()
+
+ output := captureStdout(func() {
+ Printf("hello %s", "world")
+ })
+ expected := fmt.Sprintf("hello %s", "world")
+ if output != expected {
+ t.Errorf("expected %q, got %q", expected, output)
+ }
+}
+
+func TestPrintfSilent(t *testing.T) {
+ VERBOSE = false
+
+ output := captureStdout(func() {
+ Printf("hello %s", "world")
+ })
+ if output != "" {
+ t.Errorf("expected empty output when not verbose, got %q", output)
+ }
+}
+
+func TestPrintlnVerbose(t *testing.T) {
+ VERBOSE = true
+ defer func() { VERBOSE = false }()
+
+ output := captureStdout(func() {
+ Println("hello", "world")
+ })
+ expected := fmt.Sprintln("hello", "world")
+ if output != expected {
+ t.Errorf("expected %q, got %q", expected, output)
+ }
+}
+
+func TestPrintlnSilent(t *testing.T) {
+ VERBOSE = false
+
+ output := captureStdout(func() {
+ Println("hello", "world")
+ })
+ if output != "" {
+ t.Errorf("expected empty output when not verbose, got %q", output)
+ }
+}
+
+func TestInit(t *testing.T) {
+ // init() sets VERBOSE to false
+ if VERBOSE != false {
+ t.Error("VERBOSE should default to false")
+ }
+}