MCPcopy Index your code
hub / github.com/helm/helm / TestValidatePluginName

Function TestValidatePluginName

internal/plugin/installer/plugin_structure_test.go:101–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

99}
100
101func TestValidatePluginName(t *testing.T) {
102 tests := []struct {
103 name string
104 setup func(dir string) error
105 pluginRoot string
106 expectedName string
107 expectError bool
108 }{
109 {
110 name: "matching directory and plugin name",
111 setup: func(dir string) error {
112 subdir := filepath.Join(dir, "my-plugin")
113 if err := os.MkdirAll(subdir, 0755); err != nil {
114 return err
115 }
116 yaml := `name: my-plugin
117version: 1.0.0
118usage: test
119description: test`
120 return os.WriteFile(filepath.Join(subdir, "plugin.yaml"), []byte(yaml), 0644)
121 },
122 pluginRoot: "my-plugin",
123 expectedName: "my-plugin",
124 expectError: false,
125 },
126 {
127 name: "different directory and plugin name",
128 setup: func(dir string) error {
129 subdir := filepath.Join(dir, "wrong-name")
130 if err := os.MkdirAll(subdir, 0755); err != nil {
131 return err
132 }
133 yaml := `name: my-plugin
134version: 1.0.0
135usage: test
136description: test`
137 return os.WriteFile(filepath.Join(subdir, "plugin.yaml"), []byte(yaml), 0644)
138 },
139 pluginRoot: "wrong-name",
140 expectedName: "wrong-name",
141 expectError: false, // Currently we don't error on mismatch
142 },
143 }
144
145 for _, tt := range tests {
146 t.Run(tt.name, func(t *testing.T) {
147 dir := t.TempDir()
148 if err := tt.setup(dir); err != nil {
149 t.Fatalf("Setup failed: %v", err)
150 }
151
152 pluginRoot := filepath.Join(dir, tt.pluginRoot)
153 err := validatePluginName(pluginRoot, tt.expectedName)
154 if tt.expectError {
155 if err == nil {
156 t.Error("Expected error but got none")
157 }
158 } else {

Callers

nothing calls this directly

Calls 5

validatePluginNameFunction · 0.85
FatalfMethod · 0.80
RunMethod · 0.65
WriteFileMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…