diff options
author | David Bremner <david@tethera.net> | 2022-05-05 08:29:24 -0300 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-05-05 12:26:10 -0700 |
commit | 7712c51df4f60d134451a9da3f11bb3f006991a0 (patch) | |
tree | 282318f231232ff360a73de033f2d6a1d86d7512 /tests | |
parent | 4b0625d744e73e9e7ad3708320fba7fa2cab21ae (diff) | |
download | consfigurator-7712c51df4f60d134451a9da3f11bb3f006991a0.tar.gz |
initial tests for CONSFIGURATOR.DATA.PGP
Define some simple regression tests to guard against breakage due to the
refactoring of gnupg usage.
Signed-off-by: David Bremner <david@tethera.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/pgp.lisp | 21 | ||||
-rw-r--r-- | tests/package.lisp | 3 | ||||
-rw-r--r-- | tests/runner.lisp | 20 |
3 files changed, 42 insertions, 2 deletions
diff --git a/tests/data/pgp.lisp b/tests/data/pgp.lisp new file mode 100644 index 0000000..21ba60c --- /dev/null +++ b/tests/data/pgp.lisp @@ -0,0 +1,21 @@ +(in-package :consfigurator/tests) +(named-readtables:in-readtable :consfigurator) +(in-consfig "consfigurator/tests") + +(defun populate-data-pgp () + "Invoked by test runner before data source is registered." + (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")) + +(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 1b7af62..d43456d 100644 --- a/tests/runner.lisp +++ b/tests/runner.lisp @@ -54,11 +54,27 @@ This is mainly useful when there is a single primary key." (run-program "gpgconf" "--homedir" *data-source-gnupghome* "--kill" "all")))) +(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* (merge-pathnames "pgp-secrets.gpg" ,base-dir))) + (populate-data-pgp) + (handler-case + (try-register-data-source :pgp :location *test-pgp-file*) + (missing-data-source () + (error "Test setup failure for pgp file ~a" *test-pgp-file*))) + ,@body)) + (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)))))) + ;;;; tests for test runner machinery (deftest runner.0 (not *data-source-gnupghome*) nil) @@ -70,3 +86,5 @@ This is mainly useful when there is a single primary key." 1) (deftest runner.2 (not *test-gnupg-fingerprint*) nil) + +(deftest runner.3 (not *test-pgp-file*) nil) |