- CLAUDE.md: remove deleted daemon/ entry, add embed-bench/ and lab/, fix build commands for go workspace (./... → module path), update error handling guidance to coreerr.E(), remove stale cli.AddDaemonCommand reference - Replace os.MkdirAll with coreio.Local.EnsureDir in bench/test code - Add 14 unit tests for metrics (Record, ReadEvents, Summary, sortedMap, readMetricsFile edge cases) — ai/ coverage 65.3% → 67.3% - Add parseDuration tests for cmd/metrics — coverage 0% → 24.6% - No fmt.Errorf or errors.New violations found - No os.ReadFile/os.WriteFile violations found Co-Authored-By: Virgil <virgil@lethean.io>
48 lines
922 B
Go
48 lines
922 B
Go
package metrics
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestParseDuration_Good(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
want time.Duration
|
|
}{
|
|
{"7d", 7 * 24 * time.Hour},
|
|
{"1d", 24 * time.Hour},
|
|
{"24h", 24 * time.Hour},
|
|
{"30m", 30 * time.Minute},
|
|
{"1h", time.Hour},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
got, err := parseDuration(tc.input)
|
|
if err != nil {
|
|
t.Errorf("parseDuration(%q): unexpected error: %v", tc.input, err)
|
|
continue
|
|
}
|
|
if got != tc.want {
|
|
t.Errorf("parseDuration(%q) = %v, want %v", tc.input, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseDuration_Bad(t *testing.T) {
|
|
bad := []string{
|
|
"", // too short
|
|
"d", // too short
|
|
"0d", // non-positive
|
|
"-1d", // negative
|
|
"abc", // non-numeric
|
|
"7x", // unknown unit
|
|
}
|
|
|
|
for _, input := range bad {
|
|
_, err := parseDuration(input)
|
|
if err == nil {
|
|
t.Errorf("parseDuration(%q): expected error, got nil", input)
|
|
}
|
|
}
|
|
}
|