To subscribe to updates watch my GitHub repository. New posts get added as pull requests.

Test infrastructure with goss

17 Nov 2017

goss is a simple utility for adding infrastructure tests. It is easy to use even for the most pedestrian of test writers. Some example usage includes:

$ goss add user jenkins
Adding User to './goss.yaml':

jenkins:
  exists: true
  uid: 999
  gid: 998
  groups:
  - jenkins
  home: /var/lib/jenkins
  shell: /sbin/nologin


$ goss validate
......

Total Duration: 0.003s
Count: 6, Failed: 0, Skipped: 0

Learn more about goss or download it.

Using it in the real world

I added some goss infrastructure tests to my personal project:

Using goss I added 80 infrastructure tests for my software which installs via RPM. Developing the tests took in less than 10 minutes.

Most of the time I spent trying to figure out how to effectively run the tests in CI. Then, I spent a few additional minutes copying the RPM work to DEB. A few minor test modifications were required because of minor differences installing across operating systems. I now have 160 infrastructure tests, testing DEB and RPM package installs in my personal project. This took relatively little effort.

Bonus round

Here’s a couple of one-liners I used to quickly add tests for myself. I’m not going to explain them much, but I will link to some documentation if you want to study them. Keep in mind, I am already in my test environment with my RPM package installed before running these commands.

goss add package jenkins-bootstrap

goss add service jenkins

goss add user jenkins

rpm -q --filesbypkg jenkins-bootstrap | awk '$2 ~ "etc" { print $2 }' | xargs -n1 goss add file

rpm -q --filesbypkg jenkins-bootstrap | awk '$2 ~ "init.groovy.d" { print $2 }' | xargs -n1 goss add file

find /var/lib/jenkins | xargs -n1 goss add file

goss validate

With the above command goss validate checks 100 tests. For my package installs, I only wanted to check certain parts of my installed software (like /etc and the path containing init.groovy.d).

Here are some links to additional reading material for better understanding of the one liners.


This article was last updated Nov 20, 2017.

Posted in Engineering with tags: Tips, Programming


Comments: