From 70c07409d9aed558d2e775e516960048ae0f2596 Mon Sep 17 00:00:00 2001 From: Shakti Raj Date: Wed, 24 Feb 2021 15:23:32 -0500 Subject: [PATCH] test(pkg/downloader): Adding unit test for downloadAll Signed-off-by: Shakti Raj --- pkg/downloader/manager_test.go | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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*")