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

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
pull/3900/head
Arash Deshmeh 7 years ago
parent 506ed05b84
commit 223c89e6aa

@ -41,13 +41,18 @@ func newRepoRemoveCmd(out io.Writer) *cobra.Command {
Aliases: []string{"rm"}, Aliases: []string{"rm"},
Short: "remove a chart repository", Short: "remove a chart repository",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(len(args), "name of chart repository"); err != nil { if len(args) == 0 {
return err 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 ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -79,3 +80,66 @@ func TestRepoRemove(t *testing.T) {
t.Errorf("%s was not successfully removed from repositories list", testName) 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)
}
}

Loading…
Cancel
Save