Created
March 15, 2022 15:51
-
-
Save flyingmachine/875543e51822db24b654707750093058 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; The question: how to clearly provide system def overrides? | |
;; There are two main scenarios where we want to do this: | |
;; | |
;; 1. Deriving a new "profile", e.g. deriving a test profile from a base profile | |
;; to be used for all tests | |
;; 2. Defining point overrides, e.g. you might want to mock out a specific component | |
;; only for a specific test | |
;; | |
;; Ultimately developers can use what works for them, but I want to figure out | |
;; the recommended approach. Also, I need to figure out the behavior of helpers | |
;; like `start` where you can specify a system along with overrides: | |
(ds/start :system-name {:overrides {:go :here}}) | |
;; the meta-merge approach | |
;; https://github.com/weavejester/meta-merge | |
;; | |
;; meta-merge's default behavior is to recursively merge maps, and recursively | |
;; concatenate vectors | |
(meta-merge/meta-merge {:name {:middle "bobby"} | |
:hobbies ["photography"]} | |
{:name {:first "robert", :last "foobar"} | |
:hobbies ["writing"]}) | |
;; => | |
{:name {:first "robert" | |
:middle "bobby" | |
:last "foobar"} | |
:hobbies ["photography" "writing"]} | |
;; Here's how that can work with combining system defs: | |
(def base-system | |
{::ds/defs | |
{:group-name | |
{:component-name {:start (fn [_ _ _]) | |
:conf {:port (ds/ref [:env :http-port])}}}}}) | |
(def test-system | |
(meta-merge/meta-merge | |
base-system | |
{::ds/defs | |
{:group-name | |
{:component-name {:conf {:port 9090}}}}})) | |
;; I like that for the most part you can construct minimal structures to specify | |
;; overrides. However, I still continually find myself creating little bugs | |
;; because I actually need *replace* behavior and I forget to add the ^:replace | |
;; metadata. | |
;; Heres another option: | |
(def test-system | |
(update base-ssytem ::ds/defs ds/assoc-many | |
{[:group-name :component-name :conf :port] 9090})) | |
;; this approach could be repetitive but I think the behavior would be unambiguous |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment