From 5b1e1a80d3c36800693514af3b9f5577d817deae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Lindh=C3=A9?= Date: Sun, 5 Apr 2020 11:51:06 +0200 Subject: [PATCH] Write tests for multi repo removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andreas Lindhé --- cmd/helm/repo_remove_test.go | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/cmd/helm/repo_remove_test.go b/cmd/helm/repo_remove_test.go index fec6f4fca..be4f9e240 100644 --- a/cmd/helm/repo_remove_test.go +++ b/cmd/helm/repo_remove_test.go @@ -81,6 +81,53 @@ func TestRepoRemove(t *testing.T) { if f.Has(testRepoName) { t.Errorf("%s was not successfully removed from repositories list", testRepoName) } + + // Test removal of multiple repos in one go + var testRepoNames = []string{"foo", "bar", "baz"} + b2 := bytes.NewBuffer(nil) + idxs := make(map[string][]string, len(testRepoNames)) + + for _, repoName := range testRepoNames { + o := &repoAddOptions{ + name: repoName, + url: ts.URL(), + repoFile: repoFile, + } + + if err := o.run(os.Stderr); err != nil { + t.Error(err) + } + + cacheIndex, cacheChart := indexing(b, rootDir, repoName) + idxs[repoName] = []string{cacheIndex, cacheChart} + + } + + multiRmOpts := repoRemoveOptions{ + names: testRepoNames, + repoFile: repoFile, + repoCache: rootDir, + } + + if err := multiRmOpts.run(b2); err != nil { + t.Errorf("Error removing list of repos from repositories: %q", testRepoNames) + } + if !strings.Contains(b2.String(), "has been removed") { + t.Errorf("Unexpected output: %s", b.String()) + } + + for _, repoName := range testRepoNames { + f, err := repo.LoadFile(repoFile) + if err != nil { + t.Error(err) + } + if f.Has(repoName) { + t.Errorf("%s was not successfully removed from repositories list", repoName) + } + cacheIndex := idxs[repoName][0] + cacheChart := idxs[repoName][1] + testIndices(t, cacheIndex, cacheChart, repoName) + } } func indexing(buf *bytes.Buffer, rootDir string, repoName string) (cacheIndexFile string, cacheChartsFile string) {