internal/control/audit_test.go

03fe6e44370f8129c9ac68f13fe674cc271f5ffa
gitbay/internal/control/audit_test.go

28 lines · 817 bytes

 1package control
 2
 3import (
 4	"testing"
 5	"time"
 6)
 7
 8func TestParseSince(t *testing.T) {
 9	now := time.Date(2026, 9, 1, 12, 0, 0, 0, time.UTC)
10	cases := map[string]time.Time{
11		"30m":                  now.Add(-30 * time.Minute),
12		"24h":                  now.Add(-24 * time.Hour),
13		"7d":                   now.Add(-7 * 24 * time.Hour),
14		"2026-08-01":           time.Date(2026, 8, 1, 0, 0, 0, 0, time.UTC),
15		"2026-08-01T10:00:00Z": time.Date(2026, 8, 1, 10, 0, 0, 0, time.UTC),
16	}
17	for in, want := range cases {
18		got, ok := parseSince(in, now)
19		if !ok || !got.Equal(want) {
20			t.Errorf("parseSince(%q) = %v, %v; want %v", in, got, ok, want)
21		}
22	}
23	for _, bad := range []string{"", "yesterday", "-1h", "x d", "2026-13-01"} {
24		if _, ok := parseSince(bad, now); ok {
25			t.Errorf("parseSince(%q) accepted", bad)
26		}
27	}
28}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form