Skip to content

Commit f1b2093

Browse files
committed
tests: add very basic hooks test
1 parent 7765dd7 commit f1b2093

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

tests/xbps/libxbps/shell/Kyuafile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ atf_test_program{name="orphans_test"}
3030
atf_test_program{name="noextract_files_test"}
3131
atf_test_program{name="transaction_check_revdeps_test"}
3232
atf_test_program{name="repo_test"}
33+
atf_test_program{name="hooks_test"}

tests/xbps/libxbps/shell/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ TESTSHELL+= update_shlibs_test update_hold_test update_repolock_test
1010
TESTSHELL+= cyclic_deps_test conflicts_test update_itself_test
1111
TESTSHELL+= hold_test ignore_test preserve_test repo_test
1212
TESTSHELL+= noextract_files_test orphans_test transaction_check_revdeps_test
13+
TESTSHELL+= hooks_test
1314
EXTRA_FILES = Kyuafile
1415

1516
include $(TOPDIR)/mk/test.mk
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env atf-sh
2+
3+
atf_test_case hooks_basic
4+
5+
hooks_basic_head() {
6+
atf_set "descr" "Tests for basic hooks"
7+
}
8+
9+
hooks_basic_body() {
10+
mkdir -p repo pkg_A root/etc/xbps.d/hooks
11+
12+
cat <<-EOF > root/etc/xbps.d/hooks/00-pre-install-hook.hook
13+
[Hook]
14+
When = PreTransaction
15+
Exec = sh -c echo\ pre-install-hook\ >&2
16+
17+
[Match]
18+
PackageInstall = A
19+
EOF
20+
21+
cat <<-EOF > root/etc/xbps.d/hooks/00-post-install-hook.hook
22+
[Hook]
23+
When = PostTransaction
24+
Exec = sh -c echo\ post-install-hook\ >&2
25+
26+
[Match]
27+
PackageInstall = A
28+
EOF
29+
30+
cat <<-EOF > root/etc/xbps.d/hooks/00-pre-update-hook.hook
31+
[Hook]
32+
When = PreTransaction
33+
Exec = sh -c echo\ pre-update-hook\ >&2
34+
35+
[Match]
36+
PackageUpdate = A
37+
EOF
38+
39+
cat <<-EOF > root/etc/xbps.d/hooks/00-post-update-hook.hook
40+
[Hook]
41+
When = PostTransaction
42+
Exec = sh -c echo\ post-update-hook\ >&2
43+
44+
[Match]
45+
PackageUpdate = A
46+
EOF
47+
48+
cat <<-EOF > root/etc/xbps.d/hooks/00-pre-remove-hook.hook
49+
[Hook]
50+
When = PreTransaction
51+
Exec = sh -c echo\ pre-remove-hook\ >&2
52+
53+
[Match]
54+
PackageRemove = A
55+
EOF
56+
57+
cat <<-EOF > root/etc/xbps.d/hooks/00-post-remove-hook.hook
58+
[Hook]
59+
When = PostTransaction
60+
Exec = sh -c echo\ post-remove-hook\ >&2
61+
62+
[Match]
63+
PackageRemove = A
64+
EOF
65+
66+
cd repo
67+
atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A
68+
atf_check -o ignore -- xbps-rindex -a $PWD/*.xbps
69+
cd ..
70+
71+
atf_check \
72+
-o ignore \
73+
-e match:pre-install-hook \
74+
-e match:post-install-hook \
75+
-e not-match:pre-update-hook \
76+
-e not-match:post-update-hook \
77+
-e not-match:pre-remove-hook \
78+
-e not-match:post-remove-hook \
79+
-- xbps-install -r root --repository=repo -y A
80+
81+
cd repo
82+
atf_check -o ignore -- xbps-create -A noarch -n A-1.1_1 -s "A pkg" ../pkg_A
83+
atf_check -o ignore -e ignore -- xbps-rindex -a $PWD/*.xbps
84+
cd ..
85+
86+
atf_check \
87+
-o ignore \
88+
-e not-match:pre-install-hook \
89+
-e not-match:post-install-hook \
90+
-e match:pre-update-hook \
91+
-e match:post-update-hook \
92+
-e not-match:pre-remove-hook \
93+
-e not-match:post-remove-hook \
94+
-- xbps-install -r root --repository=repo -yu
95+
96+
atf_check \
97+
-o ignore \
98+
-e not-match:pre-install-hook \
99+
-e not-match:post-install-hook \
100+
-e not-match:pre-update-hook \
101+
-e not-match:post-update-hook \
102+
-e match:pre-remove-hook \
103+
-e match:post-remove-hook \
104+
-- xbps-remove -r root -y A
105+
}
106+
107+
atf_init_test_cases() {
108+
atf_add_test_case hooks_basic
109+
}

0 commit comments

Comments
 (0)