Skip to content

Instantly share code, notes, and snippets.

@rbxbx
Last active October 6, 2016 18:11
Show Gist options
  • Save rbxbx/0107da08cd072e25c2118498de7c1ce0 to your computer and use it in GitHub Desktop.
Save rbxbx/0107da08cd072e25c2118498de7c1ce0 to your computer and use it in GitHub Desktop.
(defmacro with-system
"start a system, execute the body, and stop the system when done."
[[bound sys] & body]
`(let [system# (component/start ~sys)
~bound system#]
(try
~@body
(finally
(component/stop system#)))))
(defmacro with-test-server [[bound {:keys [quiet?] :or {quiet? true}}] & body]
`(binding [*out* (if ~quiet? (StringWriter.)
*out*)]
(let [system# (component/start (build-system))
~bound (get-in system# [:webserver :connection])
db# (get-in system# [:database :connection])
db-password# (get-in system# [:config :database-password])
aws-opts# (get system# :aws-client-opts)]
(try
(do
(db/drop-tables db#)
(db/migrate db# db-password#))
~@body
(finally
(do (db/drop-tables db#)
(drop-dynamo-tables aws-opts#)
(component/stop system#)))))))
(defmacro with-test-server-system [[bound {:keys [quiet?] :or {quiet? true}}] [sys-bound] & body]
`(binding [*out* (if ~quiet? (StringWriter.)
*out*)]
(let [system# (component/start (build-system))
~bound (get-in system# [:webserver :connection])
db# (get-in system# [:database :connection])
db-password# (get-in system# [:config :database-password])
aws-opts# (get system# :aws-client-opts)
~sys-bound system#]
(try
(do
(db/drop-tables db#)
(db/migrate db# db-password#))
~@body
(finally
(do (db/drop-tables db#)
(drop-dynamo-tables aws-opts#)
(component/stop system#)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment