ref(pkg/releasetesting): simplify test setup

pull/3945/head
Adam Reese 7 years ago
parent c5151fb7b3
commit 1e2e65ce54
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -17,81 +17,50 @@ limitations under the License.
package releasetesting package releasetesting
import ( import (
"bytes"
"errors" "errors"
"io"
"io/ioutil"
"testing" "testing"
"k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
tillerEnv "k8s.io/helm/pkg/tiller/environment"
) )
func TestCreateTestPodSuccess(t *testing.T) { func TestCreateTestPodSuccess(t *testing.T) {
env := testEnvFixture() env := testEnvFixture()
test := testFixture() test := testFixture()
err := env.createTestPod(test) if err := env.createTestPod(test); err != nil {
if err != nil {
t.Errorf("Expected no error, got an error: %s", err) t.Errorf("Expected no error, got an error: %s", err)
} }
} }
func TestCreateTestPodFailure(t *testing.T) { func TestCreateTestPodFailure(t *testing.T) {
env := testEnvFixture() env := testEnvFixture()
env.KubeClient = newCreateFailingKubeClient() env.KubeClient = &mockKubeClient{
err: errors.New("We ran out of budget and couldn't create finding-nemo"),
}
test := testFixture() test := testFixture()
err := env.createTestPod(test) if err := env.createTestPod(test); err == nil {
if err == nil {
t.Errorf("Expected error, got no error") t.Errorf("Expected error, got no error")
} }
if test.result.Info == "" { if test.result.Info == "" {
t.Errorf("Expected error to be saved in test result info but found empty string") t.Errorf("Expected error to be saved in test result info but found empty string")
} }
if test.result.Status != release.TestRun_FAILURE { if test.result.Status != release.TestRun_FAILURE {
t.Errorf("Expected test result status to be failure but got: %v", test.result.Status) t.Errorf("Expected test result status to be failure but got: %v", test.result.Status)
} }
} }
func TestDeleteTestPods(t *testing.T) {
mockTestSuite := testSuiteFixture([]string{manifestWithTestSuccessHook})
mockTestEnv := newMockTestingEnvironment()
mockTestEnv.KubeClient = newGetFailingKubeClient()
mockTestEnv.DeleteTestPods(mockTestSuite.TestManifests)
for _, testManifest := range mockTestSuite.TestManifests {
if _, err := mockTestEnv.KubeClient.Get(mockTestEnv.Namespace, bytes.NewBufferString(testManifest)); err == nil {
t.Error("Expected error, got nil")
}
}
}
func TestStreamMessage(t *testing.T) { func TestStreamMessage(t *testing.T) {
tEnv := mockTillerEnvironment() env := testEnvFixture()
defer close(env.Mesages)
ch := make(chan *hapi.TestReleaseResponse, 1)
defer close(ch)
mockTestEnv := &Environment{
Namespace: "default",
KubeClient: tEnv.KubeClient,
Timeout: 1,
Mesages: ch,
}
expectedMessage := "testing streamMessage" expectedMessage := "testing streamMessage"
expectedStatus := release.TestRun_SUCCESS expectedStatus := release.TestRun_SUCCESS
err := mockTestEnv.streamMessage(expectedMessage, expectedStatus) if err := env.streamMessage(expectedMessage, expectedStatus); err != nil {
if err != nil {
t.Errorf("Expected no errors, got: %s", err) t.Errorf("Expected no errors, got: %s", err)
} }
got := <-mockTestEnv.Mesages got := <-env.Mesages
if got.Msg != expectedMessage { if got.Msg != expectedMessage {
t.Errorf("Expected message: %s, got: %s", expectedMessage, got.Msg) t.Errorf("Expected message: %s, got: %s", expectedMessage, got.Msg)
} }
@ -99,39 +68,3 @@ func TestStreamMessage(t *testing.T) {
t.Errorf("Expected status: %v, got: %v", expectedStatus, got.Status) t.Errorf("Expected status: %v, got: %v", expectedStatus, got.Status)
} }
} }
func newMockTestingEnvironment() *Environment {
return &Environment{
Namespace: "default",
KubeClient: mockTillerEnvironment().KubeClient,
Timeout: 1,
}
}
type getFailingKubeClient struct {
tillerEnv.PrintingKubeClient
}
func newGetFailingKubeClient() *getFailingKubeClient {
return &getFailingKubeClient{
PrintingKubeClient: tillerEnv.PrintingKubeClient{Out: ioutil.Discard},
}
}
func (p *getFailingKubeClient) Get(ns string, r io.Reader) (string, error) {
return "", errors.New("in the end, they did not find Nemo")
}
type createFailingKubeClient struct {
tillerEnv.PrintingKubeClient
}
func newCreateFailingKubeClient() *createFailingKubeClient {
return &createFailingKubeClient{
PrintingKubeClient: tillerEnv.PrintingKubeClient{Out: ioutil.Discard},
}
}
func (p *createFailingKubeClient) Create(ns string, r io.Reader, t int64, shouldWait bool) error {
return errors.New("We ran out of budget and couldn't create finding-nemo")
}

