Je voudrais écrire des tests pour un web-service Pedestal.Clojure - test a pedestal route
Si je:
(defn pong
[request]
(ring-resp/response "pong"))
(defroutes routes[[["/" {:get pong}]]])
Comment puis-je écrire un test pour cela?
(deftest alive-system
(testing "ping-pong route"
;; How do I test my route ?
;; If possible :
;; - I would like to have direct access to it
;; ie. no need to bind pedestal to a port would be nice
;; - The ability to omit some interceptors would be nice also,
;; as it would allow me to receive plain Clojure data structures
;; instead of, for instance, JSON which I would have to parse.
...)
Modifier: est ce que j'essayé ici:
(deftest alive-system
(testing "ping-pong route"
(let [response (my-other.ns/routes (mock/request :get "/ping"))]
(is (= (:status response) 200))
(is (= (:body response) "pong")))))
Mais je reçois une exception:
ERROR in (alive-system) (service_test.clj:13)
Uncaught exception, not in assertion.
expected: nil
actual: java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
Avez-vous regardé https://github.com/ring-clojure/ring-mock? – ez121sl
@ ez121sl Je l'ai fait, je l'utilise déjà avec une application compojure, permettez-moi de modifier ma question. – nha
'defroutes' de Compojure crée un gestionnaire d'anneau ou quelque chose de ce genre. La version de Pedestal est apparemment différente. Leur exemple de test n'utilise pas ring-mock: https://github.com/pedestal/pedestal/blob/master/samples/hello-world/test/hello_world/service_test.clj – ez121sl