ref(tests): simplify creating fake client

pull/921/head
Adam Reese 9 years ago
parent 4db6cd93bb
commit 37cf2b9e7d

@ -21,7 +21,6 @@ import (
"regexp"
"testing"
"k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/proto/hapi/release"
)
@ -29,30 +28,28 @@ func TestGetCmd(t *testing.T) {
tests := []struct {
name string
args []string
client helm.Interface
resp *release.Release
expected string
err bool
}{
{
name: "with a release",
client: &fakeReleaseClient{
rels: []*release.Release{
releaseMock("thomas-guide"),
},
},
name: "with a release",
resp: releaseMock("thomas-guide"),
args: []string{"thomas-guide"},
expected: "CHART: foo-0.1.0-beta.1\nRELEASED: (.*)\nUSER-SUPPLIED VALUES:\nname: \"value\"\nCOMPUTED VALUES:\nname: value\n\nMANIFEST:",
},
{
name: "requires release name arg",
client: &fakeReleaseClient{},
err: true,
name: "requires release name arg",
err: true,
},
}
var buf bytes.Buffer
for _, tt := range tests {
cmd := newGetCmd(tt.client, &buf)
c := &fakeReleaseClient{
rels: []*release.Release{tt.resp},
}
cmd := newGetCmd(c, &buf)
err := cmd.RunE(cmd, tt.args)
if (err != nil) != tt.err {
t.Errorf("%q. expected error: %v, got %v", tt.name, tt.err, err)

@ -20,7 +20,6 @@ import (
"bytes"
"testing"
"k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/proto/hapi/release"
)
@ -28,30 +27,28 @@ func TestGetValuesCmd(t *testing.T) {
tests := []struct {
name string
args []string
client helm.Interface
resp *release.Release
expected string
err bool
}{
{
name: "with a release",
client: &fakeReleaseClient{
rels: []*release.Release{
releaseMock("thomas-guide"),
},
},
name: "with a release",
resp: releaseMock("thomas-guide"),
args: []string{"thomas-guide"},
expected: "name: \"value\"",
},
{
name: "requires release name arg",
client: &fakeReleaseClient{},
err: true,
name: "requires release name arg",
err: true,
},
}
var buf bytes.Buffer
for _, tt := range tests {
cmd := newGetValuesCmd(tt.client, &buf)
c := &fakeReleaseClient{
rels: []*release.Release{tt.resp},
}
cmd := newGetValuesCmd(c, &buf)
err := cmd.RunE(cmd, tt.args)
if (err != nil) != tt.err {
t.Errorf("%q. expected error: %v, got %v", tt.name, tt.err, err)

@ -21,7 +21,6 @@ import (
"regexp"
"testing"
"k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/proto/hapi/release"
)
@ -77,26 +76,22 @@ func TestListCmd(t *testing.T) {
name string
args []string
flags map[string]string
client helm.Interface
resp []*release.Release
expected string
err bool
}{
{
name: "with a release",
client: &fakeReleaseClient{
rels: []*release.Release{
releaseMock("thomas-guide"),
},
resp: []*release.Release{
releaseMock("thomas-guide"),
},
expected: "thomas-guide",
},
{
name: "list --long",
flags: map[string]string{"long": "1"},
client: &fakeReleaseClient{
rels: []*release.Release{
releaseMock("atlas"),
},
resp: []*release.Release{
releaseMock("atlas"),
},
expected: "NAME \tUPDATED \tSTATUS \tCHART \natlas\t(.*)\tDEPLOYED\tfoo-0.1.0-beta.1",
},
@ -104,7 +99,10 @@ func TestListCmd(t *testing.T) {
var buf bytes.Buffer
for _, tt := range tests {
cmd := newListCmd(tt.client, &buf)
c := &fakeReleaseClient{
rels: tt.resp,
}
cmd := newListCmd(c, &buf)
for flag, value := range tt.flags {
cmd.Flags().Set(flag, value)
}

Loading…
Cancel
Save