@ -18,18 +18,14 @@ package releasetesting
import ( import (
"io" "io"
"io/ioutil"
"testing" "testing"
"time" "time"
"k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/chart"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/storage" "k8s.io/helm/pkg/tiller/environment"
"k8s.io/helm/pkg/storage/driver"
tillerEnv "k8s.io/helm/pkg/tiller/environment"
) )
const manifestWithTestSuccessHook = ` const manifestWithTestSuccessHook = `
@ -70,22 +66,22 @@ data:
` `
func TestRun(t *testing.T) { func TestRun(t *testing.T) {
testManifests := []string{manifestWithTestSuccessHook, manifestWithTestFailureHook} testManifests := []string{manifestWithTestSuccessHook, manifestWithTestFailureHook}
ts := testSuiteFixture(testManifests) ts := testSuiteFixture(testManifests)
ch := make(chan *hapi.TestReleaseResponse, 1)
env := testEnvFixture() env := testEnvFixture()
env.Mesages = ch
go func() { go func() {
defer close(ch) defer close(env.Mesages)
if err := ts.Run(env); err != nil { if err := ts.Run(env); err != nil {
t.Error(err) t.Error(err)
} }
}() }()
for range ch { // drain for i := 0; i <= 4; i++ {
<-env.Mesages
}
if _, ok := <-env.Mesages; ok {
t.Errorf("Expected 4 messages streamed")
} }
if ts.StartedAt.IsZero() { if ts.StartedAt.IsZero() {
@ -128,19 +124,16 @@ func TestRun(t *testing.T) {
func TestRunEmptyTestSuite(t *testing.T) { func TestRunEmptyTestSuite(t *testing.T) {
ts := testSuiteFixture([]string{}) ts := testSuiteFixture([]string{})
ch := make(chan *hapi.TestReleaseResponse, 1)
env := testEnvFixture() env := testEnvFixture()
env.Mesages = ch
go func() { go func() {
defer close(ch) defer close(env.Mesages)
if err := ts.Run(env); err != nil { if err := ts.Run(env); err != nil {
t.Error(err) t.Error(err)
} }
}() }()
msg := <-ch msg := <-env.Mesages
if msg.Msg != "No Tests Found" { if msg.Msg != "No Tests Found" {
t.Errorf("Expected message 'No Tests Found', Got: %v", msg.Msg) t.Errorf("Expected message 'No Tests Found', Got: %v", msg.Msg)
} }
@ -157,30 +150,29 @@ func TestRunEmptyTestSuite(t *testing.T) {
func TestRunSuccessWithTestFailureHook(t *testing.T) { func TestRunSuccessWithTestFailureHook(t *testing.T) {
ts := testSuiteFixture([]string{manifestWithTestFailureHook}) ts := testSuiteFixture([]string{manifestWithTestFailureHook})
ch := make(chan *hapi.TestReleaseResponse, 1)
env := testEnvFixture() env := testEnvFixture()
env.KubeClient = newPodFailedKubeClient() env.KubeClient = &mockKubeClient{podFail: true}
env.Mesages = ch
go func() { go func() {
defer close(ch) defer close(env.Mesages)
if err := ts.Run(env); err != nil { if err := ts.Run(env); err != nil {
t.Error(err) t.Error(err)
} }
}() }()
for range ch { // drain for i := 0; i <= 4; i++ {
<-env.Mesages
}
if _, ok := <-env.Mesages; ok {
t.Errorf("Expected 4 messages streamed")
} }
if ts.StartedAt.IsZero() { if ts.StartedAt.IsZero() {
t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt) t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt)
} }
if ts.CompletedAt.IsZero() { if ts.CompletedAt.IsZero() {
t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt) t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt)
} }
if len(ts.Results) != 1 { if len(ts.Results) != 1 {
t.Errorf("Expected 1 test result. Got %v", len(ts.Results)) t.Errorf("Expected 1 test result. Got %v", len(ts.Results))
} }
@ -189,75 +181,38 @@ func TestRunSuccessWithTestFailureHook(t *testing.T) {
if result.StartedAt.IsZero() { if result.StartedAt.IsZero() {
t.Errorf("Expected test StartedAt to not be nil. Got: %v", result.StartedAt) t.Errorf("Expected test StartedAt to not be nil. Got: %v", result.StartedAt)
} }
if result.CompletedAt.IsZero() { if result.CompletedAt.IsZero() {
t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result.CompletedAt) t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result.CompletedAt)
} }
if result.Name != "gold-rush" { if result.Name != "gold-rush" {
t.Errorf("Expected test name to be gold-rush, Got: %v", result.Name) t.Errorf("Expected test name to be gold-rush, Got: %v", result.Name)
} }
if result.Status != release.TestRun_SUCCESS { if result.Status != release.TestRun_SUCCESS {
t.Errorf("Expected test result to be successful, got: %v", result.Status) t.Errorf("Expected test result to be successful, got: %v", result.Status)
} }
} }
func TestExtractTestManifestsFromHooks(t *testing.T) { func TestExtractTestManifestsFromHooks(t *testing.T) {
rel := releaseStub() testManifests := extractTestManifestsFromHooks(hooksStub)
testManifests := extractTestManifestsFromHooks(rel.Hooks)
if len(testManifests) != 1 { if len(testManifests) != 1 {
t.Errorf("Expected 1 test manifest, Got: %v", len(testManifests)) t.Errorf("Expected 1 test manifest, Got: %v", len(testManifests))
} }
} }
func chartStub() *chart.Chart { var hooksStub = []*release.Hook{
return &chart.Chart{
Metadata: &chart.Metadata{
Name: "nemo",
},
Templates: []*chart.File{
{Name: "templates/hello", Data: []byte("hello: world")},
{Name: "templates/hooks", Data: []byte(manifestWithTestSuccessHook)},
},
}
}
func releaseStub() *release.Release {
return &release.Release{
Name: "lost-fish",
Info: &release.Info{
FirstDeployed: time.Now(),
LastDeployed: time.Now(),
Status: &release.Status{Code: release.Status_DEPLOYED},
Description: "a release stub",
},
Chart: chartStub(),
Config: &chart.Config{Raw: `name: value`},
Version: 1,
Hooks: []*release.Hook{
{ {
Name: "finding-nemo",
Kind: "Pod",
Path: "finding-nemo",
Manifest: manifestWithTestSuccessHook, Manifest: manifestWithTestSuccessHook,
Events: []release.HookEvent{ Events: []release.HookEvent{
release.Hook_RELEASE_TEST_SUCCESS, release.Hook_RELEASE_TEST_SUCCESS,
}, },
}, },
{ {
Name: "test-cm",
Kind: "ConfigMap",
Path: "test-cm",
Manifest: manifestWithInstallHooks, Manifest: manifestWithInstallHooks,
Events: []release.HookEvent{ Events: []release.HookEvent{
release.Hook_POST_INSTALL, release.Hook_POST_INSTALL,
release.Hook_PRE_DELETE,
}, },
}, },
},
}
} }
func testFixture() *test { func testFixture() *test {
@ -273,49 +228,36 @@ func testSuiteFixture(testManifests []string) *TestSuite {
TestManifests: testManifests, TestManifests: testManifests,
Results: testResults, Results: testResults,
} }
return ts return ts
} }
func testEnvFixture() *Environment { func testEnvFixture() *Environment {
return &Environment{ return &Environment{
Namespace: "default", Namespace: "default",
KubeClient: mockTillerEnvironment().KubeClient, KubeClient: &mockKubeClient{},
Timeout: 1, Timeout: 1,
Mesages: make(chan *hapi.TestReleaseResponse, 1),
} }
} }
func mockTillerEnvironment() *tillerEnv.Environment { type mockKubeClient struct {
e := tillerEnv.New() environment.KubeClient
e.Releases = storage.Init(driver.NewMemory()) podFail bool
e.KubeClient = newPodSucceededKubeClient() err error
return e
}
type podSucceededKubeClient struct {
tillerEnv.PrintingKubeClient
} }
func newPodSucceededKubeClient() *podSucceededKubeClient { func (c *mockKubeClient) WaitAndGetCompletedPodPhase(_ string, _ io.Reader, _ time.Duration) (core.PodPhase, error) {
return &podSucceededKubeClient{ if c.podFail {
PrintingKubeClient: tillerEnv.PrintingKubeClient{Out: ioutil.Discard}, return core.PodFailed, nil
}
} }
func (p *podSucceededKubeClient) WaitAndGetCompletedPodPhase(ns string, r io.Reader, timeout time.Duration) (core.PodPhase, error) {
return core.PodSucceeded, nil return core.PodSucceeded, nil
} }
func (c *mockKubeClient) Get(_ string, _ io.Reader) (string, error) {
type podFailedKubeClient struct { return "", nil
tillerEnv.PrintingKubeClient
} }
func (c *mockKubeClient) Create(_ string, _ io.Reader, _ int64, _ bool) error {
func newPodFailedKubeClient() *podFailedKubeClient { return c.err
return &podFailedKubeClient{
PrintingKubeClient: tillerEnv.PrintingKubeClient{Out: ioutil.Discard},
} }
} func (c *mockKubeClient) Delete(_ string, _ io.Reader) error {
return nil
func (p *podFailedKubeClient) WaitAndGetCompletedPodPhase(ns string, r io.Reader, timeout time.Duration) (core.PodPhase, error) {
return core.PodFailed, nil
} }

