Merge pull request #3247 from mgalgs/missing-repos-help

feat(repo): Improve error message for missing repositories.yaml
pull/3259/head
Matthew Fisher 7 years ago committed by GitHub
commit 51a6f3c326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -55,6 +55,13 @@ func NewRepoFile() *RepoFile {
func LoadRepositoriesFile(path string) (*RepoFile, error) {
b, err := ioutil.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf(
"Couldn't load repositories file (%s).\n"+
"You might need to run `helm init` (or "+
"`helm init --client-only` if tiller is "+
"already installed)", path)
}
return nil, err
}

@ -19,6 +19,7 @@ package repo
import "testing"
import "io/ioutil"
import "os"
import "strings"
const testRepositoriesFile = "testdata/repositories.yaml"
@ -215,3 +216,12 @@ func TestWriteFile(t *testing.T) {
}
}
}
func TestRepoNotExists(t *testing.T) {
_, err := LoadRepositoriesFile("/this/path/does/not/exist.yaml")
if err == nil {
t.Errorf("expected err to be non-nil when path does not exist")
} else if !strings.Contains(err.Error(), "You might need to run `helm init`") {
t.Errorf("expected prompt to run `helm init` when repositories file does not exist")
}
}

Loading…
Cancel
Save