ref(tests): simplify creating fake client

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

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

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

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

Loading…
Cancel
Save