@ -36,8 +36,6 @@ import (
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/hooks" "k8s.io/helm/pkg/hooks"
"k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/kube"
"k8s.io/helm/pkg/storage"
"k8s.io/helm/pkg/storage/driver"
"k8s.io/helm/pkg/tiller/environment" "k8s.io/helm/pkg/tiller/environment"
) )
@ -379,7 +377,6 @@ func releaseWithKeepStub(rlsName string) *release.Release {
func MockEnvironment() *environment.Environment { func MockEnvironment() *environment.Environment {
e := environment.New() e := environment.New()
e.Releases = storage.Init(driver.NewMemory())
e.KubeClient = &environment.PrintingKubeClient{Out: ioutil.Discard} e.KubeClient = &environment.PrintingKubeClient{Out: ioutil.Discard}
return e return e
} }
@ -432,8 +429,7 @@ func (kc *mockHooksKubeClient) makeManifest(r io.Reader) (*mockHooksManifest, er
} }
manifest := &mockHooksManifest{} manifest := &mockHooksManifest{}
err = yaml.Unmarshal(b, manifest) if err = yaml.Unmarshal(b, manifest); err != nil {
if err != nil {
return nil, err return nil, err
} }
@ -498,7 +494,6 @@ func (kc *mockHooksKubeClient) WaitAndGetCompletedPodPhase(namespace string, rea
func deletePolicyStub(kubeClient *mockHooksKubeClient) *ReleaseServer { func deletePolicyStub(kubeClient *mockHooksKubeClient) *ReleaseServer {
e := environment.New() e := environment.New()
e.Releases = storage.Init(driver.NewMemory())
e.KubeClient = kubeClient e.KubeClient = kubeClient
dc := fake.NewSimpleClientset().Discovery() dc := fake.NewSimpleClientset().Discovery()
@ -535,24 +530,21 @@ name: value`, hookName, extraAnnotationsStr),
} }
func execHookShouldSucceed(rs *ReleaseServer, hook *release.Hook, releaseName string, namespace string, hookType string) error { func execHookShouldSucceed(rs *ReleaseServer, hook *release.Hook, releaseName string, namespace string, hookType string) error {
err := rs.execHook([]*release.Hook{hook}, releaseName, namespace, hookType, 600) if err := rs.execHook([]*release.Hook{hook}, releaseName, namespace, hookType, 600); err != nil {
if err != nil {
return fmt.Errorf("expected hook %s to be successful: %s", hook.Name, err) return fmt.Errorf("expected hook %s to be successful: %s", hook.Name, err)
} }
return nil return nil
} }
func execHookShouldFail(rs *ReleaseServer, hook *release.Hook, releaseName string, namespace string, hookType string) error { func execHookShouldFail(rs *ReleaseServer, hook *release.Hook, releaseName string, namespace string, hookType string) error {
err := rs.execHook([]*release.Hook{hook}, releaseName, namespace, hookType, 600) if err := rs.execHook([]*release.Hook{hook}, releaseName, namespace, hookType, 600); err == nil {
if err == nil {
return fmt.Errorf("expected hook %s to be failed", hook.Name) return fmt.Errorf("expected hook %s to be failed", hook.Name)
} }
return nil return nil
} }
func execHookShouldFailWithError(rs *ReleaseServer, hook *release.Hook, releaseName string, namespace string, hookType string, expectedError error) error { func execHookShouldFailWithError(rs *ReleaseServer, hook *release.Hook, releaseName string, namespace string, hookType string, expectedError error) error {
err := rs.execHook([]*release.Hook{hook}, releaseName, namespace, hookType, 600) if err := rs.execHook([]*release.Hook{hook}, releaseName, namespace, hookType, 600); err != expectedError {
if err != expectedError {
return fmt.Errorf("expected hook %s to fail with error %v, got %v", hook.Name, expectedError, err) return fmt.Errorf("expected hook %s to fail with error %v, got %v", hook.Name, expectedError, err)
} }
return nil return nil
@ -584,8 +576,7 @@ func TestSuccessfulHookWithoutDeletePolicy(t *testing.T) {
ctx := newDeletePolicyContext() ctx := newDeletePolicyContext()
hook := deletePolicyHookStub(ctx.HookName, nil, nil) hook := deletePolicyHookStub(ctx.HookName, nil, nil)
err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
@ -600,8 +591,7 @@ func TestFailedHookWithoutDeletePolicy(t *testing.T) {
nil, nil,
) )
err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
@ -616,8 +606,7 @@ func TestSuccessfulHookWithSucceededDeletePolicy(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_SUCCEEDED}, []release.HookDeletePolicy{release.Hook_SUCCEEDED},
) )
err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource {
@ -632,8 +621,7 @@ func TestSuccessfulHookWithFailedDeletePolicy(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_FAILED}, []release.HookDeletePolicy{release.Hook_FAILED},
) )
err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
@ -652,8 +640,7 @@ func TestFailedHookWithSucceededDeletePolicy(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_SUCCEEDED}, []release.HookDeletePolicy{release.Hook_SUCCEEDED},
) )
err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
@ -672,8 +659,7 @@ func TestFailedHookWithFailedDeletePolicy(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_FAILED}, []release.HookDeletePolicy{release.Hook_FAILED},
) )
err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource {
@ -691,8 +677,7 @@ func TestSuccessfulHookWithSuccededOrFailedDeletePolicy(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_FAILED}, []release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_FAILED},
) )
err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource {
@ -711,8 +696,7 @@ func TestFailedHookWithSuccededOrFailedDeletePolicy(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_FAILED}, []release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_FAILED},
) )
err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource {
@ -725,20 +709,15 @@ func TestHookAlreadyExists(t *testing.T) {
hook := deletePolicyHookStub(ctx.HookName, nil, nil) hook := deletePolicyHookStub(ctx.HookName, nil, nil)
err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
t.Errorf("expected resource %s to be existing after hook succeeded", hook.Name) t.Errorf("expected resource %s to be existing after hook succeeded", hook.Name)
} }
if err := execHookShouldFailWithError(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade, errResourceExists); err != nil {
err = execHookShouldFailWithError(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade, errResourceExists)
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
t.Errorf("expected resource %s to be existing after already exists error", hook.Name) t.Errorf("expected resource %s to be existing after already exists error", hook.Name)
} }
@ -752,20 +731,15 @@ func TestHookDeletingWithBeforeHookCreationDeletePolicy(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_BEFORE_HOOK_CREATION}, []release.HookDeletePolicy{release.Hook_BEFORE_HOOK_CREATION},
) )
err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
t.Errorf("expected resource %s to be existing after hook succeeded", hook.Name) t.Errorf("expected resource %s to be existing after hook succeeded", hook.Name)
} }
if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade); err != nil {
err = execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade)
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
t.Errorf("expected resource %s to be existing after hook succeeded", hook.Name) t.Errorf("expected resource %s to be existing after hook succeeded", hook.Name)
} }
@ -781,20 +755,15 @@ func TestSuccessfulHookWithMixedDeletePolicies(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_BEFORE_HOOK_CREATION}, []release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_BEFORE_HOOK_CREATION},
) )
err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource {
t.Errorf("expected resource %s to be unexisting after hook succeeded", hook.Name) t.Errorf("expected resource %s to be unexisting after hook succeeded", hook.Name)
} }
if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade); err != nil {
err = execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade)
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource {
t.Errorf("expected resource %s to be unexisting after hook succeeded", hook.Name) t.Errorf("expected resource %s to be unexisting after hook succeeded", hook.Name)
} }
@ -811,20 +780,15 @@ func TestFailedHookWithMixedDeletePolicies(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_BEFORE_HOOK_CREATION}, []release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_BEFORE_HOOK_CREATION},
) )
err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
t.Errorf("expected resource %s to be existing after hook failed", hook.Name) t.Errorf("expected resource %s to be existing after hook failed", hook.Name)
} }
if err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade); err != nil {
err = execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade)
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
t.Errorf("expected resource %s to be existing after hook failed", hook.Name) t.Errorf("expected resource %s to be existing after hook failed", hook.Name)
} }
@ -841,11 +805,9 @@ func TestFailedThenSuccessfulHookWithMixedDeletePolicies(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_BEFORE_HOOK_CREATION}, []release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_BEFORE_HOOK_CREATION},
) )
err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall) if err := execHookShouldFail(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreInstall); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; !hasResource {
t.Errorf("expected resource %s to be existing after hook failed", hook.Name) t.Errorf("expected resource %s to be existing after hook failed", hook.Name)
} }
@ -857,11 +819,9 @@ func TestFailedThenSuccessfulHookWithMixedDeletePolicies(t *testing.T) {
[]release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_BEFORE_HOOK_CREATION}, []release.HookDeletePolicy{release.Hook_SUCCEEDED, release.Hook_BEFORE_HOOK_CREATION},
) )
err = execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade) if err := execHookShouldSucceed(ctx.ReleaseServer, hook, ctx.ReleaseName, ctx.Namespace, hooks.PreUpgrade); err != nil {
if err != nil {
t.Error(err) t.Error(err)
} }
if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource { if _, hasResource := ctx.KubeClient.Resources[hook.Name]; hasResource {
t.Errorf("expected resource %s to be unexisting after hook succeeded", hook.Name) t.Errorf("expected resource %s to be unexisting after hook succeeded", hook.Name)
} }

Loading…
Cancel
Save