fix(helm): remove duplicate test code from cmd/helm/list_test. Closes #3637

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
pull/3638/head
Arash Deshmeh 7 years ago
parent c31246467c
commit 75ccc353eb

@ -17,50 +17,44 @@ limitations under the License.
package main package main
import ( import (
"bytes" "io"
"regexp"
"testing" "testing"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/proto/hapi/release"
) )
func TestListCmd(t *testing.T) { func TestListCmd(t *testing.T) {
tests := []struct { tests := []releaseCase{
name string
args []string
resp []*release.Release
expected string
err bool
}{
{ {
name: "with a release", name: "with a release",
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}),
}, },
expected: "thomas-guide", expected: "thomas-guide",
}, },
{ {
name: "list", name: "list",
args: []string{}, rels: []*release.Release{
resp: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas"}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas"}),
}, },
expected: "NAME \tREVISION\tUPDATED \tSTATUS \tCHART \tNAMESPACE\natlas\t1 \t(.*)\tDEPLOYED\tfoo-0.1.0-beta.1\tdefault \n", expected: "NAME \tREVISION\tUPDATED \tSTATUS \tCHART \tNAMESPACE\natlas\t1 \t(.*)\tDEPLOYED\tfoo-0.1.0-beta.1\tdefault \n",
}, },
{ {
name: "list, one deployed, one failed", name: "list, one deployed, one failed",
args: []string{"-q"}, flags: []string{"-q"},
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
}, },
expected: "thomas-guide\natlas-guide", expected: "thomas-guide\natlas-guide",
}, },
{ {
name: "with a release, multiple flags", name: "with a release, multiple flags",
args: []string{"--deleted", "--deployed", "--failed", "-q"}, flags: []string{"--deleted", "--deployed", "--failed", "-q"},
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETED}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
}, },
@ -69,9 +63,9 @@ func TestListCmd(t *testing.T) {
expected: "thomas-guide\natlas-guide", expected: "thomas-guide\natlas-guide",
}, },
{ {
name: "with a release, multiple flags", name: "with a release, multiple flags",
args: []string{"--all", "-q"}, flags: []string{"--all", "-q"},
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETED}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
}, },
@ -79,9 +73,9 @@ func TestListCmd(t *testing.T) {
expected: "thomas-guide\natlas-guide", expected: "thomas-guide\natlas-guide",
}, },
{ {
name: "with a release, multiple flags, deleting", name: "with a release, multiple flags, deleting",
args: []string{"--all", "-q"}, flags: []string{"--all", "-q"},
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETING}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETING}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
}, },
@ -89,9 +83,9 @@ func TestListCmd(t *testing.T) {
expected: "thomas-guide\natlas-guide", expected: "thomas-guide\natlas-guide",
}, },
{ {
name: "namespace defined, multiple flags", name: "namespace defined, multiple flags",
args: []string{"--all", "-q", "--namespace test123"}, flags: []string{"--all", "-q", "--namespace test123"},
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Namespace: "test123"}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Namespace: "test123"}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Namespace: "test321"}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Namespace: "test321"}),
}, },
@ -99,18 +93,18 @@ func TestListCmd(t *testing.T) {
expected: "thomas-guide", expected: "thomas-guide",
}, },
{ {
name: "with a pending release, multiple flags", name: "with a pending release, multiple flags",
args: []string{"--all", "-q"}, flags: []string{"--all", "-q"},
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_PENDING_INSTALL}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_PENDING_INSTALL}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
}, },
expected: "thomas-guide\natlas-guide", expected: "thomas-guide\natlas-guide",
}, },
{ {
name: "with a pending release, pending flag", name: "with a pending release, pending flag",
args: []string{"--pending", "-q"}, flags: []string{"--pending", "-q"},
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_PENDING_INSTALL}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_PENDING_INSTALL}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "wild-idea", StatusCode: release.Status_PENDING_UPGRADE}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "wild-idea", StatusCode: release.Status_PENDING_UPGRADE}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "crazy-maps", StatusCode: release.Status_PENDING_ROLLBACK}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "crazy-maps", StatusCode: release.Status_PENDING_ROLLBACK}),
@ -120,7 +114,7 @@ func TestListCmd(t *testing.T) {
}, },
{ {
name: "with old releases", name: "with old releases",
resp: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}), helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}),
}, },
@ -128,21 +122,7 @@ func TestListCmd(t *testing.T) {
}, },
} }
var buf bytes.Buffer runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
for _, tt := range tests { return newListCmd(c, out)
c := &helm.FakeClient{ })
Rels: tt.resp,
}
cmd := newListCmd(c, &buf)
cmd.ParseFlags(tt.args)
err := cmd.RunE(cmd, tt.args)
if (err != nil) != tt.err {
t.Errorf("%q. expected error: %v, got %v", tt.name, tt.err, 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()
}
} }

Loading…
Cancel
Save