test: split tests between valid and invalid

Signed-off-by: Benoit Tigeot <benoit.tigeot@lifen.fr>
pull/31491/head
Benoit Tigeot 1 month ago
parent 9b242dd9ed
commit b296cbef6c
No known key found for this signature in database
GPG Key ID: 8E6D4FC8AEBDA62C

@ -22,38 +22,38 @@ import (
)
func TestValidPluginName(t *testing.T) {
tests := []struct {
name string
pluginName string
shouldPass bool
}{
// Valid names
{"lowercase", "myplugin", true},
{"uppercase", "MYPLUGIN", true},
{"mixed case", "MyPlugin", true},
{"with digits", "plugin123", true},
{"with hyphen", "my-plugin", true},
{"with underscore", "my_plugin", true},
{"mixed chars", "my-awesome_plugin_123", true},
// Invalid names
{"empty", "", false},
{"space", "my plugin", false},
{"colon", "plugin:", false},
{"period", "my.plugin", false},
{"slash", "my/plugin", false},
{"dollar", "$plugin", false},
{"unicode", "plügîn", false},
validNames := map[string]string{
"lowercase": "myplugin",
"uppercase": "MYPLUGIN",
"mixed case": "MyPlugin",
"with digits": "plugin123",
"with hyphen": "my-plugin",
"with underscore": "my_plugin",
"mixed chars": "my-awesome_plugin_123",
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
matches := validPluginName.MatchString(tt.pluginName)
if tt.shouldPass && !matches {
t.Errorf("expected %q to match validPluginName regex", tt.pluginName)
for name, pluginName := range validNames {
t.Run("valid/"+name, func(t *testing.T) {
if !validPluginName.MatchString(pluginName) {
t.Errorf("expected %q to match validPluginName regex", pluginName)
}
if !tt.shouldPass && matches {
t.Errorf("expected %q to not match validPluginName regex", tt.pluginName)
})
}
invalidNames := map[string]string{
"empty": "",
"space": "my plugin",
"colon": "plugin:",
"period": "my.plugin",
"slash": "my/plugin",
"dollar": "$plugin",
"unicode": "plügîn",
}
for name, pluginName := range invalidNames {
t.Run("invalid/"+name, func(t *testing.T) {
if validPluginName.MatchString(pluginName) {
t.Errorf("expected %q to not match validPluginName regex", pluginName)
}
})
}

Loading…
Cancel
Save