From 34b6c97c2126f6041b89c8b414aef1fc0d0c846c Mon Sep 17 00:00:00 2001 From: Chris Lundquist Date: Wed, 25 May 2016 21:23:07 +0000 Subject: [PATCH] [lxc] add bats tests --- test/builder_lxc.bats | 40 ++++++++++++++++++++++++++ test/fixtures/builder-lxc/minimal.json | 15 ++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/builder_lxc.bats create mode 100644 test/fixtures/builder-lxc/minimal.json diff --git a/test/builder_lxc.bats b/test/builder_lxc.bats new file mode 100644 index 000000000..c29030424 --- /dev/null +++ b/test/builder_lxc.bats @@ -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 ] +} diff --git a/test/fixtures/builder-lxc/minimal.json b/test/fixtures/builder-lxc/minimal.json new file mode 100644 index 000000000..5bf7998fd --- /dev/null +++ b/test/fixtures/builder-lxc/minimal.json @@ -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`}}" ] + } + ] +}