From d44c3d5152146f5279feaae6727311b4ab22b2cc Mon Sep 17 00:00:00 2001 From: Graham Reed Date: Wed, 1 Feb 2023 15:08:38 +0000 Subject: [PATCH] Also follow HELM_PLUGINS when installing from http This is effectively but for the overridden case of `Path()` in `pkg/plugins/installer/http_installer.go`. Well slightly simpler because it can just use the directory already in `base`. The test is copied nearly wholesale from that PR. Signed-off-by: Graham Reed --- pkg/plugin/installer/http_installer.go | 2 +- pkg/plugin/installer/http_installer_test.go | 35 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pkg/plugin/installer/http_installer.go b/pkg/plugin/installer/http_installer.go index 49274f83c..6ee24a37e 100644 --- a/pkg/plugin/installer/http_installer.go +++ b/pkg/plugin/installer/http_installer.go @@ -159,7 +159,7 @@ func (i HTTPInstaller) Path() string { if i.base.Source == "" { return "" } - return helmpath.DataPath("plugins", i.PluginName) + return filepath.Join(i.base.PluginsDirectory, i.PluginName) } // cleanJoin resolves dest as a subpath of root. diff --git a/pkg/plugin/installer/http_installer_test.go b/pkg/plugin/installer/http_installer_test.go index 165007af0..595e52e6f 100644 --- a/pkg/plugin/installer/http_installer_test.go +++ b/pkg/plugin/installer/http_installer_test.go @@ -348,3 +348,38 @@ func TestMediaTypeToExtension(t *testing.T) { } } } + +func TestHttpInstallerPath(t *testing.T) { + tests := []struct { + source string + pluginName string + helmPluginsDir string + expectPath string + }{ + { + source: "", + pluginName: "not-used", + helmPluginsDir: "/helm/data/plugins", + expectPath: "", + }, { + source: "https://github.com/jkroepke/helm-secrets", + pluginName: "helm-http-plugin", + helmPluginsDir: "/helm/data/plugins", + expectPath: "/helm/data/plugins/helm-http-plugin", + }, + } + + for _, tt := range tests { + + os.Setenv("HELM_PLUGINS", tt.helmPluginsDir) + ins := &HTTPInstaller{ + PluginName: tt.pluginName, + base: newBase(tt.source), + } + insPath := ins.Path() + if insPath != tt.expectPath { + t.Errorf("expected name %s, got %s", tt.expectPath, insPath) + } + os.Unsetenv("HELM_PLUGINS") + } +}