-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtriples-backups-test.el
69 lines (60 loc) · 3.1 KB
/
triples-backups-test.el
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
60
61
62
63
64
65
66
67
68
69
;;; triples-backups-test.el --- Tests for the triples-backup module. -*- lexical-binding: t; -*-
;; Copyright (c) 2022 Free Software Foundation, Inc.
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Note: It's important to test this on emacs 29, with emacsql installed, so we
;; can make both types of sqlite backend work.
;;; Code:
(require 'ert)
(require 'triples-backups)
(require 'iso8601)
(ert-deftest triples-backups-strategy-daily ()
(cl-letf (((symbol-function 'current-time)
(lambda ()
(encode-time (iso8601-parse "2023-01-15T12:00Z")))))
(should (triples-backups-strategy-daily (encode-time (iso8601-parse "2023-01-14T12:00Z"))))
(should (triples-backups-strategy-daily (encode-time (iso8601-parse "2022-01-01T12:00Z"))))
(should-not (triples-backups-strategy-daily (encode-time (iso8601-parse "2023-01-15T12:00Z"))))
(should-not (triples-backups-strategy-daily (encode-time (iso8601-parse "2023-02-01T12:00Z"))))))
(ert-deftest triples-backups-strategy-weekly ()
(cl-letf (((symbol-function 'current-time)
(lambda ()
(encode-time (iso8601-parse "2023-01-15T12:00Z")))))
(should (triples-backups-strategy-daily (encode-time (iso8601-parse "2023-01-01T12:00Z"))))
(should (triples-backups-strategy-daily (encode-time (iso8601-parse "2022-01-01T12:00Z"))))
(should-not (triples-backups-strategy-daily (encode-time (iso8601-parse "2023-01-15T12:00Z"))))
(should-not (triples-backups-strategy-daily (encode-time (iso8601-parse "2023-02-01T12:00Z"))))))
(ert-deftest triples-backups-maybe-backup ()
(let* ((filename (make-temp-file "triples-test"))
(db (triples-connect filename))
(backup-called))
(cl-letf (((symbol-function 'triples-backup)
(lambda (_ _ num-to-keep)
(should (= num-to-keep 3))
(setq backup-called t)))
((symbol-function 'triples-backups-strategy-always)
(lambda (_) t))
((symbol-function 'triples-backups-strategy-never)
(lambda (_) nil)))
(should-error (triples-backups-maybe-backup db filename))
(triples-backups-setup db 3 'never)
(triples-backups-maybe-backup db filename)
(should-not backup-called)
(triples-backups-setup db 3 'always)
(triples-backups-maybe-backup db filename)
(should backup-called)
(triples-backups-setup db 3 'unknown)
(triples-backups-maybe-backup db filename)
(should backup-called))))
(provide 'triples-backups-test)