Run Unit Test Before Every Commit with pre-commit Hook

Why wait for CI/CD services to run your test? And suppose if you’ve submitted a pull request, you’ll have to push another commit to fix the cause of failed unit test. You can prevent that by running unit tests locally before every commit.

Introduction

Why wait for CI/CD services to run your test? And in case you’ve already submitted a pull request, you’ll have to push another commit to fix the cause of failed test held by CI provider. You can prevent that by running unit tests locally before every commit.

I’m building my website using the golang. On every git push, Travis CI runs test and create a docker image and pushes it to DockerHub. My plan is to pull that image every time it is pushed and deploy it to some production server.

Failed Travis build.
Failed Travis build.

One thing I’ve learned about this deployment system is, once I push my repo to GitHub and wait for the image to be pushed to DockerHub. I’m not sure if the test will pass and the image will be pushed. I have to open TravisCI every time I’ve to make sure.

Now I’ll show what workflow I use to to get this done.

Continue reading “Run Unit Test Before Every Commit with pre-commit Hook”