On 28/12/2014 14:13, Chris Price wrote: > On Sat, Dec 27, 2014 at 8:39 AM, Brice Figureau > <[email protected] <mailto:[email protected]>> > wrote: > The second problem I'm facing is testing the service. I have a coverage > of the various core functions (the ones producing the metadata > themself), but I struggle to see how to test whole endpoint from a given > request. > > Is there any pointers I should look at? > > > There are several different levels that you can test at, and it can be a > bit tricky to determine the most appropriate one... here are a few examples. > > If you want to test the ring request/response logic but you don't really > need to spin up a full Jetty instance to do it, you can do something > like this: > > https://github.com/puppetlabs/puppet-server/blob/dc81dbca89b206e00163c7d53d806e6c51c33ed0/test/unit/puppetlabs/services/master/master_core_test.clj#L12-L13 > > If you want to spin up a Jetty to test a ring app but you don't need the > full trapperkeeper stack, we have the with-test-webserver utility in the > tk-j9 testutils: > > Docs: > https://github.com/puppetlabs/trapperkeeper-webserver-jetty9/blob/d1f4fea3be52a937bd2f82fc512d274022cc8f49/doc/test-utils.md#with-test-webserver > Example usage: > https://github.com/puppetlabs/trapperkeeper-webserver-jetty9/blob/ad61d23dd7d3ccd7ebf96d93bc0b684d058d335d/test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_core_test.clj#L67 > > If you want to test via a trapperkeeper instance but w/o the full Puppet > Server stack, you can use the TK testutils, e.g. `with-app-with-config`: > > Docs: > https://github.com/puppetlabs/trapperkeeper/wiki/Test-Utils#with-app-with-config > Example: > https://github.com/puppetlabs/puppet-server/blob/0b5118f89d78e17e473fbdecd5414a7307b3668c/test/unit/puppetlabs/services/jruby/jruby_puppet_service_test.clj#L31 > > Finally, if you need a full death-star Puppet Server integration test > (which we don't find we usually need), we have a new testutil macro > called `with-puppetserver-running`: > > https://github.com/puppetlabs/puppet-server/blob/dc81dbca89b206e00163c7d53d806e6c51c33ed0/test/integration/puppetlabs/services/jruby/puppet_environments_int_test.clj#L112 > > That last one is pretty new and we probably need to build up some more > helper functions, test utilities, and best practices around it, though.
So I tried two of the above methods with great success, but in the case I'm focusing on it's not enough. Since it's a reimplementation of one of the ruby puppet service, I think what I should test is that the outcome of a given request by the clojure code is equivalent to what the ruby part would have returned. I think this is doable by using calling the request-handler service and comparing the result to what the clojure service would return. What do you think about that? -- Brice Figureau My Blog: http://www.masterzen.fr/ -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/54A14641.1030207%40daysofwonder.com. For more options, visit https://groups.google.com/d/optout.
