aboutsummaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync--batch-failures.el
blob: 3190be2120d3855fdad8e35744c4bf42e91da792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;;; test-calendar-sync--batch-failures.el --- Batch failure filter tests  -*- lexical-binding: t; -*-

;;; Commentary:
;; `calendar-sync--batch-failures' picks the rows that did not finish cleanly.
;; The batch runner's exit code is derived from it, and systemd reads that exit
;; code, so the rule is deliberately strict: only `ok' passes.  A calendar left
;; `syncing' at the timeout, or one that never started, is a failure -- both
;; states mean the org file on disk is not the calendar's current contents,
;; which is exactly the silent staleness the timer exists to prevent.

;;; Code:

(require 'ert)

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'calendar-sync)

(ert-deftest test-calendar-sync-batch-failures-keeps-only-non-ok ()
  "Normal: an errored calendar is returned and a healthy one is not."
  (should (equal (calendar-sync--batch-failures
                  '(("google" . ok) ("proton" . error)))
                 '(("proton" . error)))))

(ert-deftest test-calendar-sync-batch-failures-all-ok-is-empty ()
  "Normal: a fully successful run reports no failures."
  (should (equal (calendar-sync--batch-failures
                  '(("google" . ok) ("proton" . ok)))
                 '())))

(ert-deftest test-calendar-sync-batch-failures-empty-input-is-empty ()
  "Boundary: no rows in, no rows out."
  (should (equal (calendar-sync--batch-failures '()) '())))

(ert-deftest test-calendar-sync-batch-failures-timeout-counts-as-failure ()
  "Error: a calendar still `syncing' when the wait expired is a failure.
Its org file was not rewritten, so reporting success would hide the staleness."
  (should (equal (calendar-sync--batch-failures
                  '(("google" . ok) ("proton" . syncing)))
                 '(("proton" . syncing)))))

(ert-deftest test-calendar-sync-batch-failures-never-counts-as-failure ()
  "Error: a calendar that never started is a failure, not a skip."
  (should (equal (calendar-sync--batch-failures '(("google" . never)))
                 '(("google" . never)))))

(provide 'test-calendar-sync--batch-failures)
;;; test-calendar-sync--batch-failures.el ends here