Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@flyingmachine
Created March 15, 2022 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyingmachine/875543e51822db24b654707750093058 to your computer and use it in GitHub Desktop.
Save flyingmachine/875543e51822db24b654707750093058 to your computer and use it in GitHub Desktop.
;; 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