Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
f599e2d0
Commit
f599e2d0
authored
Dec 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: minimal amazon-ebs test
parent
bf10af64
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
0 deletions
+99
-0
test/README.md
test/README.md
+35
-0
test/builder_amazon_ebs.bats
test/builder_amazon_ebs.bats
+19
-0
test/fixtures/amazon-ebs/minimal.json
test/fixtures/amazon-ebs/minimal.json
+13
-0
test/test_helper.bash
test/test_helper.bash
+32
-0
No files found.
test/README.md
View file @
f599e2d0
...
...
@@ -6,3 +6,38 @@ results are expected.
Tests are run using
[
Bats
](
https://github.com/sstephenson/bats
)
, and therefore
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.
test/builder_amazon_ebs.bats
0 → 100755
View file @
f599e2d0
#!/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 ]
}
test/fixtures/amazon-ebs/minimal.json
0 → 100644
View file @
f599e2d0
{
"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"
}
}]
}
test/test_helper.bash
0 → 100644
View file @
f599e2d0
# 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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment