pedestal

asilverman 2019-02-08T21:38:27.033600Z

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

asilverman 2019-02-08T21:38:47.034100Z

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

2019-02-08T22:28:01.035700Z

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

asilverman 2019-02-11T17:25:42.008800Z

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

2019-02-12T14:13:18.010500Z

@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

2019-02-12T14:13:55.010800Z

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

2019-02-12T14:14:39.011Z

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

2019-02-12T14:14:47.011200Z

Headers can also be passed

asilverman 2019-02-12T17:49:35.017200Z

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