415bf0cce1
Single Go binary for the ClickHouse log store (logs.raw): chlog with cat/tail/grep subcommands, plus chcat/chtail/chgrep argv[0]-dispatched symlink entrypoints. Every query is time-bounded and fully parameterized; chgrep guards wide unfiltered scans. Ships nfpm RPM with completions and woodpecker PR/tag pipelines mirroring node-lookup.
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package chlog
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestParseTimeSpecDurations(t *testing.T) {
|
|
now := time.Date(2026, 8, 23, 12, 0, 0, 0, time.UTC)
|
|
cases := map[string]time.Time{
|
|
"15m": now.Add(-15 * time.Minute),
|
|
"1h": now.Add(-time.Hour),
|
|
"2d": now.Add(-48 * time.Hour),
|
|
"90s": now.Add(-90 * time.Second),
|
|
"1w": now.Add(-7 * 24 * time.Hour),
|
|
}
|
|
for spec, want := range cases {
|
|
got, err := ParseTimeSpec(spec, now)
|
|
if err != nil {
|
|
t.Errorf("%s: %v", spec, err)
|
|
continue
|
|
}
|
|
if !got.Equal(want) {
|
|
t.Errorf("%s: got %s, want %s", spec, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseTimeSpecRFC3339(t *testing.T) {
|
|
now := time.Now()
|
|
got, err := ParseTimeSpec("2026-08-23T10:30:00+10:00", now)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := time.Date(2026, 8, 23, 0, 30, 0, 0, time.UTC)
|
|
if !got.Equal(want) {
|
|
t.Errorf("got %s, want %s", got, want)
|
|
}
|
|
if got.Location() != time.UTC {
|
|
t.Errorf("not normalized to UTC: %s", got.Location())
|
|
}
|
|
}
|
|
|
|
func TestParseTimeSpecInvalid(t *testing.T) {
|
|
now := time.Now()
|
|
for _, spec := range []string{"", "abc", "1x", "-5m", "2026-13-99", "1.5h"} {
|
|
if _, err := ParseTimeSpec(spec, now); err == nil {
|
|
t.Errorf("%q: expected error", spec)
|
|
}
|
|
}
|
|
}
|