You Can And Should Write Tests For Your Shell Scripts

--

As a Software Engineer implementing features for an application, it’s common practice to write tests that verify the logic behind it. But how about when you are writing shell scripts? I rarely see tests written for shell scripts and I think that is something that can be improved.

Why I started writing tests for shell scripts

As a DevOps Engineer, I spend a lot of time writing tools, scripts and Ansible playbooks to automate engineering processes. Most of the time I verify that my scripts work by running them on live non-production environments and I admit that this is bad practice.

Horror story time. There was an incident where I ran an automation script on 1 of my environments and things went horribly wrong. There was a section in the automation script that was supposed to remove symbolic links to folders. However, the environment I ran the script on did not have the these symbolic links and the script ended up deleting the folders instead. This caused the environment to be corrupted and unusable.

It took me a few days to fix things and this impacted the work of my engineers as we ran all our regression tests against this environment. While I attempted to fix and recover the environment, the team had to adapt our usual delivery flow for the sprint which took some time. Moral of the story — maybe this could have been avoided if I had written tests for my script to check that the symbolic links to the folders…

--

--

Government Digital Products, Singapore
Government Digital Products, Singapore

Published in Government Digital Products, Singapore

Be Happy, Be Awesome! We deliver high-quality digital services to citizens and businesses in Singapore 😊

Salihan Zaol-kefli
Salihan Zaol-kefli

Written by Salihan Zaol-kefli

Software Engineer, Amateur Writer, Casual Gamer

No responses yet