Hey folks,
is there anything in place that helps with or some good example of writing tests for plugins? I have a slight idea how I want it to look like, but I figured I ask first. I don’t want to overlook anything and also I think it is a matter for a more generic debate on how to approach this.
Some background, you may want to skip the next paragraph…
Quite some time ago I started to write a plugin called csp
for Caddy. It provides request scoped nonce values that are consumed by other request handlers that inject these values into the response body, as well as into the headers. Together this implements the Content-Security-Policy nonce attribute, This is in production on one of my servers and doing quite well. Actually I am a little proud how neat and performant it does its thing. Except I had a git rebase glitch or something and it stopped working. Unit tests still pass, but my integration tests that involve other middleware (template, browse) don’t, neither does the compiled server from the now unrecoverably broken source code. I can’t figure out what is wrong, because my integrations tests are a heap of spaghetti code (in contrast to my lovely crafted plugin itself). So redoing tests from scratch is what I want to do. Thanks for reading so far.
… so my plugin csp
depends on the header
plugin, replaces stuff in the headers and provides its “service” to other plugins (I have patched browse
and template
) so they can inject nonce values into the response. My idea was to provide “some thing” as part of csp
's public API that helps other plugin authors (and myself) to write tests that check the cooperation of all three plugins. Like providing some thing that takes your request handler and stacks it between the header
handler, my csp
handler and some response recorder handler, so you can check if the nonce is placed where you want it to be.
Stacking handlers, that’s what Caddy does already, i.e. there is an opportunity to leverage the mechanics that Caddy already provide and make it more wholesome leaning towards true integration testing. I’ve patched little bugs here and there in Caddy and each time looked at the surroundings of that code for some tests that I could extend and often there were simply none. That needs to change, right?
Ideas, hints, pointers anyone?
Cheers,
Johannes