blob: 03ee2aee925d326cfb2c82441944af4409bc8b31 (
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
48
49
50
51
52
53
54
55
56
57
58
59
|
;;; test-calendar-sync--batch-results.el --- Batch result collection tests -*- lexical-binding: t; -*-
;;; Commentary:
;; `calendar-sync--batch-results' reads the per-calendar state table and
;; returns one (NAME . STATUS) pair per requested calendar. The batch runner
;; turns that into an exit code, so a calendar that never reached the table at
;; all has to read as `never' rather than nil -- a nil status would compare
;; equal to nothing and quietly drop out of the failure count.
;;; Code:
(require 'ert)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'calendar-sync)
(defun test-calendar-sync-batch-results--with-states (states body)
"Run BODY with STATES (an alist of NAME . PLIST) in the state table."
(let ((calendar-sync--calendar-states (make-hash-table :test 'equal)))
(dolist (entry states)
(puthash (car entry) (cdr entry) calendar-sync--calendar-states))
(funcall body)))
(ert-deftest test-calendar-sync-batch-results-reports-each-status ()
"Normal: every requested calendar comes back with its recorded status."
(test-calendar-sync-batch-results--with-states
'(("google" . (:status ok))
("proton" . (:status error :last-error "boom")))
(lambda ()
(should (equal (calendar-sync--batch-results '("google" "proton"))
'(("google" . ok) ("proton" . error)))))))
(ert-deftest test-calendar-sync-batch-results-empty-names-is-empty ()
"Boundary: no calendars requested yields no rows, not an error."
(test-calendar-sync-batch-results--with-states
'(("google" . (:status ok)))
(lambda ()
(should (equal (calendar-sync--batch-results '()) '())))))
(ert-deftest test-calendar-sync-batch-results-missing-calendar-reads-never ()
"Error: a calendar absent from the state table reads `never', never nil.
A nil status would drop out of the failure count and report success for a
calendar that never ran."
(test-calendar-sync-batch-results--with-states
'(("google" . (:status ok)))
(lambda ()
(should (equal (calendar-sync--batch-results '("google" "absent"))
'(("google" . ok) ("absent" . never)))))))
(ert-deftest test-calendar-sync-batch-results-preserves-request-order ()
"Boundary: rows come back in the order asked for, not hash order."
(test-calendar-sync-batch-results--with-states
'(("a" . (:status ok)) ("b" . (:status ok)) ("c" . (:status ok)))
(lambda ()
(should (equal (mapcar #'car (calendar-sync--batch-results '("c" "a" "b")))
'("c" "a" "b"))))))
(provide 'test-calendar-sync--batch-results)
;;; test-calendar-sync--batch-results.el ends here
|