diff --git a/pkg/downloader/manager_test.go b/pkg/downloader/manager_test.go index fc8d9abb2..ef3ec7ad8 100644 --- a/pkg/downloader/manager_test.go +++ b/pkg/downloader/manager_test.go @@ -17,6 +17,7 @@ package downloader import ( "bytes" + "os" "path/filepath" "reflect" "testing" @@ -181,6 +182,42 @@ func TestGetRepoNames(t *testing.T) { } } +func TestDownloadAll(t *testing.T) { + // If we run downloadAll without defer than this test will fail + // 1st downloadAll creates charts folder + // 2nd downloadAll copies existing charts to tmpcharts and fails but tmpcharts folder will be removed + // 3rd downloadAll again runs with another dependency + b := bytes.NewBuffer(nil) + m := &Manager{ + Out: b, + RepositoryConfig: repoConfig, + RepositoryCache: repoCache, + } + // remove charts folder at the end of test + defer os.RemoveAll("charts") + + // call downloadAll so that it will create charts directory + err := m.downloadAll([]*chart.Dependency{ + {Name: "local-dep", Repository: "file://./testdata/signtest", Version: "0.1.0"}, + }) + if err != nil { + t.Fatal(err) + } + // this will copy charts directory content to tmp directory and recreates new charts + err = m.downloadAll([]*chart.Dependency{ + {Name: "local-subchart", Repository: ""}, + }) + if err == nil { + t.Fatal(err) + } + err = m.downloadAll([]*chart.Dependency{ + {Name: "local-dep", Repository: "file://./testdata/signtest", Version: "0.1.0"}, + }) + if err != nil { + t.Fatal(err) + } +} + func TestUpdateBeforeBuild(t *testing.T) { // Set up a fake repo srv, err := repotest.NewTempServerWithCleanup(t, "testdata/*.tgz*")