From: David Bremner <david@tethera.net>
To: Matthew Lear <matt@bubblegen.co.uk>, notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 1/2] test: Add tests for write access to database from hooks.
Date: Thu, 18 Mar 2021 23:07:42 -0300 [thread overview]
Message-ID: <20210319020743.1491945-1-david@tethera.net> (raw)
In-Reply-To: <9C1993DF-84BD-4199-A9C8-BADA98498812@bubblegen.co.uk>
Recent changes to configuration handling meant the pre-new hook was
run while the database was open read only, limiting what could be done
in the hook. Add some known broken tests for this problem, as well as
a regression test for write access from the post-new hook.
---
test/T400-hooks.sh | 28 ++++++++++++++++++++++++++++
test/test-lib.sh | 1 +
2 files changed, 29 insertions(+)
diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh
index a3dd4c63..a2b67d59 100755
--- a/test/T400-hooks.sh
+++ b/test/T400-hooks.sh
@@ -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
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 29baa0c1..fc176af8 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -1271,3 +1271,4 @@ test_declare_external_prereq openssl
test_declare_external_prereq gpgsm
test_declare_external_prereq ${NOTMUCH_PYTHON}
test_declare_external_prereq xapian-metadata
+test_declare_external_prereq xapian-delve
--
2.30.2
next prev parent reply other threads:[~2021-03-19 2:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-18 8:32 Database locked when running hooks Matthew Lear
2021-03-18 10:55 ` David Bremner
2021-03-19 2:07 ` David Bremner [this message]
2021-03-19 2:07 ` [PATCH 2/2] CLI/new: drop the write lock to run the pre-new hook David Bremner
2021-03-24 11:03 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210319020743.1491945-1-david@tethera.net \
--to=david@tethera.net \
--cc=matt@bubblegen.co.uk \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).