blob: e83414cdbdee21b4010d988f0a790a90831a8655 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
|