Fork me on GitHub
#pedestal
<
2019-02-08
>
asilverman21:02:27

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-component

asilverman21:02:47

Can somebody help me understand what is this pattern of use of create-servlet?

ddeaguiar22:02:01

@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.

asilverman17:02:42

@U0FL657GR - Would you be open to helping me out with this subject? I wasn’t really able to find any good resources…

ddeaguiar14:02:18

@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

ddeaguiar14:02:55

I’ll work on fleshing out the reference for unit testing in the http://pedestal.io docs.

ddeaguiar14:02:39

response-for can be used to test all HTTP methods. If you are testing :post you can specify a :body.

ddeaguiar14:02:47

Headers can also be passed

asilverman17:02:35

@U0FL657GR thank you for your help 🙂 I will review the project for inspiration and clarification and follow up if any questions arise. Thanks again!