summaryrefslogtreecommitdiff
diff options
authorPawel Stolowski <stolowski@gmail.com>2018-11-28 16:51:19 +0100
committerPawel Stolowski <stolowski@gmail.com>2018-11-28 16:51:19 +0100
commite54aaebcd567d91ab119c774ec69d6b3652a8592 (patch)
treeb2db34b951bfeb186ee931ea7110db82a69748f5
parent54638800fbc734f4a9bcaaccc2bbd89648e0ff15 (diff)
Spread test.pre-remove-hook
-rw-r--r--overlord/hookstate/hooks.go1
-rw-r--r--snap/hooktypes.go1
-rw-r--r--tests/main/install-refresh-remove-hooks/task.yaml13
3 files changed, 11 insertions, 4 deletions
diff --git a/overlord/hookstate/hooks.go b/overlord/hookstate/hooks.go
index 6b3c6b8ed2..459aca36ac 100644
--- a/overlord/hookstate/hooks.go
+++ b/overlord/hookstate/hooks.go
@@ -121,4 +121,5 @@ func setupHooks(hookMgr *HookManager) {
hookMgr.Register(regexp.MustCompile("^post-refresh$"), handlerGenerator)
hookMgr.Register(regexp.MustCompile("^pre-refresh$"), handlerGenerator)
hookMgr.Register(regexp.MustCompile("^remove$"), handlerGenerator)
+ hookMgr.Register(regexp.MustCompile("^pre-remove$"), handlerGenerator)
}
diff --git a/snap/hooktypes.go b/snap/hooktypes.go
index 97b59825a7..11d0d2a8f2 100644
--- a/snap/hooktypes.go
+++ b/snap/hooktypes.go
@@ -29,6 +29,7 @@ var supportedHooks = []*HookType{
NewHookType(regexp.MustCompile("^install$")),
NewHookType(regexp.MustCompile("^pre-refresh$")),
NewHookType(regexp.MustCompile("^post-refresh$")),
+ NewHookType(regexp.MustCompile("^pre-remove$")),
NewHookType(regexp.MustCompile("^remove$")),
NewHookType(regexp.MustCompile("^prepare-(?:plug|slot)-[-a-z0-9]+$")),
NewHookType(regexp.MustCompile("^unprepare-(?:plug|slot)-[-a-z0-9]+$")),
diff --git a/tests/main/install-refresh-remove-hooks/task.yaml b/tests/main/install-refresh-remove-hooks/task.yaml
index f24aaab6d9..8aadfc9474 100644
--- a/tests/main/install-refresh-remove-hooks/task.yaml
+++ b/tests/main/install-refresh-remove-hooks/task.yaml
@@ -2,9 +2,10 @@ summary: Check install, remove and pre-refresh/post-refresh hooks.
environment:
REMOVE_HOOK_FILE: "$HOME/snap/snap-hooks/common/remove-hook-executed"
+ PREREMOVE_HOOK_FILE: "$HOME/snap/snap-hooks/common/pre-remove-hook-executed"
restore: |
- rm -f "$REMOVE_HOOK_FILE"
+ rm -f "$REMOVE_HOOK_FILE" "$PREREMOVE_HOOK_FILE"
execute: |
#shellcheck source=tests/lib/snaps.sh
@@ -44,15 +45,19 @@ execute: |
snap set snap-hooks exitcode=0
snap remove --revision=x1 snap-hooks
if test -f "$REMOVE_HOOK_FILE"; then
- echo "Remove hook was executed. It shouldn't."
+ echo "remove hook was executed. It shouldn't."
exit 1
fi
- echo "Verify that remove hook is executed"
+ echo "Verify that remove and pre-remove hooks are executed"
snap set snap-hooks exitcode=0
snap remove snap-hooks
+ if ! test -f "$PREREMOVE_HOOK_FILE"; then
+ echo "pre-remove hook was not executed"
+ exit 1
+ fi
if ! test -f "$REMOVE_HOOK_FILE"; then
- echo "Remove hook was not executed"
+ echo "remove hook was not executed"
exit 1
fi