proof of concept: set / overwrite slots from env-data

This commit is contained in:
Helmut Merz 2024-06-07 13:38:16 +02:00
parent ebd7275b8a
commit d9819cbe2e

View file

@ -16,7 +16,16 @@
(defclass test-config (config:base) (defclass test-config (config:base)
((config:env-keys :initform '(:user :password)) ((config:env-keys :initform '(:user :password))
(config:env-path :initform (t:test-path ".test.env")))) (config:env-path :initform (t:test-path ".test.env"))
(user :accessor user :initarg :user)
(password :accessor password :initarg :password)))
(defmethod initialize-instance :after ((cfg test-config) &key &allow-other-keys)
(let* ((data (config:env-data cfg))
(u (if data (gethash :user data)))
(pw (if data (gethash :password data))))
(if u (setf (user cfg) u))
(if pw (setf (password cfg) pw))))
(defun run () (defun run ()
(let ((*config* nil) (let ((*config* nil)
@ -35,4 +44,6 @@
(t:deftest test-env-override () (t:deftest test-env-override ()
(let ((data (config:env-data *config*))) (let ((data (config:env-data *config*)))
(== (gethash :user data) "user-from-env-file") (== (gethash :user data) "user-from-env-file")
(== (gethash :password data) "very_secret"))) (== (gethash :password data) "very_secret")
(== (user *config*) "user-from-env-file")
(== (password *config*) "very_secret")))