aboutsummaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync-no-config-startup.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-04 00:00:00 -0500
committerCraig Jennings <c@cjennings.net>2026-05-04 00:00:08 -0500
commitcc594fdd28f2b047be25b6f016c7f47d23e741ec (patch)
tree199342a65e842362fbcdd6756b767f2704cab722 /tests/test-calendar-sync-no-config-startup.el
parentf610c2fef97381c7ecfc9dca0a0e1a39a16abe18 (diff)
downloaddotemacs-cc594fdd28f2b047be25b6f016c7f47d23e741ec.tar.gz
dotemacs-cc594fdd28f2b047be25b6f016c7f47d23e741ec.zip
Make calendar sync startup safe without config
Diffstat (limited to 'tests/test-calendar-sync-no-config-startup.el')
-rw-r--r--tests/test-calendar-sync-no-config-startup.el130
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/test-calendar-sync-no-config-startup.el b/tests/test-calendar-sync-no-config-startup.el
new file mode 100644
index 00000000..94a53009
--- /dev/null
+++ b/tests/test-calendar-sync-no-config-startup.el
@@ -0,0 +1,130 @@
+;;; test-calendar-sync-no-config-startup.el --- No-config startup tests for calendar-sync -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Regression tests for loading calendar-sync without configured calendars.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+
+(defvar calendar-sync-private-config-file)
+(defvar calendar-sync-calendars)
+(defvar calendar-sync-auto-start)
+
+(ert-deftest test-calendar-sync-no-config-startup-does-not-start-sync ()
+ "Loading calendar-sync without calendars should not start timers or fetches."
+ (let ((calendar-sync-private-config-file
+ (expand-file-name "missing-calendar-sync.local.el" temporary-file-directory))
+ (calendar-sync-calendars nil)
+ (calendar-sync-auto-start t)
+ (timer-called nil)
+ (process-called nil)
+ messages)
+ (cl-letf (((symbol-function 'run-at-time)
+ (lambda (&rest _args)
+ (setq timer-called t)
+ 'test-calendar-sync-timer))
+ ((symbol-function 'make-process)
+ (lambda (&rest _args)
+ (setq process-called t)
+ nil))
+ ((symbol-function 'message)
+ (lambda (format-string &rest args)
+ (push (apply #'format format-string args) messages))))
+ (load (expand-file-name "modules/calendar-sync.el" user-emacs-directory)
+ nil t))
+ (should (boundp 'calendar-sync-calendars))
+ (should-not calendar-sync-calendars)
+ (should-not timer-called)
+ (should-not process-called)
+ (should-not (cl-some (lambda (msg)
+ (string-match-p "calendar-sync: Syncing" msg))
+ messages))))
+
+(ert-deftest test-calendar-sync-no-config-status-reports-missing-config ()
+ "Status should report missing calendar config without erroring."
+ (let ((calendar-sync-private-config-file
+ (expand-file-name "missing-calendar-sync.local.el" temporary-file-directory))
+ (calendar-sync-calendars nil)
+ (calendar-sync-auto-start t)
+ messages)
+ (cl-letf (((symbol-function 'run-at-time) (lambda (&rest _args) nil))
+ ((symbol-function 'make-process) (lambda (&rest _args) nil))
+ ((symbol-function 'message)
+ (lambda (format-string &rest args)
+ (push (apply #'format format-string args) messages))))
+ (load (expand-file-name "modules/calendar-sync.el" user-emacs-directory)
+ nil t)
+ (calendar-sync-status))
+ (should (member "calendar-sync: No calendars configured (set calendar-sync-calendars)"
+ messages))))
+
+(ert-deftest test-calendar-sync-no-config-loads-private-config-when-present ()
+ "Loading calendar-sync should read an ignored private config file when present."
+ (let ((config-file (make-temp-file "calendar-sync-local-" nil ".el"))
+ (calendar-sync-calendars nil)
+ (calendar-sync-auto-start t)
+ (timer-called nil)
+ (process-called nil))
+ (unwind-protect
+ (progn
+ (with-temp-file config-file
+ (insert "(setq calendar-sync-auto-start nil)\n")
+ (insert "(setq calendar-sync-calendars\n")
+ (insert " '((:name \"local\" :url \"https://example.test/calendar.ics\" :file \"/tmp/local.org\")))\n"))
+ (let ((calendar-sync-private-config-file config-file))
+ (cl-letf (((symbol-function 'run-at-time)
+ (lambda (&rest _args)
+ (setq timer-called t)
+ 'test-calendar-sync-timer))
+ ((symbol-function 'make-process)
+ (lambda (&rest _args)
+ (setq process-called t)
+ nil))
+ ((symbol-function 'message)
+ (lambda (&rest _args) nil)))
+ (load (expand-file-name "modules/calendar-sync.el" user-emacs-directory)
+ nil t))
+ (should (equal (calendar-sync--calendar-names) '("local")))
+ (should-not calendar-sync-auto-start)
+ (should-not timer-called)
+ (should-not process-called)))
+ (delete-file config-file))))
+
+(ert-deftest test-calendar-sync-no-config-private-config-does-not-auto-start-in-batch ()
+ "Private config should not auto-start sync while Emacs is noninteractive."
+ (let ((config-file (make-temp-file "calendar-sync-local-" nil ".el"))
+ (calendar-sync-calendars nil)
+ (calendar-sync-auto-start t)
+ (timer-called nil)
+ (process-called nil))
+ (unwind-protect
+ (progn
+ (with-temp-file config-file
+ (insert "(setq calendar-sync-calendars\n")
+ (insert " '((:name \"local\" :url \"https://example.test/calendar.ics\" :file \"/tmp/local.org\")))\n"))
+ (let ((calendar-sync-private-config-file config-file))
+ (cl-letf (((symbol-function 'run-at-time)
+ (lambda (&rest _args)
+ (setq timer-called t)
+ 'test-calendar-sync-timer))
+ ((symbol-function 'make-process)
+ (lambda (&rest _args)
+ (setq process-called t)
+ nil))
+ ((symbol-function 'message)
+ (lambda (&rest _args) nil)))
+ (load (expand-file-name "modules/calendar-sync.el" user-emacs-directory)
+ nil t))
+ (should (equal (calendar-sync--calendar-names) '("local")))
+ (should calendar-sync-auto-start)
+ (should noninteractive)
+ (should-not timer-called)
+ (should-not process-called)))
+ (delete-file config-file))))
+
+(provide 'test-calendar-sync-no-config-startup)
+;;; test-calendar-sync-no-config-startup.el ends here