This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-22
Channels
- # announcements (88)
- # autochrome-github (2)
- # babashka (26)
- # beginners (5)
- # biff (2)
- # cider (73)
- # clj-kondo (4)
- # cljsrn (6)
- # clojure (54)
- # clojure-art (3)
- # clojure-europe (73)
- # clojure-germany (5)
- # clojure-new-zealand (1)
- # clojure-nl (13)
- # clojure-norway (16)
- # clojure-uk (8)
- # clojurescript (73)
- # conjure (1)
- # core-async (10)
- # cursive (17)
- # datahike (51)
- # datalevin (21)
- # datomic (4)
- # emacs (2)
- # events (3)
- # fulcro (35)
- # honeysql (6)
- # introduce-yourself (1)
- # jackdaw (3)
- # jobs (1)
- # leiningen (4)
- # lsp (3)
- # malli (17)
- # off-topic (60)
- # other-languages (5)
- # pathom (17)
- # pedestal (3)
- # polylith (19)
- # portal (2)
- # practicalli (1)
- # rdf (14)
- # reitit (3)
- # releases (1)
- # reveal (9)
- # sci (1)
- # shadow-cljs (26)
- # spacemacs (17)
- # sql (4)
- # testing (10)
- # tools-build (6)
- # tools-deps (16)
- # vim (9)
I’m writing tests for an existing application running pedestal and carmine and I’m trying to override/set a variable in a test, but it seems it doesn’t have any effect.
The error is java.lang.IllegalArgumentException: hostname can't be null
which makes sense due to the way we read the config file, so I want to mock the value.
The implementation:
(def service
{...
::http/enable-session {:cookie-name "abc"
:store (taoensso.carmine.ring/carmine-store {:pool {} :spec {:host (:host (cnf/carmine))}} {:key-prefix "abc:carmine:session" :expiration-secs (* 60 60 12)})}
...})
The config edn file:
:carmine {:host "127.0.0.1"}
The test:
(deftest service-test
(with-redefs [cnf/carmine {:host "127.0.0.1"}]
(is (= 200 (:status (response-for service :get "/ping"))))))
Does anyone have any idea why the hostname is still null?Okay, in the config it is defined with defn
like this (defn carmine [] (:carmine @config-atom))
but maybe that doesn’t matter?
Or maybe I’m approaching it the wrong way? Should i set up the entire carmine service in the test?
If your service actually looks like this: def service
it doesn't matter, with-redefs will be unable to have an effect
> Or maybe I’m approaching it the wrong way?
I'd say so, most people use Component/Integrant/... plus a config lib like Aero. with-redefs
wouldn't be used - instead you'd make a mock Component implementation for the Carmine service, that exists only within tests