Add helmfile test sub-command (#150)

**Feature**
An additional sub-command to the helmfile binary; helmfile test

**Why**
Helm provides helm test (https://github.com/kubernetes/helm/blob/master/docs/chart_tests.md) as a method to run automated tests post chart install to ensure things are working as they should be.

It would be nice to be able to run something like helmfile test against a particular helmfile in order to run helm tests against all charts/releases defined in the file. Either as part of the sync (i.e. helmfile sync --test) to be ran immediately after the corresponding chart is installed, or as a separate command ran after a sync (i.e. helmfile test).

A chart without tests will exit with a 0 status, so it can be safely ran against any charts.

**Notes**

`--cleanup` (bool) & `--timeout` (default: 300) are available as first class arguments. Additional arguments can be passed to the helm binary as with other sub commands using `--args=`

Resolves #144
This commit is contained in:
Mike Eves
2018-05-22 17:12:48 +09:00
committed by KUOKA Yusuke
parent 5735efa8c0
commit 37f6ae8557
7 changed files with 102 additions and 0 deletions
+6
View File
@@ -85,6 +85,12 @@ func (helm *execer) DeleteRelease(name string, flags ...string) error {
return err
}
func (helm *execer) TestRelease(name string, flags ...string) error {
out, err := helm.exec(append([]string{"test", name}, flags...)...)
helm.write(out)
return err
}
func (helm *execer) exec(args ...string) ([]byte, error) {
cmdargs := args
if len(helm.extra) > 0 {
+19
View File
@@ -164,6 +164,25 @@ func Test_DeleteRelease_Flags(t *testing.T) {
}
}
func Test_TestRelease(t *testing.T) {
var buffer bytes.Buffer
helm := MockExecer(&buffer, "dev")
helm.TestRelease("release")
expected := "exec: helm test release --kube-context dev\n"
if buffer.String() != expected {
t.Errorf("helmexec.TestRelease()\nactual = %v\nexpect = %v", buffer.String(), expected)
}
}
func Test_TestRelease_Flags(t *testing.T) {
var buffer bytes.Buffer
helm := MockExecer(&buffer, "dev")
helm.TestRelease("release", "--cleanup", "--timeout", "60")
expected := "exec: helm test release --cleanup --timeout 60 --kube-context dev\n"
if buffer.String() != expected {
t.Errorf("helmexec.TestRelease()\nactual = %v\nexpect = %v", buffer.String(), expected)
}
}
func Test_ReleaseStatus(t *testing.T) {
var buffer bytes.Buffer
helm := MockExecer(&buffer, "dev")
+1
View File
@@ -11,6 +11,7 @@ type Interface interface {
DiffRelease(name, chart string, flags ...string) error
ReleaseStatus(name string) error
DeleteRelease(name string, flags ...string) error
TestRelease(name string, flags ...string) error
DecryptSecret(name string) (string, error)
}