[lxc] add bats tests

This commit is contained in:
Chris Lundquist 2016-05-25 21:23:07 +00:00 committed by Megan Marsh
parent 5eb1bc9338
commit 34b6c97c21
2 changed files with 55 additions and 0 deletions

40
test/builder_lxc.bats Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env bats
#
# This tests the lxc builder. The teardown function will
# delete any images in the output-lxc-* folders.
#load test_helper
#fixtures builder-lxc
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/builder-lxc"
# Required parameters
command -v lxc-create >/dev/null 2>&1 || {
echo "'lxc-create' must be installed via the lxc (or lxc1 for ubuntu >=16.04) package" >&2
exit 1
}
teardown() {
rm -rf output-lxc-*
}
@test "lxc: build centos minimal.json" {
run packer build -var template_name=centos $FIXTURE_ROOT/minimal.json
[ "$status" -eq 0 ]
[ -f output-lxc-centos/rootfs.tar.gz ]
[ -f output-lxc-centos/lxc-config ]
}
@test "lxc: build trusty minimal.json" {
run packer build -var template_name=ubuntu -var template_parameters="SUITE=trusty" $FIXTURE_ROOT/minimal.json
[ "$status" -eq 0 ]
[ -f output-lxc-ubuntu/rootfs.tar.gz ]
[ -f output-lxc-ubuntu/lxc-config ]
}
@test "lxc: build debian minimal.json" {
run packer build -var template_name=debian -var template_parameters="SUITE=jessie" $FIXTURE_ROOT/minimal.json
[ "$status" -eq 0 ]
[ -f output-lxc-debian/rootfs.tar.gz ]
[ -f output-lxc-debian/lxc-config ]
}

15
test/fixtures/builder-lxc/minimal.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"variables": {
"template_name": "debian",
"template_parameters": "SUITE=jessie"
},
"builders": [
{
"type": "lxc",
"name": "lxc-{{user `template_name`}}",
"template_name": "{{user `template_name`}}",
"config_file": "/usr/share/lxc/config/{{user `template_name`}}.common.conf",
"template_environment_vars": [ "{{user `template_parameters`}}" ]
}
]
}