summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2021-06-10 14:59:43 -0400
committerKyle Meyer <kyle@kyleam.com>2021-06-11 13:36:54 -0400
commitc901d3ec025773c8eae04257099fcdfe704085ac (patch)
tree738fb967fe89d468e5a5d8f56810c544bd9075bd /tests
parent61952fe189a2a1e97b7156eaee831a5a1915dd57 (diff)
downloadpiem-c901d3ec025773c8eae04257099fcdfe704085ac.tar.gz
Support reading inboxes from ~/.public-inbox/config
A client may mirror and configure inboxes locally. Doing so enables fast local access to public-inbox-httpd and public-inbox-nntpd. And with the next pubic-inbox release (v1.7), it will be necessary to set up local externals for lei. That can lead to a good amount of information being duplicated between the piem-inboxes option and ~/.public-inbox/config. To avoid this, let users set an option to enable collecting information from public-inbox's configuration. This relies on code getting the list of inboxes with piem-merged-inboxes rather than inspecting piem-inboxes directly. That should be okay because at this point there should be very few third-party callers. An alternative would be to merge values from the configuration into the value of piem-inboxes. That'd let callers continue to inspect public-inboxes, but I'd prefer not to touch the value of a user option. Message-Id: <20210610185943.14155-5-kyle@kyleam.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/piem-rmail-tests.el6
-rw-r--r--tests/piem-tests.el70
2 files changed, 72 insertions, 4 deletions
diff --git a/tests/piem-rmail-tests.el b/tests/piem-rmail-tests.el
index b489594..dbf655f 100644
--- a/tests/piem-rmail-tests.el
+++ b/tests/piem-rmail-tests.el
@@ -53,7 +53,8 @@ no thanks
(with-temp-buffer
(insert piem-rmail-tests-mbox-text)
(rmail-mode)
- (let ((piem-inboxes '(("foo" :address "i@inbox.example.com"))))
+ (let ((piem-get-inboxes-from-config nil)
+ (piem-inboxes '(("foo" :address "i@inbox.example.com"))))
(piem-rmail-get-inbox))))))
(ert-deftest piem-rmail-get-mid ()
@@ -63,7 +64,8 @@ no thanks
(insert piem-rmail-tests-mbox-text)
(rmail-mode)
(rmail-first-message)
- (let ((piem-inboxes '(("foo" :address "i@inbox.example.com"))))
+ (let ((piem-get-inboxes-from-config nil)
+ (piem-inboxes '(("foo" :address "i@inbox.example.com"))))
(list (piem-rmail-get-mid)
(progn
(rmail-next-message 1)
diff --git a/tests/piem-tests.el b/tests/piem-tests.el
index 91beb9a..490901e 100644
--- a/tests/piem-tests.el
+++ b/tests/piem-tests.el
@@ -19,11 +19,75 @@
;;; Code:
+(require 'cl-lib)
(require 'ert)
(require 'piem)
(require 'piem-lei-tests)
(require 'piem-rmail-tests)
+(defmacro piem-tests-with-pi-config (content &rest body)
+ "Point public-inbox's configuration to CONTENT and evaluate BODY."
+ (declare (indent 1) (debug t))
+ (let ((temp-file (cl-gensym "temp-file"))
+ (pi-config-orig (cl-gensym "pi-config-org")))
+ `(let ((,temp-file (make-temp-file "piem-tests-" nil nil ,content))
+ (,pi-config-orig (getenv "PI_CONFIG")))
+ (unwind-protect
+ (progn (setenv "PI_CONFIG" ,temp-file)
+ ,@body)
+ (setenv "PI_CONFIG" ,pi-config-orig)
+ (delete-file ,temp-file)))))
+
+(defvar piem-tests-sample-pi-config "
+[publicinbox \"foo\"]
+ address = foo@example.com
+ url = https://example.com/foo
+ inboxdir = /inboxes/foo
+ coderepo = foo.git
+
+[coderepo \"foo.git\"]
+ dir = /code/foo/.git
+")
+
+(ert-deftest piem-merged-inboxes:from-config-disabled ()
+ (let ((piem-get-inboxes-from-config nil)
+ (piem-inboxes nil))
+ (should-not (piem-merged-inboxes))
+ (should-not (piem-tests-with-pi-config ""
+ (piem-merged-inboxes)))
+ (should-not (piem-tests-with-pi-config piem-tests-sample-pi-config
+ (piem-merged-inboxes))))
+ (let ((piem-get-inboxes-from-config nil)
+ (piem-inboxes '(("inbox" :url "inbox-url"))))
+ (should (equal (piem-inbox-get :url "inbox") "inbox-url"))))
+
+(ert-deftest piem-merged-inboxes:from-config ()
+ (piem-clear-merged-inboxes)
+ (let ((piem-get-inboxes-from-config t)
+ (piem-inboxes nil))
+ (piem-tests-with-pi-config piem-tests-sample-pi-config
+ (should (equal (piem-inbox-get :address "foo")
+ "foo@example.com"))
+ (should (equal (piem-inbox-get :url "foo")
+ "https://example.com/foo"))
+ (should (equal (piem-inbox-coderepo "foo")
+ "/code/foo/")))
+ (piem-tests-with-pi-config ""
+ (should (equal (piem-inbox-get :address "foo")
+ "foo@example.com"))
+ (piem-clear-merged-inboxes)
+ (should-not (piem-inbox-get :address "foo")))))
+
+(ert-deftest piem-merged-inboxes:override-config ()
+ (piem-clear-merged-inboxes)
+ (let ((piem-get-inboxes-from-config t)
+ (piem-inboxes '(("foo" :coderepo "/tmp/override/"))))
+ (piem-tests-with-pi-config piem-tests-sample-pi-config
+ (should (equal (piem-inbox-coderepo "foo")
+ "/tmp/override/"))
+ (should (equal (piem-inbox-get :address "foo")
+ "foo@example.com")))))
+
(ert-deftest piem-message-link-re ()
(should-not (string-match-p
(piem-message-link-re "https://example.com/inbox")
@@ -52,7 +116,8 @@
(should (equal (piem-escape-mid "m/g@id") "m%2Fg@id")))
(ert-deftest piem-mid-url ()
- (let ((piem-inboxes '(("inbox-a" :url "https://example.com/a/")
+ (let ((piem-get-inboxes-from-config nil)
+ (piem-inboxes '(("inbox-a" :url "https://example.com/a/")
("inbox-b" :url "https://example.com/b/"))))
(should (equal (piem-mid-url "msg@id" "inbox-a")
"https://example.com/a/msg@id"))
@@ -60,7 +125,8 @@
"https://example.com/b/m%2Fsg@id"))
(should-error (piem-mid-url "msg@id")
:type 'user-error))
- (let ((piem-inboxes '(("inbox-a"))))
+ (let ((piem-get-inboxes-from-config nil)
+ (piem-inboxes '(("inbox-a"))))
(should-error (piem-mid-url "msg@id" "inbox-a")
:type 'user-error)))