tailcfg: use strings.CutPrefix for CheckTag; add test

Updates #cleanup

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I42eddc7547a6dd50c4d5b2a9fc88a19aac9767aa
This commit is contained in:
Andrew Dunham
2024-05-31 17:01:05 -04:00
parent 0a5bd63d32
commit 36d0ac6f8e
2 changed files with 27 additions and 2 deletions

View File

@@ -865,3 +865,27 @@ func TestDeps(t *testing.T) {
},
}.Check(t)
}
func TestCheckTag(t *testing.T) {
tests := []struct {
name string
tag string
want bool
}{
{"empty", "", false},
{"good", "tag:foo", true},
{"bad", "tag:", false},
{"no_leading_num", "tag:1foo", false},
{"no_punctuation", "tag:foa@bar", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := CheckTag(tt.tag)
if err == nil && !tt.want {
t.Errorf("got nil; want error")
} else if err != nil && tt.want {
t.Errorf("got %v; want nil", err)
}
})
}
}