Automatically recording canned responses for stubbed shell commands

This brief post shows a shell script that can automatically record canned responses from a shell command, for example the aws command line, for later use in shUnit2 tests.

For more information, see my other posts on unit testing bash scripts in shUnit2.


Replace the command of interest with a shell function following this pattern:


#!/bin/bash log_file=/tmp/ aws() { if [ ! -e $log_file ] then echo 'aws() {' >> $log_file echo ' case "$*" in' >> $log_file else awk '/esac/{exit}{print}' $log_file > x ; mv x $log_file fi echo ' "'$*'")' >> $log_file echo " cat <<'EOF'" >> $log_file command aws $* | tee -a $log_file echo 'EOF' >> $log_file echo ' ;;' >> $log_file echo ' esac' >> $log_file echo '}' >> $log_file } aws ec2 describe-instances --instance-id i-0985e6cf081ec2424 --query 'Reservations[*].Instances[0].PrivateIpAddress' --output text aws ec2 describe-images --image-id ami-0001e562 --query 'Images[].OwnerId' --output text aws ec2 describe-images --image-id ami-0001e562 --query 'Images[].CreationDate' --output text read more

JQ commands for Puppet catalogs

This is a page dedicated to useful JQ commands for querying a compiled Puppet catalog.

General note about Puppet 3 v Puppet 4/5 catalogs

In Puppet 4 the catalog structure changed a little, and it is important to be aware that the crucial resources key is in the top level in Puppet 4/5, whereas it’s nested under the data key in Puppet 3.

All commands below are for Puppet 4/5.

List all file resources by title

$ jq '.resources[] | select(.type == "File") | .title' < catalog.json read more