version: don't allocate parsing unsupported versions, empty strings

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-07-01 13:45:07 -07:00
committed by Brad Fitzpatrick
parent f11a8928a6
commit 1e6d8a1043
2 changed files with 81 additions and 20 deletions

View File

@ -28,6 +28,7 @@ func TestParse(t *testing.T) {
{"date.20200612", parsed{Datestamp: 20200612}, true},
{"borkbork", parsed{}, false},
{"1a.2.3", parsed{}, false},
{"", parsed{}, false},
}
for _, test := range tests {
@ -38,6 +39,12 @@ func TestParse(t *testing.T) {
if diff := cmp.Diff(gotParsed, test.parsed); diff != "" {
t.Errorf("parse(%q) diff (-got+want):\n%s", test.version, diff)
}
n := int(testing.AllocsPerRun(1000, func() {
gotParsed, got = parse(test.version)
}))
if n != 0 {
t.Errorf("parse(%q) allocs = %d; want 0", test.version, n)
}
}
}