1).Remove tmpPath at the return of function.

2).Adding unit test for downloadAll

Signed-off-by: Shakti Raj <shakti.rajpandey@flipkart.com>
pull/8846/head
Shakti Raj 5 years ago
parent 54ea21d245
commit e6fb3d0ab6

@ -246,6 +246,8 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
destPath := filepath.Join(m.ChartPath, "charts") destPath := filepath.Join(m.ChartPath, "charts")
tmpPath := filepath.Join(m.ChartPath, "tmpcharts") 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. // Create 'charts' directory if it doesn't already exist.
if fi, err := os.Stat(destPath); err != nil { if fi, err := os.Stat(destPath); err != nil {
if err := os.MkdirAll(destPath, 0755); err != nil { if err := os.MkdirAll(destPath, 0755); err != nil {

@ -17,6 +17,7 @@ package downloader
import ( import (
"bytes" "bytes"
"os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"testing" "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) { func TestUpdateBeforeBuild(t *testing.T) {
// Set up a fake repo // Set up a fake repo
srv, err := repotest.NewTempServerWithCleanup(t, "testdata/*.tgz*") srv, err := repotest.NewTempServerWithCleanup(t, "testdata/*.tgz*")

Loading…
Cancel
Save