From b296cbef6c8ad43de4f921c680c8df77fdd1cc84 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Sun, 16 Nov 2025 11:49:08 +0100 Subject: [PATCH] test: split tests between valid and invalid Signed-off-by: Benoit Tigeot --- internal/plugin/plugin_test.go | 58 +++++++++++++++++----------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/internal/plugin/plugin_test.go b/internal/plugin/plugin_test.go index d911942b9..d71cec2e9 100644 --- a/internal/plugin/plugin_test.go +++ b/internal/plugin/plugin_test.go @@ -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) } }) }