Add more testcases for hooks
Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
parent
793050cc18
commit
dc40ccde2e
|
|
@ -261,4 +261,225 @@ releases:
|
||||||
logLevel: "info",
|
logLevel: "info",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("hooks for no-diff release", func(t *testing.T) {
|
||||||
|
check(t, testcase{
|
||||||
|
files: map[string]string{
|
||||||
|
"/path/to/helmfile.yaml": `
|
||||||
|
releases:
|
||||||
|
- name: foo
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
# only prepare and cleanup are run
|
||||||
|
- events: ["prepare", "preapply", "presync", "cleanup"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["foo"]
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
selectors: []string{"app=test"},
|
||||||
|
diffs: map[exectest.DiffKey]error{
|
||||||
|
{Name: "foo", Chart: "incubator/raw", Flags: "--kube-contextdefault--namespacedefault--detailed-exitcode"}: nil,
|
||||||
|
},
|
||||||
|
error: "",
|
||||||
|
// as we check for log output, set concurrency to 1 to avoid non-deterministic test result
|
||||||
|
concurrency: 1,
|
||||||
|
logLevel: "info",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("hooks are run on enabled release", func(t *testing.T) {
|
||||||
|
check(t, testcase{
|
||||||
|
files: map[string]string{
|
||||||
|
"/path/to/helmfile.yaml": `
|
||||||
|
values:
|
||||||
|
- bar:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
releases:
|
||||||
|
- name: foo
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
- events: ["prepare", "preapply", "presync"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["foo"]
|
||||||
|
- name: bar
|
||||||
|
condition: bar.enabled
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
- events: ["prepare", "preapply", "presync"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["bar"]
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
selectors: []string{"app=test"},
|
||||||
|
upgraded: []exectest.Release{
|
||||||
|
{Name: "foo"},
|
||||||
|
{Name: "bar"},
|
||||||
|
},
|
||||||
|
diffs: map[exectest.DiffKey]error{
|
||||||
|
{Name: "foo", Chart: "incubator/raw", Flags: "--kube-contextdefault--namespacedefault--detailed-exitcode"}: helmexec.ExitError{Code: 2},
|
||||||
|
{Name: "bar", Chart: "incubator/raw", Flags: "--kube-contextdefault--namespacedefault--detailed-exitcode"}: helmexec.ExitError{Code: 2},
|
||||||
|
},
|
||||||
|
error: "",
|
||||||
|
// as we check for log output, set concurrency to 1 to avoid non-deterministic test result
|
||||||
|
concurrency: 1,
|
||||||
|
logLevel: "info",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("hooks are not run on disabled release", func(t *testing.T) {
|
||||||
|
check(t, testcase{
|
||||||
|
files: map[string]string{
|
||||||
|
"/path/to/helmfile.yaml": `
|
||||||
|
values:
|
||||||
|
- bar:
|
||||||
|
enabled: false
|
||||||
|
|
||||||
|
releases:
|
||||||
|
- name: foo
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
- events: ["prepare", "preapply", "presync"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["foo"]
|
||||||
|
- name: bar
|
||||||
|
condition: bar.enabled
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
- events: ["prepare", "preapply", "presync"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["bar"]
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
selectors: []string{"app=test"},
|
||||||
|
upgraded: []exectest.Release{
|
||||||
|
{Name: "foo"},
|
||||||
|
},
|
||||||
|
diffs: map[exectest.DiffKey]error{
|
||||||
|
{Name: "foo", Chart: "incubator/raw", Flags: "--kube-contextdefault--namespacedefault--detailed-exitcode"}: helmexec.ExitError{Code: 2},
|
||||||
|
},
|
||||||
|
error: "",
|
||||||
|
// as we check for log output, set concurrency to 1 to avoid non-deterministic test result
|
||||||
|
concurrency: 1,
|
||||||
|
logLevel: "info",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("hooks are run on to-be-uninstalled release", func(t *testing.T) {
|
||||||
|
check(t, testcase{
|
||||||
|
files: map[string]string{
|
||||||
|
"/path/to/helmfile.yaml": `
|
||||||
|
releases:
|
||||||
|
- name: foo
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
- events: ["prepare", "preapply", "presync"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["foo"]
|
||||||
|
- name: bar
|
||||||
|
installed: false
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
- events: ["prepare", "preapply", "presync"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["bar"]
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
selectors: []string{"app=test"},
|
||||||
|
lists: map[exectest.ListKey]string{
|
||||||
|
{Filter: "^foo$", Flags: helmV2ListFlags}: `NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
|
||||||
|
foo 4 Fri Nov 1 08:40:07 2019 DEPLOYED raw-3.1.0 3.1.0 default
|
||||||
|
`,
|
||||||
|
{Filter: "^bar$", Flags: helmV2ListFlags}: `NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
|
||||||
|
bar 4 Fri Nov 1 08:40:07 2019 DEPLOYED raw-3.1.0 3.1.0 default
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
upgraded: []exectest.Release{
|
||||||
|
{Name: "foo"},
|
||||||
|
},
|
||||||
|
diffs: map[exectest.DiffKey]error{
|
||||||
|
{Name: "foo", Chart: "incubator/raw", Flags: "--kube-contextdefault--namespacedefault--detailed-exitcode"}: helmexec.ExitError{Code: 2},
|
||||||
|
},
|
||||||
|
error: "",
|
||||||
|
// as we check for log output, set concurrency to 1 to avoid non-deterministic test result
|
||||||
|
concurrency: 1,
|
||||||
|
logLevel: "info",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("hooks are not run on alreadyd uninstalled release", func(t *testing.T) {
|
||||||
|
check(t, testcase{
|
||||||
|
files: map[string]string{
|
||||||
|
"/path/to/helmfile.yaml": `
|
||||||
|
releases:
|
||||||
|
- name: foo
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
- events: ["prepare", "preapply", "presync"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["foo"]
|
||||||
|
- name: bar
|
||||||
|
installed: false
|
||||||
|
chart: incubator/raw
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: test
|
||||||
|
hooks:
|
||||||
|
- events: ["prepare", "preapply", "presync"]
|
||||||
|
command: echo
|
||||||
|
showlogs: true
|
||||||
|
args: ["bar"]
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
selectors: []string{"app=test"},
|
||||||
|
lists: map[exectest.ListKey]string{
|
||||||
|
{Filter: "^foo$", Flags: helmV2ListFlags}: `NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
|
||||||
|
foo 4 Fri Nov 1 08:40:07 2019 DEPLOYED raw-3.1.0 3.1.0 default
|
||||||
|
`,
|
||||||
|
{Filter: "^bar$", Flags: helmV2ListFlags}: ``,
|
||||||
|
},
|
||||||
|
upgraded: []exectest.Release{
|
||||||
|
{Name: "foo"},
|
||||||
|
},
|
||||||
|
diffs: map[exectest.DiffKey]error{
|
||||||
|
{Name: "foo", Chart: "incubator/raw", Flags: "--kube-contextdefault--namespacedefault--detailed-exitcode"}: helmexec.ExitError{Code: 2},
|
||||||
|
},
|
||||||
|
error: "",
|
||||||
|
// as we check for log output, set concurrency to 1 to avoid non-deterministic test result
|
||||||
|
concurrency: 1,
|
||||||
|
logLevel: "info",
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
pkg/app/testdata/testapply_hooks/hooks_are_not_run_on_alreadyd_uninstalled_release/log
vendored
Normal file
14
pkg/app/testdata/testapply_hooks/hooks_are_not_run_on_alreadyd_uninstalled_release/log
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
hook[prepare] logs | foo
|
||||||
|
hook[prepare] logs |
|
||||||
|
|
||||||
|
hook[preapply] logs | foo
|
||||||
|
hook[preapply] logs |
|
||||||
|
|
||||||
|
hook[presync] logs | foo
|
||||||
|
hook[presync] logs |
|
||||||
|
|
||||||
|
UPDATED RELEASES:
|
||||||
|
NAME CHART VERSION
|
||||||
|
foo incubator/raw 3.1.0
|
||||||
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
hook[prepare] logs | foo
|
||||||
|
hook[prepare] logs |
|
||||||
|
|
||||||
|
hook[preapply] logs | foo
|
||||||
|
hook[preapply] logs |
|
||||||
|
|
||||||
|
hook[presync] logs | foo
|
||||||
|
hook[presync] logs |
|
||||||
|
|
||||||
|
UPDATED RELEASES:
|
||||||
|
NAME CHART VERSION
|
||||||
|
foo incubator/raw
|
||||||
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
hook[prepare] logs | foo
|
||||||
|
hook[prepare] logs |
|
||||||
|
|
||||||
|
hook[prepare] logs | bar
|
||||||
|
hook[prepare] logs |
|
||||||
|
|
||||||
|
hook[preapply] logs | foo
|
||||||
|
hook[preapply] logs |
|
||||||
|
|
||||||
|
hook[preapply] logs | bar
|
||||||
|
hook[preapply] logs |
|
||||||
|
|
||||||
|
hook[presync] logs | foo
|
||||||
|
hook[presync] logs |
|
||||||
|
|
||||||
|
hook[presync] logs | bar
|
||||||
|
hook[presync] logs |
|
||||||
|
|
||||||
|
UPDATED RELEASES:
|
||||||
|
NAME CHART VERSION
|
||||||
|
foo incubator/raw
|
||||||
|
bar incubator/raw
|
||||||
|
|
||||||
24
pkg/app/testdata/testapply_hooks/hooks_are_run_on_to-be-uninstalled_release/log
vendored
Normal file
24
pkg/app/testdata/testapply_hooks/hooks_are_run_on_to-be-uninstalled_release/log
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
hook[prepare] logs | foo
|
||||||
|
hook[prepare] logs |
|
||||||
|
|
||||||
|
hook[preapply] logs | bar
|
||||||
|
hook[preapply] logs |
|
||||||
|
|
||||||
|
hook[presync] logs | bar
|
||||||
|
hook[presync] logs |
|
||||||
|
|
||||||
|
hook[preapply] logs | foo
|
||||||
|
hook[preapply] logs |
|
||||||
|
|
||||||
|
hook[presync] logs | foo
|
||||||
|
hook[presync] logs |
|
||||||
|
|
||||||
|
UPDATED RELEASES:
|
||||||
|
NAME CHART VERSION
|
||||||
|
foo incubator/raw 3.1.0
|
||||||
|
|
||||||
|
|
||||||
|
DELETED RELEASES:
|
||||||
|
NAME
|
||||||
|
bar
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
hook[prepare] logs | foo
|
||||||
|
hook[prepare] logs |
|
||||||
|
|
||||||
|
hook[cleanup] logs | foo
|
||||||
|
hook[cleanup] logs |
|
||||||
|
|
@ -161,7 +161,7 @@ func (helm *Helm) List(context helmexec.HelmContext, filter string, flags ...str
|
||||||
for k := range helm.Lists {
|
for k := range helm.Lists {
|
||||||
keys = append(keys, k.String())
|
keys = append(keys, k.String())
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("unexpected list key: %v in %v", key, strings.Join(keys, ", "))
|
return "", fmt.Errorf("unexpected list key: %v not found in %v", key, strings.Join(keys, ", "))
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue