github.com/amtisyAts/helm@v2.17.0+incompatible/cmd/helm/installer/init_test.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package installer // import "k8s.io/helm/cmd/helm/installer" 18 19 import ( 20 "bytes" 21 "io/ioutil" 22 "os" 23 "testing" 24 25 helm_env "k8s.io/helm/pkg/helm/environment" 26 "k8s.io/helm/pkg/helm/helmpath" 27 ) 28 29 func TestInitialize(t *testing.T) { 30 home, err := ioutil.TempDir("", "helm_home") 31 if err != nil { 32 t.Fatal(err) 33 } 34 defer os.RemoveAll(home) 35 36 b := bytes.NewBuffer(nil) 37 hh := helmpath.Home(home) 38 39 settings := helm_env.EnvSettings{ 40 Home: hh, 41 } 42 stableRepositoryURL := "https://kubernetes-charts.storage.googleapis.com" 43 localRepositoryURL := "http://127.0.0.1:8879/charts" 44 45 if err := Initialize(hh, b, false, settings, stableRepositoryURL, localRepositoryURL); err != nil { 46 t.Error(err) 47 } 48 49 expectedDirs := []string{hh.String(), hh.Repository(), hh.Cache(), hh.LocalRepository()} 50 for _, dir := range expectedDirs { 51 if fi, err := os.Stat(dir); err != nil { 52 t.Errorf("%s", err) 53 } else if !fi.IsDir() { 54 t.Errorf("%s is not a directory", fi) 55 } 56 } 57 58 if fi, err := os.Stat(hh.RepositoryFile()); err != nil { 59 t.Error(err) 60 } else if fi.IsDir() { 61 t.Errorf("%s should not be a directory", fi) 62 } 63 64 if fi, err := os.Stat(hh.LocalRepository(LocalRepositoryIndexFile)); err != nil { 65 t.Errorf("%s", err) 66 } else if fi.IsDir() { 67 t.Errorf("%s should not be a directory", fi) 68 } 69 } 70 71 func TestInitializeWithoutRepos(t *testing.T) { 72 home, err := ioutil.TempDir("", "helm_home") 73 if err != nil { 74 t.Fatal(err) 75 } 76 defer os.RemoveAll(home) 77 78 b := bytes.NewBuffer(nil) 79 hh := helmpath.Home(home) 80 81 if err := InitializeWithoutRepos(hh, b); err != nil { 82 t.Error(err) 83 } 84 85 expectedDirs := []string{hh.String(), hh.Repository(), hh.Cache()} 86 for _, dir := range expectedDirs { 87 if fi, err := os.Stat(dir); err != nil { 88 t.Errorf("%s", err) 89 } else if !fi.IsDir() { 90 t.Errorf("%s is not a directory", fi) 91 } 92 } 93 94 if fi, err := os.Stat(hh.RepositoryFile()); err != nil { 95 t.Error(err) 96 } else if fi.IsDir() { 97 t.Errorf("%s should not be a directory", fi) 98 } 99 100 // Make sure the local repository was not added 101 if fi, err := os.Stat(hh.LocalRepository(LocalRepositoryIndexFile)); err == nil { 102 t.Errorf("%s should not be found", fi) 103 } 104 } 105 106 func TestEnsureHome(t *testing.T) { 107 home, err := ioutil.TempDir("", "helm_home") 108 if err != nil { 109 t.Fatal(err) 110 } 111 defer os.RemoveAll(home) 112 113 b := bytes.NewBuffer(nil) 114 hh := helmpath.Home(home) 115 116 settings := helm_env.EnvSettings{ 117 Home: hh, 118 } 119 stableRepositoryURL := "https://kubernetes-charts.storage.googleapis.com" 120 localRepositoryURL := "http://127.0.0.1:8879/charts" 121 122 if err := ensureDirectories(hh, b); err != nil { 123 t.Error(err) 124 } 125 if err := ensureDefaultRepos(hh, b, false, settings, stableRepositoryURL, localRepositoryURL); err != nil { 126 t.Error(err) 127 } 128 if err := ensureDefaultRepos(hh, b, true, settings, stableRepositoryURL, localRepositoryURL); err != nil { 129 t.Error(err) 130 } 131 if err := ensureRepoFileFormat(hh.RepositoryFile(), b); err != nil { 132 t.Error(err) 133 } 134 135 expectedDirs := []string{hh.String(), hh.Repository(), hh.Cache(), hh.LocalRepository()} 136 for _, dir := range expectedDirs { 137 if fi, err := os.Stat(dir); err != nil { 138 t.Errorf("%s", err) 139 } else if !fi.IsDir() { 140 t.Errorf("%s is not a directory", fi) 141 } 142 } 143 144 if fi, err := os.Stat(hh.RepositoryFile()); err != nil { 145 t.Error(err) 146 } else if fi.IsDir() { 147 t.Errorf("%s should not be a directory", fi) 148 } 149 150 if fi, err := os.Stat(hh.LocalRepository(LocalRepositoryIndexFile)); err != nil { 151 t.Errorf("%s", err) 152 } else if fi.IsDir() { 153 t.Errorf("%s should not be a directory", fi) 154 } 155 }