From 34b6d12ebe0824cae6fc9ebb1b14d3c8fd822a92 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 20 Mar 2018 00:14:43 -0700 Subject: [PATCH] fix(helm): fix helm history unit tests fixes #3652 --- cmd/helm/helm_test.go | 29 ++++++++++++++--------------- cmd/helm/history.go | 14 +++++++------- cmd/helm/history_test.go | 20 ++++++++++---------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/cmd/helm/helm_test.go b/cmd/helm/helm_test.go index 7d74d66b7..c95caa75f 100644 --- a/cmd/helm/helm_test.go +++ b/cmd/helm/helm_test.go @@ -40,23 +40,22 @@ type releaseCmd func(c *helm.FakeClient, out io.Writer) *cobra.Command // runReleaseCases runs a set of release cases through the given releaseCmd. func runReleaseCases(t *testing.T, tests []releaseCase, rcmd releaseCmd) { - var buf bytes.Buffer for _, tt := range tests { - c := &helm.FakeClient{ - Rels: tt.rels, - } - cmd := rcmd(c, &buf) - cmd.ParseFlags(tt.flags) - err := cmd.RunE(cmd, tt.args) - if (err != nil) != tt.err { - t.Errorf("%q. expected error, got '%v'", tt.name, err) - } - re := regexp.MustCompile(tt.expected) - if !re.Match(buf.Bytes()) { - t.Errorf("%q. expected\n%q\ngot\n%q", tt.name, tt.expected, buf.String()) - } - buf.Reset() + t.Run(tt.name, func(t *testing.T) { + c := &helm.FakeClient{Rels: tt.rels} + cmd := rcmd(c, &buf) + cmd.ParseFlags(tt.flags) + err := cmd.RunE(cmd, tt.args) + if (err != nil) != tt.err { + t.Errorf("expected error, got '%v'", err) + } + re := regexp.MustCompile(tt.expected) + if !re.Match(buf.Bytes()) { + t.Errorf("expected\n%q\ngot\n%q", tt.expected, buf.String()) + } + buf.Reset() + }) } } diff --git a/cmd/helm/history.go b/cmd/helm/history.go index 7b8979142..e6366d31d 100644 --- a/cmd/helm/history.go +++ b/cmd/helm/history.go @@ -17,14 +17,14 @@ limitations under the License. package main import ( + "encoding/json" "fmt" "io" + "github.com/ghodss/yaml" "github.com/gosuri/uitable" "github.com/spf13/cobra" - "encoding/json" - "github.com/ghodss/yaml" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/release" @@ -32,11 +32,11 @@ import ( ) type releaseInfo struct { - Revision int32 `json:"revision" yaml:"revision"` - Updated string `json:"updated" yaml:"updated"` - Status string `json:"status" yaml:"status"` - Chart string `json:"chart" yaml:"chart"` - Description string `json:"description" yaml:"description"` + Revision int32 `json:"revision"` + Updated string `json:"updated"` + Status string `json:"status"` + Chart string `json:"chart"` + Description string `json:"description"` } type releaseHistory []releaseInfo diff --git a/cmd/helm/history_test.go b/cmd/helm/history_test.go index c6a14b333..fef433742 100644 --- a/cmd/helm/history_test.go +++ b/cmd/helm/history_test.go @@ -58,24 +58,24 @@ func TestHistoryCmd(t *testing.T) { expected: "REVISION\tUPDATED \tSTATUS \tCHART \tDESCRIPTION \n3 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n4 \t(.*)\tDEPLOYED \tfoo-0.1.0-beta.1\tRelease mock\n", }, { - cmds: "helm history --max=MAX RELEASE_NAME -o yaml", - desc: "get history with yaml output format", - args: []string{"--max=2", "-o=yaml", "angry-bird"}, - resp: []*rpb.Release{ + name: "get history with yaml output format", + args: []string{"angry-bird"}, + flags: []string{"--output", "yaml"}, + rels: []*rpb.Release{ mk("angry-bird", 4, rpb.Status_DEPLOYED), mk("angry-bird", 3, rpb.Status_SUPERSEDED), }, - xout: "- chart: foo-0.1.0-beta.1\n description: Release mock\n revision: 3\n status: SUPERSEDED\n updated: (.*)\n- chart: foo-0.1.0-beta.1\n description: Release mock\n revision: 4\n status: DEPLOYED\n updated: (.*)\n\n", + expected: "- chart: foo-0.1.0-beta.1\n description: Release mock\n revision: 3\n status: SUPERSEDED\n updated: (.*)\n- chart: foo-0.1.0-beta.1\n description: Release mock\n revision: 4\n status: DEPLOYED\n updated: (.*)\n\n", }, { - cmds: "helm history --max=MAX RELEASE_NAME -o json", - desc: "get history with json output format", - args: []string{"--max=2", "-o=json", "angry-bird"}, - resp: []*rpb.Release{ + name: "get history with json output format", + args: []string{"angry-bird"}, + flags: []string{"--output", "json"}, + rels: []*rpb.Release{ mk("angry-bird", 4, rpb.Status_DEPLOYED), mk("angry-bird", 3, rpb.Status_SUPERSEDED), }, - xout: `[{"revision":3,"updated":".*","status":"SUPERSEDED","chart":"foo\-0.1.0-beta.1","description":"Release mock"},{"revision":4,"updated":".*","status":"DEPLOYED","chart":"foo\-0.1.0-beta.1","description":"Release mock"}]\n`, + expected: `[{"revision":3,"updated":".*","status":"SUPERSEDED","chart":"foo\-0.1.0-beta.1","description":"Release mock"},{"revision":4,"updated":".*","status":"DEPLOYED","chart":"foo\-0.1.0-beta.1","description":"Release mock"}]\n`, }, }