Testing of Caddy config

It would be extremly helpful if caddy would have a way to test the configuration before deploying.

Currently I can only modify the configuration and hope that it works in production. And it usually doesn’t. Also with every change I am worried that some of the other existing rules might break eg if a new rule matches too much.

So to fix this I propose a test mode of caddy where I can just give it a list of URLs and it will output how each of the URLs will be handled.

Then I can check in a test set of URLs and the expected outcome and compare if everything still works before deploying to production.

Thank you

You can run caddy validate. It does some surface-level checks to check that the config is valid, without actually running it.

If you’re worried about the result of request matchers, there’s not really any way to write a testing tool in Caddy that could test it for you. You’ll need to write your own tests. It’s not possible for Caddy to actually know your intentions, it can only take your config and assume that’s what you wanted to do (aside from syntactical/structural issues).

Matchers don’t only cover paths, but also many other aspects of a request like headers, remote IPs, hostname, scheme, whether files exist on disk for a given path, etc.

And the request might not only be handled by a single handler, it actually goes through a whole middleware chain, first down the chain then back up the chain (some handlers want to do stuff after the response has been written, like some header adjustments or encoding/compressing).

This topic was automatically closed after 30 days. New replies are no longer allowed.