From 8c1cae6dc9d5ca349590f50d736f1b637e9fb6fc Mon Sep 17 00:00:00 2001 From: Sushil Kumar Date: Sat, 6 May 2017 15:43:29 -0700 Subject: [PATCH] Added tests for new methods for plugin update --- pkg/plugin/installer/vcs_installer_test.go | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/pkg/plugin/installer/vcs_installer_test.go b/pkg/plugin/installer/vcs_installer_test.go index 081598c7c..81c57aa3f 100644 --- a/pkg/plugin/installer/vcs_installer_test.go +++ b/pkg/plugin/installer/vcs_installer_test.go @@ -97,6 +97,20 @@ func TestVCSInstaller(t *testing.T) { } else if err.Error() != "plugin already exists" { t.Errorf("expected error for plugin exists, got (%v)", err) } + + //Testing FindSource method, expect error because plugin code is not a cloned repository + if _, err := FindSource(i.Path(), home); err == nil { + t.Error("expected error for inability to find plugin source, got none") + } else if err.Error() != "cannot get information about plugin source" { + t.Errorf("expected error for inability to find plugin source, got (%v)", err) + } + + // Testing update for error + if err := Update(i); err == nil { + t.Error("expected error for plugin does not exists, got none") + } else if err.Error() != "plugin does not exists" { + t.Errorf("expected error for plugin does not exists, got (%v)", err) + } } func TestVCSInstallerNonExistentVersion(t *testing.T) { @@ -131,3 +145,66 @@ func TestVCSInstallerNonExistentVersion(t *testing.T) { t.Errorf("expected error for version does not exists, got (%v)", err) } } +func TestVCSInstallerUpdate(t *testing.T) { + + hh, err := ioutil.TempDir("", "helm-home-") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(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" + + i, err := NewForSource(source, "", 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 := Update(i); err == nil { + t.Error("expected error for plugin does not exists, got none") + } else if err.Error() != "plugin does not exists" { + t.Errorf("expected error for plugin does not exists, got (%v)", err) + } + + // Install plugin before update + if err := Install(i); err != nil { + t.Error(err) + } + + // Test FindSource method for positive result + pluginInfo, err := FindSource(i.Path(), home) + if err != nil { + t.Error(err) + } + + repoRemote := pluginInfo.(*VCSInstaller).Repo.Remote() + if repoRemote != source { + t.Errorf("invalid source found, expected %q got %q", source, repoRemote) + } + + // Update plugin + if err := Update(i); err != nil { + t.Error(err) + } + + // Test update failure + os.Remove(filepath.Join(i.Path(), "plugin.yaml")) + // Testing update for error + if err := Update(i); err == nil { + t.Error("expected error for plugin metadata missing, got none") + } else if err.Error() != "plugin metadata (plugin.yaml) missing" { + t.Errorf("expected error for plugin metadata missing, got (%v)", err) + } + +}