diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index c2aba8417..b75d3b8f0 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -247,7 +247,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { } destPath := filepath.Join(m.ChartPath, "charts") - tmpPath, err := ioutil.TempDir("", "tmpcharts-*") + tmpPath, err := ioutil.TempDir(m.ChartPath, "tmpcharts-*") if err != nil { return errors.Wrap(err, "failed to create tmpcharts dir") } diff --git a/pkg/downloader/manager_test.go b/pkg/downloader/manager_test.go index ef3ec7ad8..7f92b6dfc 100644 --- a/pkg/downloader/manager_test.go +++ b/pkg/downloader/manager_test.go @@ -17,11 +17,14 @@ package downloader import ( "bytes" + "io/ioutil" "os" "path/filepath" "reflect" "testing" + "helm.sh/helm/v3/internal/third_party/dep/fs" + "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/getter" @@ -188,22 +191,29 @@ func TestDownloadAll(t *testing.T) { // 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) + testDir, _ := ioutil.TempDir("", "helm-manager-test-*") m := &Manager{ Out: b, RepositoryConfig: repoConfig, RepositoryCache: repoCache, + ChartPath: testDir, } - // remove charts folder at the end of test - defer os.RemoveAll("charts") + // remove Chart folder at the end of test + defer os.RemoveAll(testDir) + + testChartPath := "./testdata/signtest" + + // Copy the test chart to our testing area + fs.CopyDir(testChartPath, filepath.Join(testDir, testChartPath)) // 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"}, + {Name: "local-dep", Repository: "file://" + testChartPath, Version: "0.1.0"}, }) if err != nil { t.Fatal(err) } - // this will copy charts directory content to tmp directory and recreates new charts + // this will copy charts directory content to tmp directory and recreate new charts err = m.downloadAll([]*chart.Dependency{ {Name: "local-subchart", Repository: ""}, }) @@ -211,7 +221,7 @@ func TestDownloadAll(t *testing.T) { t.Fatal(err) } err = m.downloadAll([]*chart.Dependency{ - {Name: "local-dep", Repository: "file://./testdata/signtest", Version: "0.1.0"}, + {Name: "local-dep", Repository: "file://" + testChartPath, Version: "0.1.0"}, }) if err != nil { t.Fatal(err)