Repository: helm/helm
File: internal/plugin/plugin_test.go (Go)

Code before:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package plugin

import (
	"testing"

	"helm.sh/helm/v4/internal/plugin/schema"
)

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},
	}

	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)

Review comment (bug):
perhaps separate into two tables/loops?

```
testsSuccess := map[name]struct {
		pluginName string
} {
   ...
}

for testName, tt := range testsSuccess {
		t.Run(testName, func(t *testing.T) {
			assert.True(t, validPluginName.MatchString(tt.pluginName))
		})
	}

testsFail := map[name]struct {
		pluginName string
} {
   ...
}
for testName, tt := range testsFail {
		t.Run(testName, func(t *testing.T) {
            assert.False(t, validPluginName.MatchString(tt.pluginName))
		})
	}


Code after:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package plugin

import (
	"testing"

	"helm.sh/helm/v4/internal/plugin/schema"
)

func TestValidPluginName(t *testing.T) {
	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 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)
			}
		})
	}

	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 {