diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-03 19:40:21 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-03 19:40:21 -0500 |
| commit | ac1d0edabc8e30b3781ea7e491030e5bf02d2cae (patch) | |
| tree | 90e379b71293b68af973edfb5b0b2df91485f100 /tests/test-auth-config-reset-auth-cache.el | |
| parent | e646995e940281e0ef575abc71532ac17f1b4fa9 (diff) | |
| download | dotemacs-ac1d0edabc8e30b3781ea7e491030e5bf02d2cae.tar.gz dotemacs-ac1d0edabc8e30b3781ea7e491030e5bf02d2cae.zip | |
test: cover auth-config helpers and oauth2 cache fix
I added 13 new tests across 5 files, covering the auth-config functions that lacked tests. Categories follow Normal / Boundary / Error where applicable.
`cj/toggle-auth-source-debug` flips state once and back through two toggles. `cj/oauth2-auto--plstore-read-fixed` gets three tests: cache miss reads then caches, cache hit skips `plstore-open` entirely, and the `unwind-protect` runs `plstore-close` even when `plstore-get` signals.
`cj/reset-auth-cache` covers no-prefix (skip `shell-command`), with-prefix success, and with-prefix shell failure (Emacs caches still clear). `cj/kill-gpg-agent` covers shell exit 0 and non-zero. `cj/clear-oauth2-auto-cache` covers bound-with-entries, bound-but-empty, and unbound. The unbound test restores the binding via `unwind-protect` so other tests in the same Emacs session don't void-variable.
I stubbed every boundary via `cl-letf` (`plstore-open`, `plstore-get`, `plstore-close`, `oauth2-auto--compute-id`, `auth-source-forget-all-cached`, `epa-file-clear-cache`, `shell-command`, `message`, `call-process`) and didn't stub any internal helpers.
15 auth-config tests pass together: 2 existing plus 13 new.
Diffstat (limited to 'tests/test-auth-config-reset-auth-cache.el')
| -rw-r--r-- | tests/test-auth-config-reset-auth-cache.el | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/test-auth-config-reset-auth-cache.el b/tests/test-auth-config-reset-auth-cache.el new file mode 100644 index 00000000..689ce483 --- /dev/null +++ b/tests/test-auth-config-reset-auth-cache.el @@ -0,0 +1,81 @@ +;;; test-auth-config-reset-auth-cache.el --- Tests for cj/reset-auth-cache -*- lexical-binding: t; -*- + +;;; Commentary: +;; Verifies cache-reset orchestrates auth-source, EPA, and gpg-agent +;; clears according to the prefix-arg flag. + +;;; 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-reset--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-reset-auth-cache-normal-no-prefix-skips-shell () + "Normal: no prefix arg clears Emacs caches but does not invoke shell-command." + (test-auth-config-reset--load) + (let ((auth-clears 0) + (epa-clears 0) + (shell-calls 0)) + (cl-letf (((symbol-function 'auth-source-forget-all-cached) + (lambda () (cl-incf auth-clears))) + ((symbol-function 'epa-file-clear-cache) + (lambda () (cl-incf epa-clears))) + ((symbol-function 'shell-command) + (lambda (&rest _) (cl-incf shell-calls) 0)) + ((symbol-function 'message) (lambda (&rest _) nil))) + (cj/reset-auth-cache nil) + (should (= auth-clears 1)) + (should (= epa-clears 1)) + (should (zerop shell-calls))))) + +(ert-deftest test-auth-config-reset-auth-cache-boundary-with-prefix-shell-success () + "Boundary: with prefix and shell-command returning 0, all three caches clear." + (test-auth-config-reset--load) + (let ((auth-clears 0) + (epa-clears 0) + (shell-calls 0) + (last-message nil)) + (cl-letf (((symbol-function 'auth-source-forget-all-cached) + (lambda () (cl-incf auth-clears))) + ((symbol-function 'epa-file-clear-cache) + (lambda () (cl-incf epa-clears))) + ((symbol-function 'shell-command) + (lambda (&rest _) (cl-incf shell-calls) 0)) + ((symbol-function 'message) + (lambda (fmt &rest _) (setq last-message fmt)))) + (cj/reset-auth-cache t) + (should (= auth-clears 1)) + (should (= epa-clears 1)) + (should (= shell-calls 1)) + (should (string-match-p "Emacs and gpg-agent caches cleared" last-message))))) + +(ert-deftest test-auth-config-reset-auth-cache-error-with-prefix-shell-fails () + "Error: with prefix and shell-command non-zero, warning is shown, Emacs caches still cleared." + (test-auth-config-reset--load) + (let ((auth-clears 0) + (epa-clears 0) + (last-message nil)) + (cl-letf (((symbol-function 'auth-source-forget-all-cached) + (lambda () (cl-incf auth-clears))) + ((symbol-function 'epa-file-clear-cache) + (lambda () (cl-incf epa-clears))) + ((symbol-function 'shell-command) + (lambda (&rest _) 1)) + ((symbol-function 'message) + (lambda (fmt &rest _) (setq last-message fmt)))) + (cj/reset-auth-cache t) + (should (= auth-clears 1)) + (should (= epa-clears 1)) + (should (string-match-p "Failed to clear gpg-agent cache" last-message))))) + +(provide 'test-auth-config-reset-auth-cache) +;;; test-auth-config-reset-auth-cache.el ends here |
