|
|
@ -66,26 +66,18 @@ func (h *HookFailingKubeClient) Delete(resources kube.ResourceList) (*kube.Resul
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestHooksCleanUp(t *testing.T) {
|
|
|
|
func TestHooksCleanUp(t *testing.T) {
|
|
|
|
hookKubeClient := &HookFailingKubeClient{kubefake.PrintingKubeClient{Out: ioutil.Discard}, resource.Info{
|
|
|
|
|
|
|
|
Name: "build-config-2",
|
|
|
|
|
|
|
|
Namespace: "test",
|
|
|
|
|
|
|
|
}, []resource.Info{}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configuration := &Configuration{
|
|
|
|
|
|
|
|
Releases: storage.Init(driver.NewMemory()),
|
|
|
|
|
|
|
|
KubeClient: hookKubeClient,
|
|
|
|
|
|
|
|
Capabilities: chartutil.DefaultCapabilities,
|
|
|
|
|
|
|
|
Log: func(format string, v ...interface{}) {
|
|
|
|
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
if *verbose {
|
|
|
|
|
|
|
|
t.Logf(format, v...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hookEvent := release.HookPreInstall
|
|
|
|
hookEvent := release.HookPreInstall
|
|
|
|
|
|
|
|
|
|
|
|
r := &release.Release{
|
|
|
|
testCases := []struct {
|
|
|
|
|
|
|
|
name string
|
|
|
|
|
|
|
|
inputRelease release.Release
|
|
|
|
|
|
|
|
failOn resource.Info
|
|
|
|
|
|
|
|
expectedDeleteRecord []resource.Info
|
|
|
|
|
|
|
|
expectError bool
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Deletion hook runs for previously successful hook on failure of a heavier weight hook",
|
|
|
|
|
|
|
|
release.Release{
|
|
|
|
Name: "test-release",
|
|
|
|
Name: "test-release",
|
|
|
|
Namespace: "test",
|
|
|
|
Namespace: "test",
|
|
|
|
Hooks: []*release.Hook{
|
|
|
|
Hooks: []*release.Hook{
|
|
|
@ -140,11 +132,10 @@ data:
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}, resource.Info{
|
|
|
|
|
|
|
|
Name: "build-config-2",
|
|
|
|
_ = configuration.execHook(r, hookEvent, 600)
|
|
|
|
Namespace: "test",
|
|
|
|
|
|
|
|
}, []resource.Info{
|
|
|
|
if !reflect.DeepEqual(hookKubeClient.deleteRecord, []resource.Info{
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: "build-config-1",
|
|
|
|
Name: "build-config-1",
|
|
|
|
Namespace: "test",
|
|
|
|
Namespace: "test",
|
|
|
@ -157,11 +148,41 @@ data:
|
|
|
|
Name: "build-config-2",
|
|
|
|
Name: "build-config-2",
|
|
|
|
Namespace: "test",
|
|
|
|
Namespace: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}) {
|
|
|
|
}, true,
|
|
|
|
t.Fatalf("Got unexpected delete record")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//if err != nil {
|
|
|
|
for _, tc := range testCases {
|
|
|
|
// t.Fatalf("An expected error occured: %#v", err)
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
//}
|
|
|
|
kubeClient := &HookFailingKubeClient{
|
|
|
|
|
|
|
|
kubefake.PrintingKubeClient{Out: ioutil.Discard}, tc.failOn, []resource.Info{},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configuration := &Configuration{
|
|
|
|
|
|
|
|
Releases: storage.Init(driver.NewMemory()),
|
|
|
|
|
|
|
|
KubeClient: kubeClient,
|
|
|
|
|
|
|
|
Capabilities: chartutil.DefaultCapabilities,
|
|
|
|
|
|
|
|
Log: func(format string, v ...interface{}) {
|
|
|
|
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
if *verbose {
|
|
|
|
|
|
|
|
t.Logf(format, v...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := configuration.execHook(&tc.inputRelease, hookEvent, 600)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(kubeClient.deleteRecord, tc.expectedDeleteRecord) {
|
|
|
|
|
|
|
|
t.Fatalf("Got unexpected delete record, expected: %#v, but got: %#v", kubeClient.deleteRecord, tc.expectedDeleteRecord)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil && !tc.expectError {
|
|
|
|
|
|
|
|
t.Fatalf("Got an unexpected error.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err == nil && tc.expectError {
|
|
|
|
|
|
|
|
t.Fatalf("Expected and error but did not get it.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|