fix(helm): fix helm history unit tests

fixes #3652
pull/3717/head
Adam Reese 7 years ago
parent 87f66af061
commit 34b6d12ebe
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -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. // runReleaseCases runs a set of release cases through the given releaseCmd.
func runReleaseCases(t *testing.T, tests []releaseCase, rcmd releaseCmd) { func runReleaseCases(t *testing.T, tests []releaseCase, rcmd releaseCmd) {
var buf bytes.Buffer var buf bytes.Buffer
for _, tt := range tests { for _, tt := range tests {
c := &helm.FakeClient{ t.Run(tt.name, func(t *testing.T) {
Rels: tt.rels, c := &helm.FakeClient{Rels: tt.rels}
} cmd := rcmd(c, &buf)
cmd := rcmd(c, &buf) cmd.ParseFlags(tt.flags)
cmd.ParseFlags(tt.flags) err := cmd.RunE(cmd, tt.args)
err := cmd.RunE(cmd, tt.args) if (err != nil) != tt.err {
if (err != nil) != tt.err { t.Errorf("expected error, got '%v'", err)
t.Errorf("%q. expected error, got '%v'", tt.name, err) }
} re := regexp.MustCompile(tt.expected)
re := regexp.MustCompile(tt.expected) if !re.Match(buf.Bytes()) {
if !re.Match(buf.Bytes()) { t.Errorf("expected\n%q\ngot\n%q", tt.expected, buf.String())
t.Errorf("%q. expected\n%q\ngot\n%q", tt.name, tt.expected, buf.String()) }
} buf.Reset()
buf.Reset() })
} }
} }

@ -17,14 +17,14 @@ limitations under the License.
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"io" "io"
"github.com/ghodss/yaml"
"github.com/gosuri/uitable" "github.com/gosuri/uitable"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"encoding/json"
"github.com/ghodss/yaml"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/proto/hapi/release"
@ -32,11 +32,11 @@ import (
) )
type releaseInfo struct { type releaseInfo struct {
Revision int32 `json:"revision" yaml:"revision"` Revision int32 `json:"revision"`
Updated string `json:"updated" yaml:"updated"` Updated string `json:"updated"`
Status string `json:"status" yaml:"status"` Status string `json:"status"`
Chart string `json:"chart" yaml:"chart"` Chart string `json:"chart"`
Description string `json:"description" yaml:"description"` Description string `json:"description"`
} }
type releaseHistory []releaseInfo type releaseHistory []releaseInfo

@ -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", 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", name: "get history with yaml output format",
desc: "get history with yaml output format", args: []string{"angry-bird"},
args: []string{"--max=2", "-o=yaml", "angry-bird"}, flags: []string{"--output", "yaml"},
resp: []*rpb.Release{ rels: []*rpb.Release{
mk("angry-bird", 4, rpb.Status_DEPLOYED), mk("angry-bird", 4, rpb.Status_DEPLOYED),
mk("angry-bird", 3, rpb.Status_SUPERSEDED), 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", name: "get history with json output format",
desc: "get history with json output format", args: []string{"angry-bird"},
args: []string{"--max=2", "-o=json", "angry-bird"}, flags: []string{"--output", "json"},
resp: []*rpb.Release{ rels: []*rpb.Release{
mk("angry-bird", 4, rpb.Status_DEPLOYED), mk("angry-bird", 4, rpb.Status_DEPLOYED),
mk("angry-bird", 3, rpb.Status_SUPERSEDED), 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`,
}, },
} }

Loading…
Cancel
Save