I have a program which calls certbot-auto to register a new SSL certificate when it is triggered. Now I’m going to write unit tests for this program. What are the best practices for writing unit tests in this case?
I don’t want the unit tests to depend on network connections. Should I write another program that mimics the input and output of certbot-auto?
I don’t believe that Certbot was written to be programmatically driven. If you have the opportunity, it may be better for you to directly use libraries that implement the ACME protocol, and then you will have much better control over success/failure.
To continue with your current approach, I would just to look at the exit code of the certbot process. (0 means success, everything else is failure).
Parsing the text output of Certbot is far too fragile for my liking.
As far as depending on network connectivity, you can actually just run Boulder yourself in a test mode (or even the Pebble project) which will provide an ACME implementation you can use Certbot against, on localhost (i.e. with flag --server http://localhost:4000/directory).
FWIW I think this is an integration test, not a unit test.