fix(tiller): add test for failed hooks

This commit is contained in:
Matt Butcher 2016-09-06 18:00:08 -06:00
parent 53b01949a8
commit 663f2b0f1d
2 changed files with 36 additions and 1 deletions

View File

@ -588,7 +588,7 @@ func (s *releaseServer) execHook(hs []*release.Hook, name, namespace, hook strin
b := bytes.NewBufferString(h.Manifest)
if err := kubeCli.Create(namespace, b); err != nil {
log.Printf("wrning: Release %q pre-install %s failed: %s", name, h.Path, err)
log.Printf("warning: Release %q pre-install %s failed: %s", name, h.Path, err)
return err
}
// No way to rewind a bytes.Buffer()?

View File

@ -17,7 +17,9 @@ limitations under the License.
package main
import (
"errors"
"fmt"
"io"
"os"
"regexp"
"strings"
@ -431,6 +433,25 @@ func TestInstallReleaseNoHooks(t *testing.T) {
}
}
func TestInstallReleaseFailedHooks(t *testing.T) {
c := context.Background()
rs := rsFixture()
rs.env.Releases.Create(releaseStub())
rs.env.KubeClient = newHookFailingKubeClient()
req := &services.InstallReleaseRequest{
Chart: chartStub(),
}
res, err := rs.InstallRelease(c, req)
if err == nil {
t.Error("Expected failed install")
}
if hl := res.Release.Info.Status.Code; hl != release.Status_FAILED {
t.Errorf("Expected FAILED release. Got %d", hl)
}
}
func TestInstallReleaseReuseName(t *testing.T) {
c := context.Background()
rs := rsFixture()
@ -912,6 +933,20 @@ func mockEnvironment() *environment.Environment {
return e
}
func newHookFailingKubeClient() *hookFailingKubeClient {
return &hookFailingKubeClient{
PrintingKubeClient: environment.PrintingKubeClient{Out: os.Stdout},
}
}
type hookFailingKubeClient struct {
environment.PrintingKubeClient
}
func (h *hookFailingKubeClient) WatchUntilReady(ns string, r io.Reader) error {
return errors.New("Failed watch")
}
type mockListServer struct {
val *services.ListReleasesResponse
}