diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 0efac37bc..74948526b 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -246,6 +246,8 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { destPath := filepath.Join(m.ChartPath, "charts") tmpPath := filepath.Join(m.ChartPath, "tmpcharts") + // remove tmpPath after this function returns + defer os.RemoveAll(tmpPath) // Create 'charts' directory if it doesn't already exist. if fi, err := os.Stat(destPath); err != nil { if err := os.MkdirAll(destPath, 0755); err != nil { diff --git a/pkg/downloader/manager_test.go b/pkg/downloader/manager_test.go index 9532cca7c..5039f810f 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*")