(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func 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 |
| 48 | version: 1.2.3 |
| 49 | description: Test plugin |
| 50 | command: $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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…