Я хотел бы написать тесты для веб-сервиса Pedestal.Clojure - test a Проход по пьедесталу
Если у меня есть:
(defn pong
[request]
(ring-resp/response "pong"))
(defroutes routes[[["/" {:get pong}]]])
Как бы я написать тест для этого?
(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.
...)
Edit: Вот что я пробовал:
(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")))))
Но я получаю исключение:
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
Вы просмотрели https://github.com/ring-clojure/ring-mock? – ez121sl
@ ez121sl Я сделал, я использую его с помощью приложения compojure, позвольте мне изменить свой вопрос. – nha
'defroutes' Compojure создает обработчик кольца или что-то в этом роде. Версия для пьедестала, по-видимому, отличается. Их образец теста не использует ring-mock: https://github.com/pedestal/pedestal/blob/master/samples/hello-world/test/hello_world/service_test.clj – ez121sl