aboutsummaryrefslogtreecommitdiff
path: root/tests/test-auth-config-clear-oauth2-auto-cache.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-03 19:40:21 -0500
committerCraig Jennings <c@cjennings.net>2026-05-03 19:40:21 -0500
commitac1d0edabc8e30b3781ea7e491030e5bf02d2cae (patch)
tree90e379b71293b68af973edfb5b0b2df91485f100 /tests/test-auth-config-clear-oauth2-auto-cache.el
parente646995e940281e0ef575abc71532ac17f1b4fa9 (diff)
downloaddotemacs-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-clear-oauth2-auto-cache.el')
-rw-r--r--tests/test-auth-config-clear-oauth2-auto-cache.el64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test-auth-config-clear-oauth2-auto-cache.el b/tests/test-auth-config-clear-oauth2-auto-cache.el
new file mode 100644
index 00000000..52a78f53
--- /dev/null
+++ b/tests/test-auth-config-clear-oauth2-auto-cache.el
@@ -0,0 +1,64 @@
+;;; test-auth-config-clear-oauth2-auto-cache.el --- Tests for clear-oauth2-auto-cache -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Verifies the in-memory oauth2-auto cache is cleared when bound, and the
+;; not-loaded message is shown when unbound. The error test restores the
+;; binding in an unwind-protect so other tests in the same Emacs session
+;; do not hit a void-variable error.
+
+;;; 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-clear-oauth2--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-clear-oauth2-cache-normal-bound-with-entries-clears ()
+ "Normal: bound cache with entries gets cleared, success message shown."
+ (test-auth-config-clear-oauth2--load)
+ (let ((cache (make-hash-table :test 'equal))
+ (last-message nil))
+ (puthash "k1" "v1" cache)
+ (puthash "k2" "v2" cache)
+ (setq oauth2-auto--plstore-cache cache)
+ (cl-letf (((symbol-function 'message)
+ (lambda (fmt &rest _) (setq last-message fmt))))
+ (cj/clear-oauth2-auto-cache)
+ (should (zerop (hash-table-count oauth2-auto--plstore-cache)))
+ (should (string-match-p "oauth2-auto token cache cleared" last-message)))))
+
+(ert-deftest test-auth-config-clear-oauth2-cache-boundary-bound-empty-stays-empty ()
+ "Boundary: empty bound cache stays empty, success message still shown."
+ (test-auth-config-clear-oauth2--load)
+ (let ((cache (make-hash-table :test 'equal))
+ (last-message nil))
+ (setq oauth2-auto--plstore-cache cache)
+ (cl-letf (((symbol-function 'message)
+ (lambda (fmt &rest _) (setq last-message fmt))))
+ (cj/clear-oauth2-auto-cache)
+ (should (zerop (hash-table-count oauth2-auto--plstore-cache)))
+ (should (string-match-p "oauth2-auto token cache cleared" last-message)))))
+
+(ert-deftest test-auth-config-clear-oauth2-cache-error-unbound-warns ()
+ "Error: unbound oauth2-auto cache var triggers warning message."
+ (test-auth-config-clear-oauth2--load)
+ (when (boundp 'oauth2-auto--plstore-cache)
+ (makunbound 'oauth2-auto--plstore-cache))
+ (unwind-protect
+ (let ((last-message nil))
+ (cl-letf (((symbol-function 'message)
+ (lambda (fmt &rest _) (setq last-message fmt))))
+ (cj/clear-oauth2-auto-cache)
+ (should (string-match-p "oauth2-auto not loaded yet" last-message))))
+ (setq oauth2-auto--plstore-cache (make-hash-table :test 'equal))))
+
+(provide 'test-auth-config-clear-oauth2-auto-cache)
+;;; test-auth-config-clear-oauth2-auto-cache.el ends here