aboutsummaryrefslogtreecommitdiff
path: root/tests/test-auth-config-kill-gpg-agent.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-auth-config-kill-gpg-agent.el')
-rw-r--r--tests/test-auth-config-kill-gpg-agent.el42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test-auth-config-kill-gpg-agent.el b/tests/test-auth-config-kill-gpg-agent.el
new file mode 100644
index 000000000..8933bee7c
--- /dev/null
+++ b/tests/test-auth-config-kill-gpg-agent.el
@@ -0,0 +1,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