github.com/sgoings/helm@v2.0.0-alpha.2.0.20170406211108-734e92851ac3+incompatible/pkg/plugin/installer/vcs_installer_test.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package installer // import "k8s.io/helm/pkg/plugin/installer" 17 18 import ( 19 "io/ioutil" 20 "os" 21 "testing" 22 23 "k8s.io/helm/pkg/helm/helmpath" 24 25 "github.com/Masterminds/vcs" 26 ) 27 28 var _ Installer = new(VCSInstaller) 29 30 type testRepo struct { 31 local, remote, current string 32 tags, branches []string 33 err error 34 vcs.Repo 35 } 36 37 func (r *testRepo) LocalPath() string { return r.local } 38 func (r *testRepo) Remote() string { return r.remote } 39 func (r *testRepo) Update() error { return r.err } 40 func (r *testRepo) Get() error { return r.err } 41 func (r *testRepo) IsReference(string) bool { return false } 42 func (r *testRepo) Tags() ([]string, error) { return r.tags, r.err } 43 func (r *testRepo) Branches() ([]string, error) { return r.branches, r.err } 44 func (r *testRepo) UpdateVersion(version string) error { 45 r.current = version 46 return r.err 47 } 48 49 func TestVCSInstaller(t *testing.T) { 50 hh, err := ioutil.TempDir("", "helm-home-") 51 if err != nil { 52 t.Fatal(err) 53 } 54 defer os.Remove(hh) 55 56 home := helmpath.Home(hh) 57 if err := os.MkdirAll(home.Plugins(), 0755); err != nil { 58 t.Fatalf("Could not create %s: %s", home.Plugins(), err) 59 } 60 61 source := "https://github.com/adamreese/helm-env" 62 repo := &testRepo{ 63 local: "../testdata/plugdir/echo", 64 tags: []string{"0.1.0", "0.1.1"}, 65 } 66 67 i, err := NewForSource(source, "~0.1.0", home) 68 if err != nil { 69 t.Errorf("unexpected error: %s", err) 70 } 71 72 // ensure a VCSInstaller was returned 73 vcsInstaller, ok := i.(*VCSInstaller) 74 if !ok { 75 t.Error("expected a VCSInstaller") 76 } 77 78 // set the testRepo in the VCSInstaller 79 vcsInstaller.Repo = repo 80 81 if err := Install(i); err != nil { 82 t.Error(err) 83 } 84 if repo.current != "0.1.1" { 85 t.Errorf("expected version '0.1.1', got %q", repo.current) 86 } 87 if i.Path() != home.Path("plugins", "helm-env") { 88 t.Errorf("expected path '$HELM_HOME/plugins/helm-env', got %q", i.Path()) 89 } 90 }