Commit 223c89e6 authored by Arash Deshmeh's avatar Arash Deshmeh

feat(helm): support removing multiple repositories with repo remove command

Signed-off-by: 's avatarArash Deshmeh <adeshmeh@ca.ibm.com>
parent 506ed05b
......@@ -41,13 +41,18 @@ func newRepoRemoveCmd(out io.Writer) *cobra.Command {
Aliases: []string{"rm"},
Short: "remove a chart repository",
RunE: func(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(len(args), "name of chart repository"); err != nil {
return err
if len(args) == 0 {
return fmt.Errorf("need at least one argument, name of chart repository")
}
remove.name = args[0]
remove.home = settings.Home
return remove.run()
remove.home = settings.Home
for i := 0; i < len(args); i++ {
remove.name = args[i]
if err := remove.run(); err != nil {
return err
}
}
return nil
},
}
......
......@@ -18,6 +18,7 @@ package main
import (
"bytes"
"io/ioutil"
"os"
"strings"
"testing"
......@@ -79,3 +80,66 @@ func TestRepoRemove(t *testing.T) {
t.Errorf("%s was not successfully removed from repositories list", testName)
}
}
func TestRepoRemove_NoArguments(t *testing.T) {
cmd := newRepoRemoveCmd(ioutil.Discard)
if err := cmd.RunE(cmd, []string{}); err == nil {
t.Errorf("Expected an error since no repo names were provided")
}
}
func TestRepoRemove_MultipleRepos(t *testing.T) {
ts, thome, err := repotest.NewTempServer("testdata/testserver/*.*")
if err != nil {
t.Fatal(err)
}
hh := helmpath.Home(thome)
cleanup := resetEnv()
defer func() {
ts.Stop()
os.RemoveAll(thome.String())
cleanup()
}()
if err := ensureTestHome(hh, t); err != nil {
t.Fatal(err)
}
settings.Home = thome
repoFoo := testName + "foo"
repoBar := testName + "bar"
if err := addRepository(repoFoo, ts.URL(), "", "", hh, "", "", "", true); err != nil {
t.Error(err)
}
if err := addRepository(repoBar, ts.URL(), "", "", hh, "", "", "", true); err != nil {
t.Error(err)
}
b := bytes.NewBuffer(nil)
cmd := newRepoRemoveCmd(b)
if err := cmd.RunE(cmd, []string{repoFoo, repoBar}); err != nil {
t.Error(err)
}
if !strings.Contains(b.String(), repoFoo) {
t.Errorf("Expected %q in output, found: %q", repoFoo, b.String())
}
if !strings.Contains(b.String(), repoBar) {
t.Errorf("Expected %q in output, found: %q", repoBar, b.String())
}
f, err := repo.LoadRepositoriesFile(hh.RepositoryFile())
if err != nil {
t.Error(err)
}
if f.Has(repoFoo) {
t.Errorf("%s was not successfully removed from repositories list", repoFoo)
}
if f.Has(repoBar) {
t.Errorf("%s was not successfully removed from repositories list", repoBar)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment