]> git.notmuchmail.org Git - notmuch/blobdiff - test/T400-hooks.sh
test: Add tests for write access to database from hooks.
[notmuch] / test / T400-hooks.sh
index a3dd4c6308941674c96b434525faead831f042ce..a2b67d59b5de42abdb162e71be8c02025cd23c53 100755 (executable)
@@ -2,6 +2,8 @@
 test_description='hooks'
 . $(dirname "$0")/test-lib.sh || exit 1
 
+test_require_external_prereq xapian-delve
+
 create_echo_hook () {
     local TOKEN="${RANDOM}"
     mkdir -p ${HOOK_DIR}
@@ -13,6 +15,19 @@ EOF
     echo "${TOKEN}" > ${2}
 }
 
+create_write_hook () {
+    local TOKEN="${RANDOM}"
+    mkdir -p ${HOOK_DIR}
+    cat <<EOF >"${HOOK_DIR}/${1}"
+#!/bin/sh
+if xapian-delve ${MAIL_DIR}/.notmuch/xapian | grep -q "writing = false"; then
+   echo "${TOKEN}" > ${3}
+fi
+EOF
+    chmod +x "${HOOK_DIR}/${1}"
+    echo "${TOKEN}" > ${2}
+}
+
 create_failing_hook () {
     local HOOK_DIR=${2}
     mkdir -p ${HOOK_DIR}
@@ -137,6 +152,19 @@ EOF
     chmod +x "${HOOK_DIR}/pre-new"
     test_expect_code 1 "notmuch new"
 
+    test_begin_subtest "post-new with write access [${config}]"
+    rm -rf ${HOOK_DIR}
+    create_write_hook "post-new" write.expected write.output $HOOK_DIR
+    NOTMUCH_NEW
+    test_expect_equal_file write.expected write.output
+
+    test_begin_subtest "pre-new with write access [${config}]"
+    test_subtest_known_broken
+    rm -rf ${HOOK_DIR}
+    create_write_hook "pre-new" write.expected write.output $HOOK_DIR
+    NOTMUCH_NEW
+    test_expect_equal_file write.expected write.output
+
     rm -rf ${HOOK_DIR}
 done
 test_done