Merge pull request #3717 from adamreese/fix/history-output

fix(helm): fix helm history unit tests
pull/3721/head
Adam Reese 7 years ago committed by GitHub
commit 19c73207b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()
})
}
}

@ -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

@ -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`,
},
}

Loading…
Cancel
Save