|
|
@ -16,12 +16,15 @@ limitations under the License.
|
|
|
|
package installer // import "k8s.io/helm/pkg/plugin/installer"
|
|
|
|
package installer // import "k8s.io/helm/pkg/plugin/installer"
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"archive/tar"
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"compress/gzip"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
"k8s.io/helm/pkg/helm/helmpath"
|
|
|
|
"k8s.io/helm/pkg/helm/helmpath"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -187,3 +190,88 @@ func TestHTTPInstallerUpdate(t *testing.T) {
|
|
|
|
t.Error("update method not implemented for http installer")
|
|
|
|
t.Error("update method not implemented for http installer")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestExtract(t *testing.T) {
|
|
|
|
|
|
|
|
//create a temp home
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cacheDir := filepath.Join(home.Cache(), "plugins", "plugin-key")
|
|
|
|
|
|
|
|
if err := os.MkdirAll(cacheDir, 0755); err != nil {
|
|
|
|
|
|
|
|
t.Fatalf("Could not create %s: %s", cacheDir, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//{"plugin.yaml", "plugin metadata up in here"},
|
|
|
|
|
|
|
|
//{"README.md", "so you know what's upp"},
|
|
|
|
|
|
|
|
//{"script.sh", "echo script"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tarbuf bytes.Buffer
|
|
|
|
|
|
|
|
tw := tar.NewWriter(&tarbuf)
|
|
|
|
|
|
|
|
var files = []struct {
|
|
|
|
|
|
|
|
Name, Body string
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{"../../plugin.yaml", "sneaky plugin metadata"},
|
|
|
|
|
|
|
|
{"README.md", "some text"},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, file := range files {
|
|
|
|
|
|
|
|
hdr := &tar.Header{
|
|
|
|
|
|
|
|
Name: file.Name,
|
|
|
|
|
|
|
|
Typeflag: tar.TypeReg,
|
|
|
|
|
|
|
|
Mode: 0600,
|
|
|
|
|
|
|
|
Size: int64(len(file.Body)),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tw.WriteHeader(hdr); err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := tw.Write([]byte(file.Body)); err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tw.Close(); err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
|
|
gz := gzip.NewWriter(&buf)
|
|
|
|
|
|
|
|
if _, err := gz.Write(tarbuf.Bytes()); err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
gz.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source := "https://repo.localdomain/plugins/fake-plugin-0.0.1.tgz"
|
|
|
|
|
|
|
|
extr, err := NewExtractor(source)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = extr.Extract(&buf, cacheDir); err != nil {
|
|
|
|
|
|
|
|
t.Errorf("Did not expect error but got error: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pluginYAMLFullPath := filepath.Join(cacheDir, "plugin.yaml")
|
|
|
|
|
|
|
|
if _, err := os.Stat(pluginYAMLFullPath); err != nil {
|
|
|
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
|
|
|
t.Errorf("Expected %s to exist but doesn't", pluginYAMLFullPath)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readmeFullPath := filepath.Join(cacheDir, "README.md")
|
|
|
|
|
|
|
|
if _, err := os.Stat(readmeFullPath); err != nil {
|
|
|
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
|
|
|
t.Errorf("Expected %s to exist but doesn't", readmeFullPath)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|