MCPcopy
hub / github.com/helm/helm / TestLoadCLIPlugins

Function TestLoadCLIPlugins

pkg/cmd/plugin_test.go:86–163  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestLoadCLIPlugins(t *testing.T) {
87 settings.PluginsDirectory = "testdata/helmhome/helm/plugins"
88 settings.RepositoryConfig = "testdata/helmhome/helm/repositories.yaml"
89 settings.RepositoryCache = "testdata/helmhome/helm/repository"
90
91 var (
92 out bytes.Buffer
93 cmd cobra.Command
94 )
95 loadCLIPlugins(&cmd, &out)
96
97 fullEnvOutput := strings.Join([]string{
98 "HELM_PLUGIN_NAME=fullenv",
99 "HELM_PLUGIN_DIR=testdata/helmhome/helm/plugins/fullenv",
100 "HELM_PLUGINS=testdata/helmhome/helm/plugins",
101 "HELM_REPOSITORY_CONFIG=testdata/helmhome/helm/repositories.yaml",
102 "HELM_REPOSITORY_CACHE=testdata/helmhome/helm/repository",
103 "HELM_BIN=" + os.Args[0],
104 }, "\n") + "\n"
105
106 // Test that the YAML file was correctly converted to a command.
107 tests := []struct {
108 use string
109 short string
110 long string
111 expect string
112 args []string
113 code int
114 }{
115 {"args", "echo args", "This echos args", "-a -b -c\n", []string{"-a", "-b", "-c"}, 0},
116 {"echo", "echo stuff", "This echos stuff", "hello\n", []string{}, 0},
117 {"exitwith", "exitwith code", "This exits with the specified exit code", "", []string{"2"}, 2},
118 {"fullenv", "show env vars", "show all env vars", fullEnvOutput, []string{}, 0},
119 {"shortenv", "env stuff", "show the env", "HELM_PLUGIN_NAME=shortenv\n", []string{}, 0},
120 // "noversion": plugin is invalid, and should not be loaded
121 }
122
123 pluginCmds := cmd.Commands()
124
125 require.Len(t, pluginCmds, len(tests), "Expected %d plugins, got %d", len(tests), len(pluginCmds))
126
127 for i := range pluginCmds {
128 out.Reset()
129 tt := tests[i]
130 pluginCmd := pluginCmds[i]
131 t.Run(fmt.Sprintf("%s-%d", pluginCmd.Name(), i), func(t *testing.T) {
132 out.Reset()
133 if pluginCmd.Use != tt.use {
134 t.Errorf("%d: Expected Use=%q, got %q", i, tt.use, pluginCmd.Use)
135 }
136 if pluginCmd.Short != tt.short {
137 t.Errorf("%d: Expected Use=%q, got %q", i, tt.short, pluginCmd.Short)
138 }
139 if pluginCmd.Long != tt.long {
140 t.Errorf("%d: Expected Use=%q, got %q", i, tt.long, pluginCmd.Long)
141 }
142
143 // Currently, plugins assume a Linux subsystem. Skip the execution

Callers

nothing calls this directly

Calls 5

loadCLIPluginsFunction · 0.85
RunMethod · 0.65
NameMethod · 0.65
LenMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…