Commit 3cf44795 authored by Baptiste Daroussin's avatar Baptiste Daroussin
Browse files

Trigger: test all triggering possibility in unit tests

parent fec332b6
......@@ -4,7 +4,10 @@
tests_init \
cleanup_lua \
deferred
deferred \
glob_trigger \
regex_trigger \
path_trigger
cleanup_lua_body() {
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "/"
......@@ -41,7 +44,7 @@ path_glob: [ "/*" ]
trigger: {
type: lua
script: <<EOS
print "deferred"
print("deferred " .. arg[1])
EOS
}
EOF
......@@ -56,10 +59,67 @@ OUTPUT='--sandbox
-- /trigger_dir
--end args
--
print "deferred"
print("deferred " .. arg[1])
'
atf_check -o inline:"${OUTPUT}" cat ${TMPDIR}/target/var/db/pkg/triggers/*
atf_check -o inline:"deferred\n" pkg -o PKG_DBDIR=${TMPDIR}/target/var/db/pkg triggers
atf_check -o inline:"deferred /trigger_dir\n" pkg -o PKG_DBDIR=${TMPDIR}/target/var/db/pkg triggers
# test the deferred trigger has been removed
atf_check ls ${TMPDIR}/target/var/db/pkg/triggers
}
glob_trigger_body() {
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "/"
mkdir trigger_dir/
cat << EOF >> trigger_dir/trigger.ucl
path_glob: [ "/*" ]
trigger: {
type: lua
script: <<EOS
print("triggered " .. arg[1])
EOS
}
EOF
echo ${TMPDIR}/trigger_dir/trigger.ucl > plist
atf_check pkg create -M test.ucl -p plist
mkdir target
unset PKG_TRIGGERS_DIR
atf_check -o inline:"triggered ${TMPDIR}/trigger_dir\n" pkg -o REPOS_DIR=/dev/null -o PKG_TRIGGERS_DIR="${TMPDIR}/trigger_dir" install -qfy ${TMPDIR}/test-1.pkg
}
regex_trigger_body() {
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "/"
mkdir trigger_dir/
cat << EOF >> trigger_dir/trigger.ucl
path_regex: [ ".*trigger.*" ]
trigger: {
type: lua
script: <<EOS
print("triggered " .. arg[1])
EOS
}
EOF
echo ${TMPDIR}/trigger_dir/trigger.ucl > plist
atf_check pkg create -M test.ucl -p plist
mkdir target
unset PKG_TRIGGERS_DIR
atf_check -o inline:"triggered ${TMPDIR}/trigger_dir\n" pkg -o REPOS_DIR=/dev/null -o PKG_TRIGGERS_DIR="${TMPDIR}/trigger_dir" install -qfy ${TMPDIR}/test-1.pkg
}
path_trigger_boddy() {
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "/"
mkdir trigger_dir/
cat << EOF >> trigger_dir/trigger.ucl
path: [ "${TMPDIR}/trigger_dir" ]
trigger: {
type: lua
script: <<EOS
print("triggered " .. arg[1])
EOS
}
EOF
echo ${TMPDIR}/trigger_dir/trigger.ucl > plist
atf_check pkg create -M test.ucl -p plist -r .
mkdir target
unset PKG_TRIGGERS_DIR
atf_check -o inline:"triggered ${TMPDIR}/trigger_dir\n" pkg -o REPOS_DIR=/dev/null -o PKG_TRIGGERS_DIR="${TMPDIR}/trigger_dir" install -qfy ${TMPDIR}/test-1.pkg
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment