diff options
Diffstat (limited to 'tests/test-pearl-config.el')
| -rw-r--r-- | tests/test-pearl-config.el | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/test-pearl-config.el b/tests/test-pearl-config.el new file mode 100644 index 0000000..e83414c --- /dev/null +++ b/tests/test-pearl-config.el @@ -0,0 +1,76 @@ +;;; test-pearl-config.el --- Tests for pearl config helpers -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Craig Jennings + +;; Author: Craig Jennings <c@cjennings.net> + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Unit tests for the small config / state helpers: `pearl--headers', +;; `pearl-toggle-debug', and `pearl-load-api-key-from-env'. + +;;; Code: + +(require 'test-bootstrap (expand-file-name "test-bootstrap.el")) + +;;; pearl--headers + +(ert-deftest test-pearl-headers-no-key-errors () + "Building headers without an API key signals an error." + (let ((pearl-api-key nil)) + (should-error (pearl--headers)))) + +(ert-deftest test-pearl-headers-with-key-sets-authorization () + "With a key set, the Authorization header carries the raw key (no Bearer)." + (let ((pearl-api-key "lin_api_abc123")) + (let ((headers (pearl--headers))) + (should (string-equal "lin_api_abc123" (cdr (assoc "Authorization" headers)))) + (should (string-equal "application/json" (cdr (assoc "Content-Type" headers))))))) + +;;; pearl-toggle-debug + +(ert-deftest test-pearl-toggle-debug-flips-from-nil () + "Toggling from nil enables debug." + (let ((pearl-debug nil)) + (pearl-toggle-debug) + (should (eq t pearl-debug)))) + +(ert-deftest test-pearl-toggle-debug-flips-from-t () + "Toggling from t disables debug." + (let ((pearl-debug t)) + (pearl-toggle-debug) + (should (null pearl-debug)))) + +;;; pearl-load-api-key-from-env + +(ert-deftest test-pearl-load-api-key-from-env-present () + "When LINEAR_API_KEY is set, the key is loaded into the variable." + (let ((process-environment (cons "LINEAR_API_KEY=env-key-xyz" process-environment)) + (pearl-api-key nil)) + (pearl-load-api-key-from-env) + (should (string-equal "env-key-xyz" pearl-api-key)))) + +(ert-deftest test-pearl-load-api-key-from-env-absent-leaves-key () + "When LINEAR_API_KEY is unset, the key variable is left unchanged." + (let ((process-environment + (seq-remove (lambda (e) (string-prefix-p "LINEAR_API_KEY=" e)) + process-environment)) + (pearl-api-key nil)) + (pearl-load-api-key-from-env) + (should (null pearl-api-key)))) + +(provide 'test-pearl-config) +;;; test-pearl-config.el ends here |
