From c8e10b6c5ab26d8bd34c288a7ce91c320862b58e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 10 Apr 2026 09:46:59 +0300 Subject: 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 --- internal/post/post_test.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 internal/post/post_test.go (limited to 'internal/post') 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) + } + }) + } +} -- cgit v1.2.3