feat(helm): adding --name to update single repo

Signed-off-by: Deepak Sattiraju <desattir@microsoft.com>

Lint

Signed-off-by: ds-ms <desattir@microsoft.com>

make docs

Signed-off-by: ds-ms <desattir@microsoft.com>

make docs

Signed-off-by: ds-ms <desattir@microsoft.com>
Signed-off-by: Deepak Sattiraju <desattir@microsoft.com>

using args instead of --name

Signed-off-by: ds-ms <desattir@microsoft.com>

Adding [repo_name] to use

Signed-off-by: ds-ms <desattir@microsoft.com>

Adding test

Signed-off-by: ds-ms <desattir@microsoft.com>

Adding positive test case

Signed-off-by: ds-ms <desattir@microsoft.com>

lint

Signed-off-by: ds-ms <desattir@microsoft.com>

Renaming

Signed-off-by: ds-ms <desattir@microsoft.com>

Updating repo_name to REPO_NAME

feat(helm): adding --name to update single repo

Signed-off-by: Deepak Sattiraju <desattir@microsoft.com>

Lint

Signed-off-by: ds-ms <desattir@microsoft.com>

make docs

Signed-off-by: ds-ms <desattir@microsoft.com>

make docs

Signed-off-by: ds-ms <desattir@microsoft.com>
Signed-off-by: Deepak Sattiraju <desattir@microsoft.com>

using args instead of --name

Signed-off-by: ds-ms <desattir@microsoft.com>

Adding [repo_name] to use

Signed-off-by: ds-ms <desattir@microsoft.com>

Adding test

Signed-off-by: ds-ms <desattir@microsoft.com>

Adding positive test case

Signed-off-by: ds-ms <desattir@microsoft.com>

lint

Signed-off-by: ds-ms <desattir@microsoft.com>

Renaming

Signed-off-by: ds-ms <desattir@microsoft.com>

Updating repo_name to REPO_NAME
pull/5182/head
Deepak Sattiraju 7 years ago committed by ds-ms
parent e46dd138b1
commit c49ba7da85

@ -36,15 +36,24 @@ Information is cached locally, where it is used by commands like 'helm search'.
'helm update' is the deprecated form of 'helm repo update'. It will be removed in 'helm update' is the deprecated form of 'helm repo update'. It will be removed in
future releases. future releases.
You can specify the name of a repository you want to update.
$ helm repo update <repo_name>
To update all the repositories, use 'helm repo update'.
` `
var errNoRepositories = errors.New("no repositories found. You must add one before updating") var errNoRepositories = errors.New("no repositories found. You must add one before updating")
var errNoRepositoriesMatchingRepoName = errors.New("no repositories found matching the provided name. Verify if the repo exists")
type repoUpdateCmd struct { type repoUpdateCmd struct {
update func([]*repo.ChartRepository, io.Writer, helmpath.Home, bool) error update func([]*repo.ChartRepository, io.Writer, helmpath.Home, bool) error
home helmpath.Home home helmpath.Home
out io.Writer out io.Writer
strict bool strict bool
name string
} }
func newRepoUpdateCmd(out io.Writer) *cobra.Command { func newRepoUpdateCmd(out io.Writer) *cobra.Command {
@ -53,12 +62,15 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command {
update: updateCharts, update: updateCharts,
} }
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update", Use: "update [REPO_NAME]",
Aliases: []string{"up"}, Aliases: []string{"up"},
Short: "Update information of available charts locally from chart repositories", Short: "Update information of available charts locally from chart repositories",
Long: updateDesc, Long: updateDesc,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
u.home = settings.Home u.home = settings.Home
if len(args) != 0 {
u.name = args[0]
}
return u.run() return u.run()
}, },
} }
@ -84,8 +96,22 @@ func (u *repoUpdateCmd) run() error {
if err != nil { if err != nil {
return err return err
} }
if len(u.name) != 0 {
if cfg.Name == u.name {
repos = append(repos, r) repos = append(repos, r)
break
} else {
continue
} }
} else {
repos = append(repos, r)
}
}
if len(repos) == 0 {
return errNoRepositoriesMatchingRepoName
}
return u.update(repos, u.out, u.home, u.strict) return u.update(repos, u.out, u.home, u.strict)
} }

@ -132,3 +132,78 @@ func TestUpdateCmdStrictFlag(t *testing.T) {
t.Errorf("Expected 'Unable to get an update', got %q", got) t.Errorf("Expected 'Unable to get an update', got %q", got)
} }
} }
func TestUpdateCmdWithSingleRepoNameWhichDoesntExist(t *testing.T) {
thome, err := tempHelmHome(t)
if err != nil {
t.Fatal(err)
}
cleanup := resetEnv()
defer func() {
os.RemoveAll(thome.String())
cleanup()
}()
settings.Home = thome
out := bytes.NewBuffer(nil)
cmd := newRepoUpdateCmd(out)
if err = cmd.RunE(cmd, []string{"randomRepo"}); err == nil {
t.Fatal("expected error due to wrong repo name")
}
if got := fmt.Sprintf("%v", err); !strings.Contains(got, "no repositories found matching the provided name. Verify if the repo exists") {
t.Errorf("Expected 'no repositories found matching the provided name. Verify if the repo exists', got %q", got)
}
}
func TestUpdateRepo(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
if err := addRepository("repo1", ts.URL(), "", "", hh, "", "", "", true); err != nil {
t.Error(err)
}
if err := addRepository("repo2", ts.URL(), "", "", hh, "", "", "", true); err != nil {
t.Error(err)
}
out := bytes.NewBuffer(nil)
cmd := newRepoUpdateCmd(out)
if err = cmd.RunE(cmd, []string{"repo1"}); err != nil {
t.Fatal("expected to update repo1 correctly")
}
got := out.String()
if !strings.Contains(got, "Successfully got an update from the \"repo1\"") {
t.Errorf("Expected to successfully update \"repo1\" repository, got %q", got)
}
if strings.Contains(got, "Successfully got an update from the \"repo2\"") {
t.Errorf("Shouldn't have updated \"repo2\" repository, got %q", got)
}
if !strings.Contains(got, "Update Complete.") {
t.Error("Update was not successful")
}
}

@ -11,9 +11,16 @@ Information is cached locally, where it is used by commands like 'helm search'.
'helm update' is the deprecated form of 'helm repo update'. It will be removed in 'helm update' is the deprecated form of 'helm repo update'. It will be removed in
future releases. future releases.
You can specify the name of a repository you want to update.
$ helm repo update <repo_name>
To update all the repositories, use 'helm repo update'.
``` ```
helm repo update [flags] helm repo update [REPO_NAME] [flags]
``` ```
### Options ### Options
@ -39,4 +46,4 @@ helm repo update [flags]
* [helm repo](helm_repo.md) - Add, list, remove, update, and index chart repositories * [helm repo](helm_repo.md) - Add, list, remove, update, and index chart repositories
###### Auto generated by spf13/cobra on 16-May-2019 ###### Auto generated by spf13/cobra on 7-Jun-2019

Loading…
Cancel
Save