feat(e2e): starting framework for e2e tests

pull/606/head
Adam Reese 10 years ago
parent 39897eaf89
commit 60bce48631

@ -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]), "../../.."))
}

@ -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
}
Loading…
Cancel
Save