From 07ed22b4faae7475df09840d3f226cf023d6d2cd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 30 Jul 2013 22:29:06 -0700 Subject: [PATCH] builder/amazon/chroot: validate that chroot_mounts are 3 elements --- builder/amazon/chroot/builder.go | 8 ++++++++ builder/amazon/chroot/builder_test.go | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index 3eeaa2051..3a42045fb 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -83,6 +83,14 @@ func (b *Builder) Prepare(raws ...interface{}) error { errs := common.CheckUnusedConfig(md) errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare()...) + for _, mounts := range b.config.ChrootMounts { + if len(mounts) != 3 { + errs = packer.MultiErrorAppend( + errs, errors.New("Each chroot_mounts entry should be three elements.")) + break + } + } + if b.config.SourceAmi == "" { errs = packer.MultiErrorAppend(errs, errors.New("source_ami is required.")) } diff --git a/builder/amazon/chroot/builder_test.go b/builder/amazon/chroot/builder_test.go index 2736dbbd8..2e4b5986a 100644 --- a/builder/amazon/chroot/builder_test.go +++ b/builder/amazon/chroot/builder_test.go @@ -19,6 +19,24 @@ func TestBuilder_ImplementsBuilder(t *testing.T) { } } +func TestBuilderPrepare_ChrootMounts(t *testing.T) { + b := &Builder{} + config := testConfig() + + config["chroot_mounts"] = nil + err := b.Prepare(config) + if err != nil { + t.Errorf("err: %s", err) + } + + config["chroot_mounts"] = [][]string{ + []string{"bad"}, + } + err = b.Prepare(config) + if err == nil { + t.Fatal("should have error") + } +} func TestBuilderPrepare_SourceAmi(t *testing.T) { b := &Builder{} config := testConfig()