From 416c97d221adc1d39d69fe2c486cb1aec434357b Mon Sep 17 00:00:00 2001 From: Stanton Xu Date: Sun, 14 Jun 2020 00:35:13 -0700 Subject: [PATCH] Updated test cases Signed-off-by: Stanton Xu --- cmd/helm/install.go | 4 ++++ cmd/helm/install_test.go | 8 ++++++++ cmd/helm/testdata/testcharts/deprecatedchart/Chart.yaml | 8 ++++++++ cmd/helm/testdata/testcharts/deprecatedchart/README.md | 3 +++ cmd/helm/upgrade.go | 5 +++++ cmd/helm/upgrade_test.go | 8 ++++++++ 6 files changed, 36 insertions(+) create mode 100644 cmd/helm/testdata/testcharts/deprecatedchart/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/deprecatedchart/README.md diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 117c7ba5b..d4ab3c5ad 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -267,6 +267,10 @@ func (i *installCmd) run() error { return prettyError(err) } + if chartRequested.Metadata.Deprecated { + fmt.Fprintln(os.Stderr, "WARNING: This chart is deprecated") + } + if req, err := chartutil.LoadRequirements(chartRequested); err == nil { // If checkDependencies returns an error, we have unfulfilled dependencies. // As of Helm 2.4.0, this is treated as a stopping condition: diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index e00c33a81..b7bf6d227 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -207,6 +207,14 @@ func TestInstall(t *testing.T) { resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "virgil"}), expected: "info:\n Description: Release mock\n first_deployed:\n seconds: 242085845\n last_deployed:\n seconds: 242085845\n status:\n code: 1\nname: virgil\nnamespace: default\n", }, + // Install deprecated chart + { + name: "install with warning about deprecated chart", + args: []string{"testdata/testcharts/deprecatedchart"}, + flags: []string{"--name", "deprecatedchart"}, + resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "deprecatedchart"}), + expected: "deprecatedchart", + }, } runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { diff --git a/cmd/helm/testdata/testcharts/deprecatedchart/Chart.yaml b/cmd/helm/testdata/testcharts/deprecatedchart/Chart.yaml new file mode 100644 index 000000000..24abd5ece --- /dev/null +++ b/cmd/helm/testdata/testcharts/deprecatedchart/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +description: Deprecated testing chart +home: https://helm.sh/helm +name: deprecatedchart +sources: + - https://github.com/helm/helm +version: 0.1.0 +deprecated: true \ No newline at end of file diff --git a/cmd/helm/testdata/testcharts/deprecatedchart/README.md b/cmd/helm/testdata/testcharts/deprecatedchart/README.md new file mode 100644 index 000000000..02b8e2b92 --- /dev/null +++ b/cmd/helm/testdata/testcharts/deprecatedchart/README.md @@ -0,0 +1,3 @@ +#Deprecated + +This space intentionally left blank. \ No newline at end of file diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 6b885ba63..9a4a54d2e 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -19,6 +19,7 @@ package main import ( "fmt" "io" + "os" "strings" "github.com/spf13/cobra" @@ -266,6 +267,10 @@ func (u *upgradeCmd) run() error { return prettyError(err) } + if ch.Metadata.Deprecated { + fmt.Fprintln(os.Stderr, "WARNING: This chart is deprecated") + } + resp, err := u.client.UpdateReleaseFromChart( u.release, ch, diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index 433f3bd2c..2b0b4d055 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -85,6 +85,7 @@ func TestUpgradeCmd(t *testing.T) { originalDepsPath := filepath.Join("testdata/testcharts/reqtest") missingDepsPath := filepath.Join("testdata/testcharts/chart-missing-deps") badDepsPath := filepath.Join("testdata/testcharts/chart-bad-requirements") + deprecatedChart := filepath.Join("testdata/testcharts/deprecatedchart") var ch3 *chart.Chart ch3, err = chartutil.Load(originalDepsPath) if err != nil { @@ -183,6 +184,13 @@ func TestUpgradeCmd(t *testing.T) { resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "bonkers-bunny", Version: 1, Chart: ch3}), err: true, }, + { + name: "upgrade a release with deprecated chart", + args: []string{"crazy-bunny", deprecatedChart}, + resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "crazy-bunny", Version: 2, Chart: ch}), + expected: "Release \"crazy-bunny\" has been upgraded.\n", + rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "crazy-bunny", Version: 2, Chart: ch})}, + }, } cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command {