|
|
@ -18,6 +18,7 @@ package installer // import "k8s.io/helm/pkg/plugin/installer"
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/base64"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
"k8s.io/helm/pkg/helm/helmpath"
|
|
|
|
"k8s.io/helm/pkg/helm/helmpath"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
@ -29,9 +30,10 @@ var _ Installer = new(HTTPInstaller)
|
|
|
|
// Fake http client
|
|
|
|
// Fake http client
|
|
|
|
type TestHTTPGetter struct {
|
|
|
|
type TestHTTPGetter struct {
|
|
|
|
MockResponse *bytes.Buffer
|
|
|
|
MockResponse *bytes.Buffer
|
|
|
|
|
|
|
|
MockError error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *TestHTTPGetter) Get(href string) (*bytes.Buffer, error) { return t.MockResponse, nil }
|
|
|
|
func (t *TestHTTPGetter) Get(href string) (*bytes.Buffer, error) { return t.MockResponse, t.MockError }
|
|
|
|
|
|
|
|
|
|
|
|
// Fake plugin tarball data
|
|
|
|
// Fake plugin tarball data
|
|
|
|
var fakePluginB64 = "H4sIAKRj51kAA+3UX0vCUBgGcC9jn+Iwuk3Peza3GeyiUlJQkcogCOzgli7dJm4TvYk+a5+k479UqquUCJ/fLs549sLO2TnvWnJa9aXnjwujYdYLovxMhsPcfnHOLdNkOXthM/IVQQYjg2yyLLJ4kXGhLp5j0z3P41tZksqxmspL3B/O+j/XtZu1y8rdYzkOZRCxduKPk53ny6Wwz/GfIIf1As8lxzGJSmoHNLJZphKHG4YpTCE0wVk3DULfpSJ3DMMqkj3P5JfMYLdX1Vr9Ie/5E5cstcdC8K04iGLX5HaJuKpWL17F0TCIBi5pf/0pjtLhun5j3f9v6r7wfnI/H0eNp9d1/5P6Gez0vzo7wsoxfrAZbTny/o9k6J8z/VkO/LPlWdC1iVpbEEcq5nmeJ13LEtmbV0k2r2PrOs9PuuNglC5rL1Y5S/syXRQmutaNw1BGnnp8Wq3UG51WvX1da3bKtZtCN/R09DwAAAAAAAAAAAAAAAAAAADAb30AoMczDwAoAAA="
|
|
|
|
var fakePluginB64 = "H4sIAKRj51kAA+3UX0vCUBgGcC9jn+Iwuk3Peza3GeyiUlJQkcogCOzgli7dJm4TvYk+a5+k479UqquUCJ/fLs549sLO2TnvWnJa9aXnjwujYdYLovxMhsPcfnHOLdNkOXthM/IVQQYjg2yyLLJ4kXGhLp5j0z3P41tZksqxmspL3B/O+j/XtZu1y8rdYzkOZRCxduKPk53ny6Wwz/GfIIf1As8lxzGJSmoHNLJZphKHG4YpTCE0wVk3DULfpSJ3DMMqkj3P5JfMYLdX1Vr9Ie/5E5cstcdC8K04iGLX5HaJuKpWL17F0TCIBi5pf/0pjtLhun5j3f9v6r7wfnI/H0eNp9d1/5P6Gez0vzo7wsoxfrAZbTny/o9k6J8z/VkO/LPlWdC1iVpbEEcq5nmeJ13LEtmbV0k2r2PrOs9PuuNglC5rL1Y5S/syXRQmutaNw1BGnnp8Wq3UG51WvX1da3bKtZtCN/R09DwAAAAAAAAAAAAAAAAAAADAb30AoMczDwAoAAA="
|
|
|
@ -69,10 +71,10 @@ func TestHTTPInstaller(t *testing.T) {
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ensure a HttpInstaller was returned
|
|
|
|
// ensure a HTTPInstaller was returned
|
|
|
|
httpInstaller, ok := i.(*HTTPInstaller)
|
|
|
|
httpInstaller, ok := i.(*HTTPInstaller)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
t.Error("expected a HttpInstaller")
|
|
|
|
t.Error("expected a HTTPInstaller")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// inject fake http client responding with minimal plugin tarball
|
|
|
|
// inject fake http client responding with minimal plugin tarball
|
|
|
@ -101,3 +103,87 @@ func TestHTTPInstaller(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestHTTPInstallerNonExistentVersion(t *testing.T) {
|
|
|
|
|
|
|
|
source := "https://repo.localdomain/plugins/fake-plugin-0.0.2.tar.gz"
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i, err := NewForSource(source, "0.0.2", home)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ensure a HTTPInstaller was returned
|
|
|
|
|
|
|
|
httpInstaller, ok := i.(*HTTPInstaller)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
t.Error("expected a HTTPInstaller")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// inject fake http client responding with error
|
|
|
|
|
|
|
|
httpInstaller.getter = &TestHTTPGetter{
|
|
|
|
|
|
|
|
MockError: fmt.Errorf("failed to download plugin for some reason"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// attempt to install the plugin
|
|
|
|
|
|
|
|
if err := Install(i); err == nil {
|
|
|
|
|
|
|
|
t.Error("expected error from http client")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestHTTPInstallerUpdate(t *testing.T) {
|
|
|
|
|
|
|
|
source := "https://repo.localdomain/plugins/fake-plugin-0.0.1.tar.gz"
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i, err := NewForSource(source, "0.0.1", home)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Errorf("unexpected error: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ensure a HTTPInstaller was returned
|
|
|
|
|
|
|
|
httpInstaller, ok := i.(*HTTPInstaller)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
t.Error("expected a HTTPInstaller")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// inject fake http client responding with minimal plugin tarball
|
|
|
|
|
|
|
|
mockTgz, err := base64.StdEncoding.DecodeString(fakePluginB64)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Fatalf("Could not decode fake tgz plugin: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
httpInstaller.getter = &TestHTTPGetter{
|
|
|
|
|
|
|
|
MockResponse: bytes.NewBuffer(mockTgz),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// install the plugin before updating
|
|
|
|
|
|
|
|
if err := Install(i); err != nil {
|
|
|
|
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if i.Path() != home.Path("plugins", "fake-plugin") {
|
|
|
|
|
|
|
|
t.Errorf("expected path '$HELM_HOME/plugins/fake-plugin', got %q", i.Path())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update plugin, should fail because it is not implemented
|
|
|
|
|
|
|
|
if err := Update(i); err == nil {
|
|
|
|
|
|
|
|
t.Error("update method not implemented for http installer")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|