github.com/vtuson/helm@v2.8.2+incompatible/cmd/helm/dependency_build_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 main 17 18 import ( 19 "bytes" 20 "os" 21 "path/filepath" 22 "strings" 23 "testing" 24 25 "k8s.io/helm/pkg/helm/helmpath" 26 "k8s.io/helm/pkg/provenance" 27 "k8s.io/helm/pkg/repo" 28 "k8s.io/helm/pkg/repo/repotest" 29 ) 30 31 func TestDependencyBuildCmd(t *testing.T) { 32 hh, err := tempHelmHome(t) 33 if err != nil { 34 t.Fatal(err) 35 } 36 cleanup := resetEnv() 37 defer func() { 38 os.RemoveAll(hh.String()) 39 cleanup() 40 }() 41 42 settings.Home = hh 43 44 srv := repotest.NewServer(hh.String()) 45 defer srv.Stop() 46 _, err = srv.CopyCharts("testdata/testcharts/*.tgz") 47 if err != nil { 48 t.Fatal(err) 49 } 50 51 chartname := "depbuild" 52 if err := createTestingChart(hh.String(), chartname, srv.URL()); err != nil { 53 t.Fatal(err) 54 } 55 56 out := bytes.NewBuffer(nil) 57 dbc := &dependencyBuildCmd{out: out} 58 dbc.helmhome = helmpath.Home(hh) 59 dbc.chartpath = filepath.Join(hh.String(), chartname) 60 61 // In the first pass, we basically want the same results as an update. 62 if err := dbc.run(); err != nil { 63 output := out.String() 64 t.Logf("Output: %s", output) 65 t.Fatal(err) 66 } 67 68 output := out.String() 69 if !strings.Contains(output, `update from the "test" chart repository`) { 70 t.Errorf("Repo did not get updated\n%s", output) 71 } 72 73 // Make sure the actual file got downloaded. 74 expect := filepath.Join(hh.String(), chartname, "charts/reqtest-0.1.0.tgz") 75 if _, err := os.Stat(expect); err != nil { 76 t.Fatal(err) 77 } 78 79 // In the second pass, we want to remove the chart's request dependency, 80 // then see if it restores from the lock. 81 lockfile := filepath.Join(hh.String(), chartname, "requirements.lock") 82 if _, err := os.Stat(lockfile); err != nil { 83 t.Fatal(err) 84 } 85 if err := os.RemoveAll(expect); err != nil { 86 t.Fatal(err) 87 } 88 89 if err := dbc.run(); err != nil { 90 output := out.String() 91 t.Logf("Output: %s", output) 92 t.Fatal(err) 93 } 94 95 // Now repeat the test that the dependency exists. 96 expect = filepath.Join(hh.String(), chartname, "charts/reqtest-0.1.0.tgz") 97 if _, err := os.Stat(expect); err != nil { 98 t.Fatal(err) 99 } 100 101 // Make sure that build is also fetching the correct version. 102 hash, err := provenance.DigestFile(expect) 103 if err != nil { 104 t.Fatal(err) 105 } 106 107 i, err := repo.LoadIndexFile(dbc.helmhome.CacheIndex("test")) 108 if err != nil { 109 t.Fatal(err) 110 } 111 112 reqver := i.Entries["reqtest"][0] 113 if h := reqver.Digest; h != hash { 114 t.Errorf("Failed hash match: expected %s, got %s", hash, h) 115 } 116 if v := reqver.Version; v != "0.1.0" { 117 t.Errorf("mismatched versions. Expected %q, got %q", "0.1.0", v) 118 } 119 120 }