From 6344f1d8e995468f9db5f0e9421dc6f09e26b034 Mon Sep 17 00:00:00 2001 From: Sushil Kumar Date: Wed, 3 May 2017 13:37:47 -0700 Subject: [PATCH] Errors out in case requested plugin version does not exists Fixes issues/2384 - helm plugin install installs a default version in case requested version is not available --- pkg/plugin/installer/vcs_installer.go | 4 ++- pkg/plugin/installer/vcs_installer_test.go | 35 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkg/plugin/installer/vcs_installer.go b/pkg/plugin/installer/vcs_installer.go index ce7a93b83..f9f181662 100644 --- a/pkg/plugin/installer/vcs_installer.go +++ b/pkg/plugin/installer/vcs_installer.go @@ -16,6 +16,7 @@ limitations under the License. package installer // import "k8s.io/helm/pkg/plugin/installer" import ( + "fmt" "os" "sort" @@ -112,7 +113,8 @@ func (i *VCSInstaller) solveVersion(repo vcs.Repo) (string, error) { return ver, nil } } - return "", nil + + return "", fmt.Errorf("requested version %q does not exist for plugin %q", i.Version, i.Repo.Remote()) } // setVersion attempts to checkout the version diff --git a/pkg/plugin/installer/vcs_installer_test.go b/pkg/plugin/installer/vcs_installer_test.go index e340bbe5a..53da07ad4 100644 --- a/pkg/plugin/installer/vcs_installer_test.go +++ b/pkg/plugin/installer/vcs_installer_test.go @@ -22,6 +22,8 @@ import ( "k8s.io/helm/pkg/helm/helmpath" + "fmt" + "github.com/Masterminds/vcs" ) @@ -88,3 +90,36 @@ func TestVCSInstaller(t *testing.T) { t.Errorf("expected path '$HELM_HOME/plugins/helm-env', got %q", i.Path()) } } + +func TestVCSInstallerNonExistentVersion(t *testing.T) { + hh, err := ioutil.TempDir("", "helm-home-") + if err != nil { + t.Fatal(err) + } + defer os.Remove(hh) + + home := helmpath.Home(hh) + if err := os.MkdirAll(home.Plugins(), 0755); err != nil { + t.Fatalf("Could not create %s: %s", home.Plugins(), err) + } + + source := "https://github.com/adamreese/helm-env" + version := "0.2.0" + + i, err := NewForSource(source, version, home) + if err != nil { + t.Errorf("unexpected error: %s", err) + } + + // ensure a VCSInstaller was returned + _, ok := i.(*VCSInstaller) + if !ok { + t.Error("expected a VCSInstaller") + } + + if err := Install(i); err == nil { + t.Error("expected error for version does not exists, got none") + } else if err.Error() != fmt.Sprintf("requested version %q does not exist for plugin %q", version, source) { + t.Errorf("expected error for version does not exists, got (%v)", err) + } +}