Skip to content

Commit

Permalink
test: cleaner helper file
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Dec 12, 2013
1 parent 1cfffaf commit a7537ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
4 changes: 1 addition & 3 deletions test/builder_amazon_ebs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
25 changes: 19 additions & 6 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

0 comments on commit a7537ff

Please sign in to comment.