diff --git a/test/builder_amazon_ebs.bats b/test/builder_amazon_ebs.bats index 9db5ddb9c..fd1e84172 100755 --- a/test/builder_amazon_ebs.bats +++ b/test/builder_amazon_ebs.bats @@ -8,9 +8,7 @@ load test_helper fixtures amazon-ebs teardown() { - aws ec2 describe-images --owners self --output json --filters 'Name=tag:packer-test,Values=true' \ - | jq -r -M '.Images[]["ImageId"]' \ - | xargs -n1 aws ec2 deregister-image --image-id + aws_ami_cleanup } @test "build minimal.json" { diff --git a/test/test_helper.bash b/test/test_helper.bash index 5bde7766f..c16c737c1 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -7,12 +7,9 @@ for cmd in "${required[@]}"; do } done -# This sets the directory for fixtures by specifying the name of -# the folder with fixtures. -fixtures() { - FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1" -} - +#-------------------------------------------------------------------- +# Bats modification +#-------------------------------------------------------------------- # This allows us to override a function in Bash save_function() { local ORIG_FUNC=$(declare -f $1) @@ -30,3 +27,19 @@ run() { echo $line done } + +#-------------------------------------------------------------------- +# Helper functions +#-------------------------------------------------------------------- +# This sets the directory for fixtures by specifying the name of +# the folder with fixtures. +fixtures() { + FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1" +} + +# This deletes any AMIs with a tag "packer-test" of "true" +aws_ami_cleanup() { + aws ec2 describe-images --owners self --output json --filters 'Name=tag:packer-test,Values=true' \ + | jq -r -M '.Images[]["ImageId"]' \ + | xargs -n1 aws ec2 deregister-image --image-id +}