From 97b1a7b815d02bf9d0ba2314db7f0fd4b516e21d Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Fri, 1 Apr 2016 12:13:27 -0700 Subject: [PATCH] feat(e2e): add must run and image flags for install --- test/e2e/helm.go | 21 ++++++++++++++++++--- test/e2e/helm_test.go | 32 ++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/test/e2e/helm.go b/test/e2e/helm.go index 6b5bde4f9..ea7ccc257 100644 --- a/test/e2e/helm.go +++ b/test/e2e/helm.go @@ -30,7 +30,7 @@ func NewHelmContext(t *testing.T) *HelmContext { } } -func (h *HelmContext) Run(args ...string) *HelmCmd { +func (h *HelmContext) MustRun(args ...string) *HelmCmd { cmd := h.newCmd() if status := cmd.exec(args...); status != nil { h.t.Fatalf("helm %v failed unexpectedly: %v", args, status) @@ -38,6 +38,20 @@ func (h *HelmContext) Run(args ...string) *HelmCmd { return cmd } +func (h *HelmContext) Run(args ...string) *HelmCmd { + cmd := h.newCmd() + cmd.exec(args...) + return cmd +} + +func (h *HelmContext) RunFail(args ...string) *HelmCmd { + cmd := h.newCmd() + if status := cmd.exec(args...); status == nil { + h.t.Fatalf("helm unexpected to fail: %v", args, status) + } + return cmd +} + func (h *HelmContext) newCmd() *HelmCmd { return &HelmCmd{ ctx: h, @@ -48,6 +62,7 @@ type HelmCmd struct { ctx *HelmContext path string ran bool + status error stdout, stderr bytes.Buffer } @@ -58,7 +73,7 @@ func (h *HelmCmd) exec(args ...string) error { h.stderr.Reset() cmd.Stdout = &h.stdout cmd.Stderr = &h.stderr - status := cmd.Run() + h.status = cmd.Run() if h.stdout.Len() > 0 { h.ctx.t.Log("standard output:") h.ctx.t.Log(h.stdout.String()) @@ -68,7 +83,7 @@ func (h *HelmCmd) exec(args ...string) error { h.ctx.t.Log(h.stderr.String()) } h.ran = true - return status + return h.status } // Stdout returns standard output of the helmCmd run as a string. diff --git a/test/e2e/helm_test.go b/test/e2e/helm_test.go index 2095346a3..0175c6e22 100644 --- a/test/e2e/helm_test.go +++ b/test/e2e/helm_test.go @@ -21,25 +21,31 @@ var ( repoName = flag.String("repo-name", "areese-charts", "Repository name") chart = flag.String("chart", "gs://areese-charts/replicatedservice-3.tgz", "Chart to deploy") host = flag.String("host", "", "The URL to the helm server") + + resourcifierImage = "quay.io/adamreese/resourcifier:latest" + expandybirdImage = "quay.io/adamreese/expandybird:latest" + managerImage = "quay.io/adamreese/manager:latest" ) func TestHelm(t *testing.T) { kube := NewKubeContext() helm := NewHelmContext(t) - t.Log(kube.CurrentContext()) - t.Log(kube.Cluster()) - t.Log(kube.Server()) + t.Logf("Kubenetes context: %s", kube.CurrentContext()) + t.Logf("Cluster: %s", kube.Cluster()) + t.Logf("Server: %s", kube.Server()) if !kube.Running() { t.Fatal("Not connected to kubernetes") } - t.Log("Kuberneter Version") t.Log(kube.Version()) + //TODO: skip check if running local binaries if !helmRunning(helm) { - t.Fatal("Helm is not installed") + t.Error("Helm is not installed") + helm.MustRun("server", "install", "--resourcifier-image", resourcifierImage, "--expandybird-image", expandybirdImage, "--manager-image", managerImage) + //TODO: wait for pods to be ready } helm.Host = helmHost() @@ -49,28 +55,30 @@ func TestHelm(t *testing.T) { } t.Logf("Using host: %v", helm.Host) - if !helm.Run("repo", "list").Contains(*repoURL) { + // Add repo if it does not exsit + if !helm.MustRun("repo", "list").Contains(*repoURL) { t.Logf("Adding repo %s %s", *repoName, *repoURL) - helm.Run("repo", "add", *repoName, *repoURL) + helm.MustRun("repo", "add", *repoName, *repoURL) } + // Generate a name deploymentName := genName() t.Log("Executing deploy") - helm.Run("deploy", "--properties", "container_port=6379,image=kubernetes/redis:v1,replicas=2", "--name", deploymentName, *chart) + helm.MustRun("deploy", "--properties", "container_port=6379,image=kubernetes/redis:v1,replicas=2", "--name", deploymentName, *chart) t.Log("Executing deployment list") - if !helm.Run("deployment", "list").Contains(deploymentName) { + if !helm.MustRun("deployment", "list").Contains(deploymentName) { t.Fatal("Could not list deployment") } t.Log("Executing deployment info") - if !helm.Run("deployment", "info", deploymentName).Contains("Deployed") { + if !helm.MustRun("deployment", "info", deploymentName).Contains("Deployed") { t.Fatal("Could not deploy") } t.Log("Executing deployment delete") - if !helm.Run("deployment", "rm", deploymentName).Contains("Deleted") { + if !helm.MustRun("deployment", "rm", deploymentName).Contains("Deleted") { t.Fatal("Could not delete deployment") } } @@ -87,6 +95,6 @@ func helmHost() string { } func helmRunning(h *HelmContext) bool { - out := h.Run("server", "status").Stdout() + out := h.MustRun("server", "status").Stdout() return strings.Count(out, "Running") == 5 }