Commit 4edccdea authored by vaikas-google's avatar vaikas-google

fix the tests for the command

parent 7587769d
...@@ -24,39 +24,50 @@ import ( ...@@ -24,39 +24,50 @@ import (
"github.com/kubernetes/helm/pkg/common" "github.com/kubernetes/helm/pkg/common"
) )
type pathAndResponse struct {
path string
resp interface{}
}
func TestDeployment(t *testing.T) { func TestDeployment(t *testing.T) {
var deploymentTestCases = []struct { var deploymentTestCases = []struct {
args []string args []string
resp interface{} resp []pathAndResponse
expected string expected string
}{ }{
{ {
[]string{"deployment", "show", "guestbook.yaml"}, []string{"deployment", "show", "guestbook.yaml"},
&common.Deployment{ []pathAndResponse{{"/deployments/", &common.Deployment{
Name: "guestbook.yaml", Name: "guestbook.yaml",
State: &common.DeploymentState{Status: common.CreatedStatus}, State: &common.DeploymentState{Status: common.CreatedStatus},
}, }}},
"Name: guestbook.yaml\nStatus: Created\n", "Name: guestbook.yaml\nStatus: Created\n",
}, },
{ {
[]string{"deployment", "show", "guestbook.yaml"}, []string{"deployment", "show", "guestbook.yaml"},
&common.Deployment{ []pathAndResponse{{"/deployments/", &common.Deployment{
Name: "guestbook.yaml", Name: "guestbook.yaml",
State: &common.DeploymentState{ State: &common.DeploymentState{
Status: common.FailedStatus, Status: common.FailedStatus,
Errors: []string{"error message"}, Errors: []string{"error message"},
}, },
}, }}},
"Name: guestbook.yaml\nStatus: Failed\nErrors:\n error message\n", "Name: guestbook.yaml\nStatus: Failed\nErrors:\n error message\n",
}, },
{ {
[]string{"deployment", "list"}, []string{"deployment", "list"},
[]string{"guestbook.yaml"}, []pathAndResponse{{"/deployments/", []string{"guestbook.yaml"}}},
"guestbook.yaml\n", "guestbook.yaml\n",
}, },
{ {
[]string{"deployment", "describe", "guestbook.yaml"}, []string{"deployment", "describe", "guestbook.yaml"},
&common.Manifest{ []pathAndResponse{{
"/deployments/guestbook.yaml",
&common.Deployment{Name: "guestbook.yaml",
State: &common.DeploymentState{Status: common.CreatedStatus},
LatestManifest: "manifestxyz",
}},
{"/deployments/guestbook.yaml/manifests/manifestxyz", &common.Manifest{
Deployment: "guestbook.yaml", Deployment: "guestbook.yaml",
Name: "manifestxyz", Name: "manifestxyz",
ExpandedConfig: &common.Configuration{ ExpandedConfig: &common.Configuration{
...@@ -67,7 +78,7 @@ func TestDeployment(t *testing.T) { ...@@ -67,7 +78,7 @@ func TestDeployment(t *testing.T) {
{Name: "be", Type: "Service", State: &common.ResourceState{Status: common.Created}}, {Name: "be", Type: "Service", State: &common.ResourceState{Status: common.Created}},
}, },
}, },
}, }}},
"Name: fe-rc\nType: ReplicationController\nStatus: Created\n" + "Name: fe-rc\nType: ReplicationController\nStatus: Created\n" +
"Name: fe\nType: Service\nStatus: Created\n" + "Name: fe\nType: Service\nStatus: Created\n" +
"Name: be-rc\nType: ReplicationController\nStatus: Created\n" + "Name: be-rc\nType: ReplicationController\nStatus: Created\n" +
...@@ -77,11 +88,14 @@ func TestDeployment(t *testing.T) { ...@@ -77,11 +88,14 @@ func TestDeployment(t *testing.T) {
for _, tc := range deploymentTestCases { for _, tc := range deploymentTestCases {
th := testHelm(t) th := testHelm(t)
th.mux.HandleFunc("/deployments/", func(w http.ResponseWriter, r *http.Request) { for _, pathAndResponse := range tc.resp {
data, err := json.Marshal(tc.resp) var response = pathAndResponse.resp
th.mux.HandleFunc(pathAndResponse.path, func(w http.ResponseWriter, r *http.Request) {
data, err := json.Marshal(response)
th.must(err) th.must(err)
w.Write(data) w.Write(data)
}) })
}
th.run(tc.args...) th.run(tc.args...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment