chore(pkg/downloader): use chart directory in ioutil.TempDir

Create tmpcharts-[random-suffix] under Chart directory when updating deps

Signed-off-by: gzur <gzur@gzur.org>
pull/9393/head
gzur 5 years ago
parent 70c07409d9
commit 5dee27c2e8

@ -247,7 +247,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
} }
destPath := filepath.Join(m.ChartPath, "charts") destPath := filepath.Join(m.ChartPath, "charts")
tmpPath, err := ioutil.TempDir("", "tmpcharts-*") tmpPath, err := ioutil.TempDir(m.ChartPath, "tmpcharts-*")
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create tmpcharts dir") return errors.Wrap(err, "failed to create tmpcharts dir")
} }

@ -17,11 +17,14 @@ package downloader
import ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"testing" "testing"
"helm.sh/helm/v3/internal/third_party/dep/fs"
"helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/getter" "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 // 2nd downloadAll copies existing charts to tmpcharts and fails but tmpcharts folder will be removed
// 3rd downloadAll again runs with another dependency // 3rd downloadAll again runs with another dependency
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
testDir, _ := ioutil.TempDir("", "helm-manager-test-*")
m := &Manager{ m := &Manager{
Out: b, Out: b,
RepositoryConfig: repoConfig, RepositoryConfig: repoConfig,
RepositoryCache: repoCache, RepositoryCache: repoCache,
ChartPath: testDir,
} }
// remove charts folder at the end of test // remove Chart folder at the end of test
defer os.RemoveAll("charts") 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 // call downloadAll so that it will create charts directory
err := m.downloadAll([]*chart.Dependency{ 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 { if err != nil {
t.Fatal(err) 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{ err = m.downloadAll([]*chart.Dependency{
{Name: "local-subchart", Repository: ""}, {Name: "local-subchart", Repository: ""},
}) })
@ -211,7 +221,7 @@ func TestDownloadAll(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = m.downloadAll([]*chart.Dependency{ 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 { if err != nil {
t.Fatal(err) t.Fatal(err)

Loading…
Cancel
Save