aboutsummaryrefslogtreecommitdiff
path: root/tests/test-auth-config-kill-gpg-agent.el
blob: 8933bee7c1e6e1e72e149b63b1a4299291de1ef4 (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
;;; test-auth-config-kill-gpg-agent.el --- Tests for cj/kill-gpg-agent -*- lexical-binding: t; -*-

;;; Commentary:
;; Verifies cj/kill-gpg-agent reports success or warning based on shell exit code.

;;; Code:

(require 'cl-lib)
(require 'ert)
(require 'auth-source)

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

(defun test-auth-config-kill--load ()
  "Load auth-config with external process calls stubbed."
  (cl-letf (((symbol-function 'call-process)
             (lambda (&rest _args) 0)))
    (load (expand-file-name "modules/auth-config.el" user-emacs-directory)
          nil t)))

(ert-deftest test-auth-config-kill-gpg-agent-normal-shell-success ()
  "Normal: shell-command exit 0 yields success message."
  (test-auth-config-kill--load)
  (let ((last-message nil))
    (cl-letf (((symbol-function 'shell-command) (lambda (&rest _) 0))
              ((symbol-function 'message)
               (lambda (fmt &rest _) (setq last-message fmt))))
      (cj/kill-gpg-agent)
      (should (string-match-p "gpg-agent killed" last-message)))))

(ert-deftest test-auth-config-kill-gpg-agent-error-shell-fails ()
  "Error: shell-command non-zero yields warning message."
  (test-auth-config-kill--load)
  (let ((last-message nil))
    (cl-letf (((symbol-function 'shell-command) (lambda (&rest _) 1))
              ((symbol-function 'message)
               (lambda (fmt &rest _) (setq last-message fmt))))
      (cj/kill-gpg-agent)
      (should (string-match-p "Failed to kill gpg-agent" last-message)))))

(provide 'test-auth-config-kill-gpg-agent)
;;; test-auth-config-kill-gpg-agent.el ends here