From b03f2bcc9449fb83dbfb3083f0c43995977a162d Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 22 Mar 2016 23:01:33 -0700 Subject: [PATCH] test(cli): add show depoyment unit test --- cmd/helm/deployment_test.go | 69 +++++++++++++++++++++++++++++++++++++ cmd/helm/helm_test.go | 19 ---------- 2 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 cmd/helm/deployment_test.go diff --git a/cmd/helm/deployment_test.go b/cmd/helm/deployment_test.go new file mode 100644 index 000000000..592f9ec07 --- /dev/null +++ b/cmd/helm/deployment_test.go @@ -0,0 +1,69 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "encoding/json" + "net/http" + "testing" + + "github.com/kubernetes/helm/pkg/common" +) + +func TestShowDeployment(t *testing.T) { + th := setup() + defer th.teardown() + + deployment := common.NewDeployment("guestbook.yaml") + + th.mux.HandleFunc("/deployments/", func(w http.ResponseWriter, r *http.Request) { + data, err := json.Marshal(deployment) + if err != nil { + t.Fatal(err) + } + 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) + } +} + +func TestListDeployment(t *testing.T) { + th := setup() + defer th.teardown() + + th.mux.HandleFunc("/deployments", func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(`["guestbook.yaml"]`)) + }) + + expected := "guestbook.yaml\n" + + actual := CaptureOutput(func() { + th.Run("deployment", "list") + }) + + if expected != actual { + t.Errorf("Expected %v got %v", expected, actual) + } +} diff --git a/cmd/helm/helm_test.go b/cmd/helm/helm_test.go index c2d04bb33..df6ec4ba9 100644 --- a/cmd/helm/helm_test.go +++ b/cmd/helm/helm_test.go @@ -105,22 +105,3 @@ func CaptureOutput(fn func()) string { b, _ := ioutil.ReadAll(r) return string(b) } - -func TestHelm(t *testing.T) { - th := setup() - defer th.teardown() - - th.mux.HandleFunc("/deployments", func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(`["guestbook.yaml"]`)) - }) - - expected := "guestbook.yaml\n" - - actual := CaptureOutput(func() { - th.Run("deployment", "list") - }) - - if expected != actual { - t.Errorf("Expected %v got %v", expected, actual) - } -}