mirror of https://github.com/hashicorp/packer
parent
f522fd9840
commit
0367476c39
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# This tests the amazon-ebs builder. The teardown function will automatically
|
||||
# delete any AMIs with a tag of `packer-test` being equal to "true" so
|
||||
# be sure any test cases set this.
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@test "build minimal.json" {
|
||||
run packer build $FIXTURE_ROOT/minimal.json
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}]
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
# Let's verify that the tools we need are installed
|
||||
declare -a required=(aws jq)
|
||||
for cmd in "${required[@]}"; do
|
||||
command -v $cmd >/dev/null 2>&1 || {
|
||||
echo "'$cmd' must be installed" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
|
||||
# This sets the directory for fixtures by specifying the name of
|
||||
# the folder with fixtures.
|
||||
fixtures() {
|
||||
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1"
|
||||
}
|
||||
|
||||
# This allows us to override a function in Bash
|
||||
save_function() {
|
||||
local ORIG_FUNC=$(declare -f $1)
|
||||
local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
|
||||
eval "$NEWNAME_FUNC"
|
||||
}
|
||||
|
||||
# Override the run function so that we always output the output
|
||||
save_function run old_run
|
||||
run() {
|
||||
old_run $@
|
||||
|
||||
# "$output" gets rid of newlines. This will bring them back.
|
||||
for line in "${lines[@]}"; do
|
||||
echo $line
|
||||
done
|
||||
}
|
||||
Loading…
Reference in new issue