I'm trying to unit test my microservices before deployment, however in the Skaffold pipeline images are tested before deployment. The issue here is that the code in my images are dependent on configs and credentials that are mounted from k8s configmaps and secrets, therefore tests will always fail if unit tests are run before deployment.
How do I run unit tests for microservices with skaffold? How are unit tests normally run for microservices? Looking around the net, no one seems to have a straight answer.
Any guidance will be much appreciated.
There are several strategies I've used or seen people use for end-to-end testing of a deployment:
container-debug-support
images that are used by skaffold debug
. We run a little script that builds and deploys a set of images in a integration
profile that includes a set of test Jobs (example). The script then waits for these jobs to complete with kubectl wait
.after-deploy
hooks. You can use this to do some smoke testing or load testing. This approach works if you're planning to keep the app running; I'm not sure that tearing down the app within the hooks is a great idea.skaffold run
and skaffold delete
are helpful primitives for staging and tearing down an application.