8e51094d94
- call_monitor - main.go - operations.db - operations.db-shm - operations.db-wal - cluster.go - cluster_test.go Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeSnippet(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want string
|
|
}{
|
|
{"sqlite3 /tmp/x.db \"SELECT 42\"", "sqlite3 /PATH \"STR\""},
|
|
{"grep -n 'foo' line 123", "grep -n 'STR' line N"},
|
|
{" multi space ", "multi space"},
|
|
{"sha=ab12cd34ef56", "sha=HEX"},
|
|
}
|
|
for _, c := range cases {
|
|
got := normalizeSnippet(c.in)
|
|
if got != c.want {
|
|
t.Errorf("normalize(%q)=%q want %q", c.in, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHashSnippetStable(t *testing.T) {
|
|
a := hashSnippet(normalizeSnippet("ls /tmp/foo"))
|
|
b := hashSnippet(normalizeSnippet("ls /tmp/bar"))
|
|
if a != b {
|
|
t.Errorf("expected same hash after normalization: %s vs %s", a, b)
|
|
}
|
|
c := hashSnippet(normalizeSnippet("cat /tmp/foo"))
|
|
if a == c {
|
|
t.Errorf("expected different hash for different commands")
|
|
}
|
|
}
|
|
|
|
func TestSplitCSV(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
want int
|
|
}{
|
|
{"a,b,c", 3},
|
|
{" a , b , c ", 3},
|
|
{"", 0},
|
|
{"a,,b", 2},
|
|
}
|
|
for _, c := range cases {
|
|
got := splitCSV(c.in)
|
|
if len(got) != c.want {
|
|
t.Errorf("splitCSV(%q) len=%d want %d (%v)", c.in, len(got), c.want, got)
|
|
}
|
|
}
|
|
}
|