From 60bce486315b4b5763d2bd1e3282275f4c171b8e Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Thu, 31 Mar 2016 16:58:20 -0700 Subject: [PATCH] feat(e2e): starting framework for e2e tests --- test/e2e/helm.go | 75 +++++++++++++++++++++++++++++++++++++++++++ test/e2e/helm_test.go | 34 ++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 test/e2e/helm.go create mode 100644 test/e2e/helm_test.go diff --git a/test/e2e/helm.go b/test/e2e/helm.go new file mode 100644 index 000000000..7b0e39fa9 --- /dev/null +++ b/test/e2e/helm.go @@ -0,0 +1,75 @@ +package e2e + +import ( + "bytes" + "os" + "os/exec" + "path" + "path/filepath" + "testing" +) + +type HelmContext struct { + t *testing.T + Path string + Host string +} + +func NewHelmContext(t *testing.T) *HelmContext { + return &HelmContext{ + t: t, + Path: RepoRoot() + "/bin/helm", + } +} + +func (h *HelmContext) Run(args ...string) *HelmCmd { + cmd := h.newCmd() + if status := cmd.exec(args...); status != nil { + h.t.Fatalf("helm %v failed unexpectedly: %v", args, status) + } + return cmd +} + +func (h *HelmContext) newCmd() *HelmCmd { + return &HelmCmd{ + ctx: h, + } +} + +type HelmCmd struct { + ctx *HelmContext + path string + ran bool + stdout, stderr bytes.Buffer +} + +func (h *HelmCmd) exec(args ...string) error { + cmd := exec.Command(h.ctx.Path, args...) + h.stdout.Reset() + h.stderr.Reset() + cmd.Stdout = &h.stdout + cmd.Stderr = &h.stderr + status := cmd.Run() + h.ran = true + return status +} + +// Stdout returns standard output of the helmCmd run as a string. +func (h *HelmCmd) Stdout() string { + if !h.ran { + h.ctx.t.Fatal("internal testsuite error: stdout called before run") + } + return h.stdout.String() +} + +// Stderr returns standard error of the helmCmd run as a string. +func (h *HelmCmd) Stderr() string { + if !h.ran { + h.ctx.t.Fatal("internal testsuite error: stdout called before run") + } + return h.stderr.String() +} + +func RepoRoot() string { + return filepath.Clean(filepath.Join(path.Base(os.Args[0]), "../../..")) +} diff --git a/test/e2e/helm_test.go b/test/e2e/helm_test.go new file mode 100644 index 000000000..5c474796d --- /dev/null +++ b/test/e2e/helm_test.go @@ -0,0 +1,34 @@ +package e2e + +import ( + "os/exec" + "strings" + "testing" +) + +func TestHelm(t *testing.T) { + if !kubeRunning() { + t.Fatal("Not connected to kubernetes") + } + + helm := NewHelmContext(t) + if !helmRunning(helm) { + t.Fatal("Helm is not installed") + } + + // Setup helm host + + // Run deploy + + // Test deployment +} + +func helmRunning(h *HelmContext) bool { + out := h.Run("server", "status").Stdout() + return strings.Count(out, "Running") == 5 +} + +func kubeRunning() bool { + _, err := exec.Command("kubectl", "cluster-info").CombinedOutput() + return err == nil +}