From 4f8e67572b3e9ab000a3927ddf23f45f1125416c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Lindh=C3=A9?= Date: Tue, 7 Apr 2020 19:03:46 +0200 Subject: [PATCH] Lift out buffer from indexing function and add comments 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 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/helm/repo_remove_test.go b/cmd/helm/repo_remove_test.go index be4f9e240..dbba7f5de 100644 --- a/cmd/helm/repo_remove_test.go +++ b/cmd/helm/repo_remove_test.go @@ -62,7 +62,10 @@ func TestRepoRemove(t *testing.T) { t.Error(err) } - idx, idx2 := indexing(b, rootDir, testRepoName) + idx, idx2 := indexing(rootDir, testRepoName) + + // Reset the buffer before running repo remove + b.Reset() if err := rmOpts.run(b); err != nil { t.Errorf("Error removing %s from repositories", testRepoName) @@ -84,9 +87,9 @@ func TestRepoRemove(t *testing.T) { // 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)) + // Add test repos for _, repoName := range testRepoNames { o := &repoAddOptions{ name: repoName, @@ -98,21 +101,28 @@ func TestRepoRemove(t *testing.T) { t.Error(err) } - cacheIndex, cacheChart := indexing(b, rootDir, repoName) + cacheIndex, cacheChart := indexing(rootDir, repoName) idxs[repoName] = []string{cacheIndex, cacheChart} } + // Create repo remove command multiRmOpts := repoRemoveOptions{ names: testRepoNames, repoFile: repoFile, repoCache: rootDir, } - if err := multiRmOpts.run(b2); err != nil { + // Reset the buffer before running repo remove + b.Reset() + + // Run repo remove command + if err := multiRmOpts.run(b); err != nil { t.Errorf("Error removing list of repos from repositories: %q", testRepoNames) } - if !strings.Contains(b2.String(), "has been removed") { + + // Check that stuff were removed + if !strings.Contains(b.String(), "has been removed") { t.Errorf("Unexpected output: %s", b.String()) } @@ -130,7 +140,7 @@ func TestRepoRemove(t *testing.T) { } } -func indexing(buf *bytes.Buffer, rootDir string, repoName string) (cacheIndexFile string, cacheChartsFile string) { +func indexing(rootDir string, repoName string) (cacheIndexFile string, cacheChartsFile string) { idx := filepath.Join(rootDir, helmpath.CacheIndexFile(repoName)) mf, _ := os.Create(idx) mf.Close() @@ -139,8 +149,6 @@ func indexing(buf *bytes.Buffer, rootDir string, repoName string) (cacheIndexFil mf, _ = os.Create(idx2) mf.Close() - buf.Reset() - return idx, idx2 }