Skip to content

Commit

Permalink
Updated test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Stanton Xu <xjiefeng@gmail.com>
  • Loading branch information
stantonxu committed Jun 20, 2020
1 parent cc25841 commit 416c97d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/helm/install.go
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions cmd/helm/install_test.go
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions cmd/helm/testdata/testcharts/deprecatedchart/README.md
@@ -0,0 +1,3 @@
#Deprecated

This space intentionally left blank.
5 changes: 5 additions & 0 deletions cmd/helm/upgrade.go
Expand Up @@ -19,6 +19,7 @@ package main
import (
"fmt"
"io"
"os"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions cmd/helm/upgrade_test.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 416c97d

Please sign in to comment.