[PATCH consfigurator v3 5/8] initial tests for consfigurator.data.pgp
David Bremner
david at tethera.net
Sun Mar 13 14:40:08 GMT 2022
Define some simple regression tests to guard against breakage due to the
refactoring of gnupg usage.
Signed-off-by: David Bremner <david at tethera.net>
---
consfigurator.asd | 1 +
tests/data/pgp.lisp | 15 +++++++++++++++
tests/package.lisp | 3 ++-
tests/runner.lisp | 18 +++++++++++++++++-
4 files changed, 35 insertions(+), 2 deletions(-)
create mode 100644 tests/data/pgp.lisp
diff --git a/consfigurator.asd b/consfigurator.asd
index 721d2b1..e408d53 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -110,6 +110,7 @@
(:feature (:not :sbcl) #:rt))
:components ((:file "tests/package")
(:file "tests/runner")
+ (:file "tests/data/pgp")
(:file "tests/data/util")
(:file "tests/util")
(:file "tests/property/file"))
diff --git a/tests/data/pgp.lisp b/tests/data/pgp.lisp
new file mode 100644
index 0000000..c19ab73
--- /dev/null
+++ b/tests/data/pgp.lisp
@@ -0,0 +1,15 @@
+(in-package :consfigurator/tests)
+(named-readtables:in-readtable :consfigurator)
+(in-consfig "consfigurator/tests")
+
+(deftest data.pgp.1
+ (data.pgp:get-data *test-pgp-file* "_secrets" "test")
+ "this is a sekrit")
+
+(deftest data.pgp.2
+ (get-data-string "_secrets" "test")
+ "this is a sekrit")
+
+(deftest data.pgp.3
+ (get-data-string "host.example.com" "/etc/foo.conf")
+ "secret file content")
diff --git a/tests/package.lisp b/tests/package.lisp
index fcb912c..47f41e4 100644
--- a/tests/package.lisp
+++ b/tests/package.lisp
@@ -3,4 +3,5 @@
(defpackage :consfigurator/tests
(:use #:cl #:consfigurator #:consfigurator.data.util #:alexandria #:anaphora
#+sbcl :sb-rt #-sbcl :rtest)
- (:local-nicknames (#:file #:consfigurator.property.file)))
+ (:local-nicknames (#:file #:consfigurator.property.file)
+ (#:data.pgp #:consfigurator.data.pgp)))
diff --git a/tests/runner.lisp b/tests/runner.lisp
index 0a9867b..6615683 100644
--- a/tests/runner.lisp
+++ b/tests/runner.lisp
@@ -53,6 +53,18 @@ mainly useful when there is a single primary key."
*DATA-SOURCE-GNUPGHOME* set appropriately."
`(with-test-gnupg-home-func ,base-dir (lambda () (progn , at body))))
+(defparameter *test-pgp-file* nil)
+
+(defmacro with-test-pgp-source (base-dir &rest body)
+ "Run BODY with *TEST-PGP-FILE* defined and a corresponding pgp data source
+registered and populated."
+ `(let ((*test-pgp-file* (strcat (namestring ,base-dir) "/pgp-secrets.gpg")))
+ (data.pgp:set-data *test-pgp-file* "_secrets" "test" "this is a sekrit")
+ (data.pgp:set-data *test-pgp-file* "host.example.com" "/etc/foo.conf"
+ "secret file content")
+ (try-register-data-source :pgp :location *test-pgp-file*)
+ , at body))
+
;; tests for test runner machinery
(deftest runner.0 (not *data-source-gnupghome*) nil)
@@ -64,9 +76,13 @@ mainly useful when there is a single primary key."
(deftest runner.2 (not *test-gnupg-fingerprint*) nil)
+(deftest runner.3 (not *test-pgp-file*) nil)
+
(defun runner ()
"Run tests via (sb-)rt, with setup and teardown"
(with-local-temporary-directory (test-home)
(with-test-gnupg-home test-home
- (do-tests))))
+ (with-reset-data-sources
+ (with-test-pgp-source test-home
+ (do-tests))))))
--
2.35.1
More information about the sgo-software-discuss
mailing list