Commit 4b3d3cfa authored by Adam Reese's avatar Adam Reese

test(cli): use table test for deployments

parent b03f2bcc
...@@ -25,27 +25,48 @@ import ( ...@@ -25,27 +25,48 @@ import (
) )
func TestShowDeployment(t *testing.T) { func TestShowDeployment(t *testing.T) {
th := setup() var deploymentTestCases = []struct {
defer th.teardown() args []string
resp *common.Deployment
deployment := common.NewDeployment("guestbook.yaml") expected string
}{
{
[]string{"deployment", "show", "guestbook.yaml"},
&common.Deployment{
Name: "guestbook.yaml",
State: &common.DeploymentState{Status: common.CreatedStatus},
},
"Name: guestbook.yaml\nStatus: Created\n",
},
{
[]string{"deployment", "show", "guestbook.yaml"},
&common.Deployment{
Name: "guestbook.yaml",
State: &common.DeploymentState{
common.FailedStatus, []string{"error message"},
},
},
"Name: guestbook.yaml\nStatus: Failed\nErrors:\n error message\n",
},
}
for _, tc := range deploymentTestCases {
th := setup()
th.mux.HandleFunc("/deployments/", func(w http.ResponseWriter, r *http.Request) { th.mux.HandleFunc("/deployments/", func(w http.ResponseWriter, r *http.Request) {
data, err := json.Marshal(deployment) data, err := json.Marshal(tc.resp)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
w.Write(data) w.Write(data)
}) })
expected := "Name: guestbook.yaml\nStatus: Created\n"
actual := CaptureOutput(func() { actual := CaptureOutput(func() {
th.Run("deployment", "show", "guestbook.yaml") th.Run(tc.args...)
}) })
if tc.expected != actual {
if expected != actual { t.Errorf("Expected %v got %v", tc.expected, actual)
t.Errorf("Expected %v got %v", expected, actual) }
th.teardown()
} }
} }
......
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