From ac1d0edabc8e30b3781ea7e491030e5bf02d2cae Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 3 May 2026 19:40:21 -0500 Subject: 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. --- tests/test-auth-config-toggle-auth-source-debug.el | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/test-auth-config-toggle-auth-source-debug.el (limited to 'tests/test-auth-config-toggle-auth-source-debug.el') diff --git a/tests/test-auth-config-toggle-auth-source-debug.el b/tests/test-auth-config-toggle-auth-source-debug.el new file mode 100644 index 00000000..489ef826 --- /dev/null +++ b/tests/test-auth-config-toggle-auth-source-debug.el @@ -0,0 +1,41 @@ +;;; test-auth-config-toggle-auth-source-debug.el --- Tests for debug toggle -*- lexical-binding: t; -*- + +;;; Commentary: +;; Verifies the debug toggle helper flips both module and auth-source state. + +;;; 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-toggle--load () + "Load auth-config with external process calls stubbed." + (setq cj/auth-source-debug-enabled nil) + (setq auth-source-debug nil) + (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-toggle-normal-flips-disabled-to-enabled () + "Normal: toggle from disabled flips both vars to enabled." + (test-auth-config-toggle--load) + (cl-letf (((symbol-function 'message) (lambda (&rest _) nil))) + (cj/toggle-auth-source-debug) + (should cj/auth-source-debug-enabled) + (should auth-source-debug))) + +(ert-deftest test-auth-config-toggle-boundary-two-toggles-return-to-disabled () + "Boundary: two toggles in a row leave both vars disabled." + (test-auth-config-toggle--load) + (cl-letf (((symbol-function 'message) (lambda (&rest _) nil))) + (cj/toggle-auth-source-debug) + (cj/toggle-auth-source-debug) + (should-not cj/auth-source-debug-enabled) + (should-not auth-source-debug))) + +(provide 'test-auth-config-toggle-auth-source-debug) +;;; test-auth-config-toggle-auth-source-debug.el ends here -- cgit v1.2.3