2013-07-29 19:42:35 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testConfig() map[string]interface{} {
|
2013-07-30 12:55:17 -04:00
|
|
|
return map[string]interface{}{
|
2013-07-31 01:33:41 -04:00
|
|
|
"ami_name": "foo",
|
2013-07-30 12:55:17 -04:00
|
|
|
"source_ami": "foo",
|
|
|
|
}
|
2013-07-29 19:42:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilder_ImplementsBuilder(t *testing.T) {
|
|
|
|
var raw interface{}
|
|
|
|
raw = &Builder{}
|
|
|
|
if _, ok := raw.(packer.Builder); !ok {
|
|
|
|
t.Fatalf("Builder should be a builder")
|
|
|
|
}
|
|
|
|
}
|
2013-07-30 12:55:17 -04:00
|
|
|
|
2013-07-31 01:33:41 -04:00
|
|
|
func TestBuilderPrepare_AMIName(t *testing.T) {
|
|
|
|
var b Builder
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
// Test good
|
|
|
|
config["ami_name"] = "foo"
|
2013-11-02 23:56:54 -04:00
|
|
|
warnings, err := b.Prepare(config)
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
2013-07-31 01:33:41 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test bad
|
|
|
|
config["ami_name"] = "foo {{"
|
|
|
|
b = Builder{}
|
2013-11-02 23:56:54 -04:00
|
|
|
warnings, err = b.Prepare(config)
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
2013-07-31 01:33:41 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test bad
|
|
|
|
delete(config, "ami_name")
|
|
|
|
b = Builder{}
|
2013-11-02 23:56:54 -04:00
|
|
|
warnings, err = b.Prepare(config)
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
2013-07-31 01:33:41 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-31 01:29:06 -04:00
|
|
|
func TestBuilderPrepare_ChrootMounts(t *testing.T) {
|
|
|
|
b := &Builder{}
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
config["chroot_mounts"] = nil
|
2013-11-02 23:56:54 -04:00
|
|
|
warnings, err := b.Prepare(config)
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
2013-07-31 01:29:06 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
config["chroot_mounts"] = [][]string{
|
|
|
|
[]string{"bad"},
|
|
|
|
}
|
2013-11-02 23:56:54 -04:00
|
|
|
warnings, err = b.Prepare(config)
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
2013-07-31 01:29:06 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
2013-07-30 12:55:17 -04:00
|
|
|
func TestBuilderPrepare_SourceAmi(t *testing.T) {
|
|
|
|
b := &Builder{}
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
config["source_ami"] = ""
|
2013-11-02 23:56:54 -04:00
|
|
|
warnings, err := b.Prepare(config)
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
2013-07-30 12:55:17 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
config["source_ami"] = "foo"
|
2013-11-02 23:56:54 -04:00
|
|
|
warnings, err = b.Prepare(config)
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
2013-07-30 12:55:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2013-09-27 07:55:19 -04:00
|
|
|
|
|
|
|
func TestBuilderPrepare_CommandWrapper(t *testing.T) {
|
|
|
|
b := &Builder{}
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
config["command_wrapper"] = "echo hi; {{.Command}}"
|
2013-11-02 23:56:54 -04:00
|
|
|
warnings, err := b.Prepare(config)
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warnings)
|
|
|
|
}
|
2013-09-27 07:55:19 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|