aboutsummaryrefslogtreecommitdiff
path: root/tests/test-reconcile--pull-clean.el
blob: 89739987e675e550850ff6dbbbc62891e1da141f (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
60
61
62
;;; test-reconcile--pull-clean.el --- Tests for cj/reconcile--pull-clean -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for pulling latest changes on a clean git repository.

;;; Code:

(require 'ert)
(require 'testutil-reconcile-open-repos)
(require 'reconcile-open-repos)

;;; Normal Cases

(ert-deftest test-pull-clean-normal-success ()
  "Successful pull produces no warning message."
  (reconcile-test-with-temp-dirs
   ("repo/.git/")
   (let ((dir (expand-file-name "repo" test-root))
         (messages nil))
    (reconcile-test-with-git-mock
        (lambda (args)
          (should (equal args '("pull" "--rebase" "--quiet")))
          '(:exit 0 :output ""))
      (cl-letf (((symbol-function 'message)
                  (lambda (fmt &rest args) (push (apply #'format fmt args) messages))))
        (let ((result (cj/reconcile--pull-clean dir)))
          (should (eq (plist-get result :status) 'pulled)))))
     (should-not (cl-some (lambda (m) (string-match-p "Warning" m)) messages)))))

(ert-deftest test-pull-clean-normal-failure-warns ()
  "Failed pull produces a warning message with directory and exit code."
  (reconcile-test-with-temp-dirs
   ("repo/.git/")
   (let ((dir (expand-file-name "repo" test-root))
         (messages nil))
    (reconcile-test-with-git-mock
        (lambda (_args) '(:exit 1 :output "boom\n"))
      (cl-letf (((symbol-function 'message)
                  (lambda (fmt &rest args) (push (apply #'format fmt args) messages))))
        (let ((result (cj/reconcile--pull-clean dir)))
          (should (eq (plist-get result :status) 'pull-failed))
          (should (equal (plist-get result :output) "boom\n")))))
     (should (cl-some (lambda (m) (string-match-p "Warning.*git pull failed" m)) messages))
     (should (cl-some (lambda (m) (string-match-p "exit code: 1" m)) messages)))))

;;; Boundary Cases

(ert-deftest test-pull-clean-boundary-nonzero-exit-128 ()
  "Exit code 128 (common git error) is reported in warning."
  (reconcile-test-with-temp-dirs
   ("repo/.git/")
   (let ((dir (expand-file-name "repo" test-root))
         (messages nil))
    (reconcile-test-with-git-mock
        (lambda (_args) '(:exit 128 :output "fatal\n"))
      (cl-letf (((symbol-function 'message)
                  (lambda (fmt &rest args) (push (apply #'format fmt args) messages))))
        (cj/reconcile--pull-clean dir)))
     (should (cl-some (lambda (m) (string-match-p "exit code: 128" m)) messages)))))

(provide 'test-reconcile--pull-clean)
;;; test-reconcile--pull-clean.el ends here