summaryrefslogtreecommitdiff
path: root/internal/post/post_test.go
blob: 7283afd41de80286b3efa094aa14c594f793d433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)
			}
		})
	}
}