From 4b3d3cfa56aae75abb6988e923eb9dcfc47af8e9 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 22 Mar 2016 23:45:18 -0700 Subject: [PATCH] test(cli): use table test for deployments --- cmd/helm/deployment_test.go | 59 +++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/cmd/helm/deployment_test.go b/cmd/helm/deployment_test.go index 592f9ec07..834189c63 100644 --- a/cmd/helm/deployment_test.go +++ b/cmd/helm/deployment_test.go @@ -25,27 +25,48 @@ import ( ) func TestShowDeployment(t *testing.T) { - th := setup() - defer th.teardown() - - deployment := common.NewDeployment("guestbook.yaml") + var deploymentTestCases = []struct { + args []string + resp *common.Deployment + 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", + }, + } - th.mux.HandleFunc("/deployments/", func(w http.ResponseWriter, r *http.Request) { - data, err := json.Marshal(deployment) - if err != nil { - t.Fatal(err) + for _, tc := range deploymentTestCases { + th := setup() + th.mux.HandleFunc("/deployments/", func(w http.ResponseWriter, r *http.Request) { + data, err := json.Marshal(tc.resp) + if err != nil { + t.Fatal(err) + } + w.Write(data) + }) + + actual := CaptureOutput(func() { + th.Run(tc.args...) + }) + if tc.expected != actual { + t.Errorf("Expected %v got %v", tc.expected, actual) } - w.Write(data) - }) - - expected := "Name: guestbook.yaml\nStatus: Created\n" - - actual := CaptureOutput(func() { - th.Run("deployment", "show", "guestbook.yaml") - }) - - if expected != actual { - t.Errorf("Expected %v got %v", expected, actual) + th.teardown() } }