github.com/rothwerx/packer@v0.9.0/test/test_helper.bash (about)

     1  # Let's verify that the tools we need are installed
     2  declare -a required=(aws)
     3  for cmd in "${required[@]}"; do
     4      command -v $cmd >/dev/null 2>&1 || {
     5          echo "'$cmd' must be installed" >&2
     6          exit 1
     7      }
     8  done
     9  
    10  #--------------------------------------------------------------------
    11  # Bats modification
    12  #--------------------------------------------------------------------
    13  # This allows us to override a function in Bash
    14  save_function() {
    15      local ORIG_FUNC=$(declare -f $1)
    16      local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
    17      eval "$NEWNAME_FUNC"
    18  }
    19  
    20  # Override the run function so that we always output the output
    21  save_function run old_run
    22  run() {
    23      old_run $@
    24  
    25      # Output the command we ran
    26      echo "Executing: " $@
    27  
    28      # "$output" gets rid of newlines. This will bring them back.
    29      for line in "${lines[@]}"; do
    30          echo $line
    31      done
    32  }
    33  
    34  #--------------------------------------------------------------------
    35  # Helper functions
    36  #--------------------------------------------------------------------
    37  # This sets the directory for fixtures by specifying the name of
    38  # the folder with fixtures.
    39  fixtures() {
    40      FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1"
    41  }
    42  
    43  # This deletes any AMIs with a tag "packer-test" of "true"
    44  aws_ami_cleanup() {
    45      local region=${1:-us-east-1}
    46      aws ec2 describe-images --region ${region} --owners self --output text \
    47          --filters 'Name=tag:packer-test,Values=true' \
    48          --query 'Images[*].ImageId' \
    49          | xargs -n1 aws ec2 deregister-image --region ${region} --image-id
    50  }