Hi #pedestal users, I am in need of guidance regarding the function below
(defn create-servlet
"Creates a servlet given an options map with keyword keys prefixed by namespace e.g.
:io.pedestal.http/interceptors or ::bootstrap/interceptors if the namespace is aliased to bootstrap.
Options:
* :io.pedestal.http/interceptors: A vector of interceptors that defines a service.
Note: Additional options are passed to default-interceptors if :interceptors is not set."
[service-map]
(-> service-map
default-interceptors
service-fn
servlet))
I am looking at some legacy code that is exercising this function in order to create a test servlet, but that seems to be opposed to this guide -> http://pedestal.io/guides/pedestal-with-componentCan somebody help me understand what is this pattern of use of create-servlet
?
@ariel.silverman it’s common to use response-for
to test your service implementation. That constructs a servlet request under the covers which is used to exercise your implementation.
@ddeaguiar - Would you be open to helping me out with this subject? I wasn’t really able to find any good resources…
@ariel.silverman sure! Here’s a start. A new pedestal project created via the pedestal-service template contains some initial tests. Here’s a trimmed down version of one of those tests in the ‘Hello World’ sample: https://github.com/pedestal/pedestal/blob/master/samples/hello-world/test/hello_world/service_test.clj#L19-L25
I’ll work on fleshing out the reference for unit testing in the http://pedestal.io docs.
response-for
can be used to test all HTTP methods. If you are testing :post
you can specify a :body
.
Headers can also be passed
@ddeaguiar thank you for your help 🙂 I will review the project for inspiration and clarification and follow up if any questions arise. Thanks again!