summaryrefslogtreecommitdiff
path: root/internal/post
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-10 09:46:59 +0300
committerPaul Buetow <paul@buetow.org>2026-04-10 09:46:59 +0300
commitc8e10b6c5ab26d8bd34c288a7ce91c320862b58e (patch)
tree107e842ca542c80cdf187017251ef6d4d63d597a /internal/post
parent53ad6846aa7506b621cd38f4933442379638a01d (diff)
test: add table-driven unit tests for post, processor, generator
Cover NewID; txt autolink helpers; markdown local image discovery; pagination, page filenames, JSON script literals, time formatting, and buildPageData nav links. Made-with: Cursor
Diffstat (limited to 'internal/post')
-rw-r--r--internal/post/post_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/post/post_test.go b/internal/post/post_test.go
new file mode 100644
index 0000000..7283afd
--- /dev/null
+++ b/internal/post/post_test.go
@@ -0,0 +1,55 @@
+package post
+
+import (
+ "testing"
+ "time"
+)
+
+func TestNewID(t *testing.T) {
+ t.Parallel()
+
+ loc := time.FixedZone("CET", 1*3600)
+ base := time.Date(2026, 4, 9, 14, 30, 22, 0, loc)
+
+ tests := []struct {
+ name string
+ tm time.Time
+ suffix int
+ want string
+ }{
+ {
+ name: "utc no suffix",
+ tm: time.Date(2026, 4, 9, 14, 30, 22, 0, time.UTC),
+ suffix: 0,
+ want: "2026-04-09-143022",
+ },
+ {
+ name: "non utc converts to utc",
+ tm: base,
+ suffix: 0,
+ want: "2026-04-09-133022",
+ },
+ {
+ name: "suffix one",
+ tm: time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC),
+ suffix: 1,
+ want: "2026-01-02-030405-1",
+ },
+ {
+ name: "suffix large",
+ tm: time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC),
+ suffix: 42,
+ want: "2026-01-02-030405-42",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ t.Parallel()
+ got := NewID(tt.tm, tt.suffix)
+ if got != tt.want {
+ t.Fatalf("NewID(%v, %d) = %q; want %q", tt.tm, tt.suffix, got, tt.want)
+ }
+ })
+ }
+}