Merge pull request #3638 from adshmh/fix-duplication-of-test-code-on-helm-list

Remove duplicate test code from cmd/helm/list_test.go
pull/3650/head
Taylor Thomas 7 years ago committed by GitHub
commit 38335161d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,50 +17,44 @@ limitations under the License.
package main
import (
"bytes"
"regexp"
"io"
"testing"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/proto/hapi/release"
)
func TestListCmd(t *testing.T) {
tests := []struct {
name string
args []string
resp []*release.Release
expected string
err bool
}{
tests := []releaseCase{
{
name: "with a release",
resp: []*release.Release{
rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}),
},
expected: "thomas-guide",
},
{
name: "list",
args: []string{},
resp: []*release.Release{
rels: []*release.Release{
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",
},
{
name: "list, one deployed, one failed",
args: []string{"-q"},
resp: []*release.Release{
name: "list, one deployed, one failed",
flags: []string{"-q"},
rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
},
expected: "thomas-guide\natlas-guide",
},
{
name: "with a release, multiple flags",
args: []string{"--deleted", "--deployed", "--failed", "-q"},
resp: []*release.Release{
name: "with a release, multiple flags",
flags: []string{"--deleted", "--deployed", "--failed", "-q"},
rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETED}),
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",
},
{
name: "with a release, multiple flags",
args: []string{"--all", "-q"},
resp: []*release.Release{
name: "with a release, multiple flags",
flags: []string{"--all", "-q"},
rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETED}),
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",
},
{
name: "with a release, multiple flags, deleting",
args: []string{"--all", "-q"},
resp: []*release.Release{
name: "with a release, multiple flags, deleting",
flags: []string{"--all", "-q"},
rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_DELETING}),
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",
},
{
name: "namespace defined, multiple flags",
args: []string{"--all", "-q", "--namespace test123"},
resp: []*release.Release{
name: "namespace defined, multiple flags",
flags: []string{"--all", "-q", "--namespace test123"},
rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Namespace: "test123"}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Namespace: "test321"}),
},
@ -99,18 +93,18 @@ func TestListCmd(t *testing.T) {
expected: "thomas-guide",
},
{
name: "with a pending release, multiple flags",
args: []string{"--all", "-q"},
resp: []*release.Release{
name: "with a pending release, multiple flags",
flags: []string{"--all", "-q"},
rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_PENDING_INSTALL}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", StatusCode: release.Status_DEPLOYED}),
},
expected: "thomas-guide\natlas-guide",
},
{
name: "with a pending release, pending flag",
args: []string{"--pending", "-q"},
resp: []*release.Release{
name: "with a pending release, pending flag",
flags: []string{"--pending", "-q"},
rels: []*release.Release{
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: "crazy-maps", StatusCode: release.Status_PENDING_ROLLBACK}),
@ -120,7 +114,7 @@ func TestListCmd(t *testing.T) {
},
{
name: "with old releases",
resp: []*release.Release{
rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}),
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", StatusCode: release.Status_FAILED}),
},
@ -128,21 +122,7 @@ func TestListCmd(t *testing.T) {
},
}
var buf bytes.Buffer
for _, tt := range tests {
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()
}
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newListCmd(c, out)
})
}

Loading…
Cancel
Save