test: minimal amazon-ebs test
This commit is contained in:
parent
bf10af6401
commit
f599e2d0ce
|
@ -6,3 +6,38 @@ results are expected.
|
||||||
|
|
||||||
Tests are run using [Bats](https://github.com/sstephenson/bats), and therefore
|
Tests are run using [Bats](https://github.com/sstephenson/bats), and therefore
|
||||||
Bash is required to run any tests.
|
Bash is required to run any tests.
|
||||||
|
|
||||||
|
**Warning:** Many of these tests run using AWS, and therefore have a
|
||||||
|
real-world cost associated with running the tests. Be aware of that prior
|
||||||
|
to running the tests. Additionally, many tests will leave left-over artifacts
|
||||||
|
(AMIs) that you'll have to manually clean up.
|
||||||
|
|
||||||
|
## Required Software
|
||||||
|
|
||||||
|
Before running the tests, you'll need the following installed. If you're
|
||||||
|
running on Mac OS X, most of these are available with `brew`:
|
||||||
|
|
||||||
|
* [Bats](https://github.com/sstephenson/bats)
|
||||||
|
|
||||||
|
* [AWS cli](http://aws.amazon.com/cli/)
|
||||||
|
* [jq](http://stedolan.github.io/jq/)
|
||||||
|
|
||||||
|
## Configuring Tests
|
||||||
|
|
||||||
|
**For tests that require AWS credentials:**
|
||||||
|
|
||||||
|
Set the following self-explanatory environmental variables:
|
||||||
|
|
||||||
|
* `AWS_ACCESS_KEY_ID`
|
||||||
|
* `AWS_SECRET_ACCESS_KEY`
|
||||||
|
|
||||||
|
## Running Tests
|
||||||
|
|
||||||
|
These tests are meant to be run _one file at a time_. There are some
|
||||||
|
test files (such as the amazon-chroot builder test) that simply won't
|
||||||
|
run except in special environments, so running all test files will probably
|
||||||
|
never work.
|
||||||
|
|
||||||
|
If you're working on Packer and want to test that your change didn't
|
||||||
|
adversely affect something, try running only the test that is related to
|
||||||
|
your change.
|
||||||
|
|
|
@ -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