MCPcopy
hub / github.com/helm/helm / TestPluginUninstallCleansUpVersionedFiles

Function TestPluginUninstallCleansUpVersionedFiles

pkg/cmd/plugin_uninstall_test.go:29–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestPluginUninstallCleansUpVersionedFiles(t *testing.T) {
30 ensure.HelmHome(t)
31
32 // Create a fake plugin directory structure in a temp directory
33 pluginsDir := t.TempDir()
34 t.Setenv("HELM_PLUGINS", pluginsDir)
35
36 // Create a new settings instance that will pick up the environment variable
37 testSettings := cli.New()
38 pluginName := "test-plugin"
39
40 // Create plugin directory
41 pluginDir := filepath.Join(pluginsDir, pluginName)
42 if err := os.MkdirAll(pluginDir, 0755); err != nil {
43 t.Fatal(err)
44 }
45
46 // Create plugin.yaml
47 pluginYAML := `name: test-plugin
48version: 1.2.3
49description: Test plugin
50command: $HELM_PLUGIN_DIR/test-plugin
51`
52 if err := os.WriteFile(filepath.Join(pluginDir, "plugin.yaml"), []byte(pluginYAML), 0644); err != nil {
53 t.Fatal(err)
54 }
55
56 // Create versioned tarball and provenance files
57 tarballFile := filepath.Join(pluginsDir, "test-plugin-1.2.3.tgz")
58 provFile := filepath.Join(pluginsDir, "test-plugin-1.2.3.tgz.prov")
59 otherVersionTarball := filepath.Join(pluginsDir, "test-plugin-2.0.0.tgz")
60
61 if err := os.WriteFile(tarballFile, []byte("fake tarball"), 0644); err != nil {
62 t.Fatal(err)
63 }
64 if err := os.WriteFile(provFile, []byte("fake provenance"), 0644); err != nil {
65 t.Fatal(err)
66 }
67 // Create another version that should NOT be removed
68 if err := os.WriteFile(otherVersionTarball, []byte("other version"), 0644); err != nil {
69 t.Fatal(err)
70 }
71
72 // Load the plugin
73 p, err := plugin.LoadDir(pluginDir)
74 if err != nil {
75 t.Fatal(err)
76 }
77
78 // Create a test uninstall function that uses our test settings
79 testUninstallPlugin := func(plugin plugin.Plugin) error {
80 if err := os.RemoveAll(plugin.Dir()); err != nil {
81 return err
82 }
83
84 // Clean up versioned tarball and provenance files from test HELM_PLUGINS directory
85 pluginName := plugin.Metadata().Name
86 pluginVersion := plugin.Metadata().Version

Callers

nothing calls this directly

Calls 9

HelmHomeFunction · 0.92
NewFunction · 0.92
LoadDirFunction · 0.92
MetadataStruct · 0.92
FatalMethod · 0.80
DirMethod · 0.65
WriteFileMethod · 0.45
RemoveMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…