|
|
|
|
@ -84,6 +84,7 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
|
config["boot_wait"] = "5s"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -210,6 +211,7 @@ func TestBuilderPrepare_GuestAdditionsURL(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config["guest_additions_url"] = "http://www.packer.io"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("should not have error: %s", err)
|
|
|
|
|
@ -230,6 +232,7 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Bad
|
|
|
|
|
config["http_port_min"] = -500
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
@ -238,6 +241,7 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
|
|
|
|
// Good
|
|
|
|
|
config["http_port_min"] = 500
|
|
|
|
|
config["http_port_max"] = 1000
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -269,6 +273,7 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test good
|
|
|
|
|
config["iso_checksum"] = "FOo"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -292,6 +297,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test good
|
|
|
|
|
config["iso_checksum_type"] = "mD5"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -303,6 +309,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test unknown
|
|
|
|
|
config["iso_checksum_type"] = "fake"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
@ -312,18 +319,59 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
|
|
|
|
|
func TestBuilderPrepare_ISOUrl(t *testing.T) {
|
|
|
|
|
var b Builder
|
|
|
|
|
config := testConfig()
|
|
|
|
|
delete(config, "iso_url")
|
|
|
|
|
delete(config, "iso_urls")
|
|
|
|
|
|
|
|
|
|
// Test both epty
|
|
|
|
|
config["iso_url"] = ""
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err := b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test iso_url set
|
|
|
|
|
config["iso_url"] = "http://www.packer.io"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("should not have error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expected := []string{"http://www.packer.io"}
|
|
|
|
|
if !reflect.DeepEqual(b.config.ISOUrls, expected) {
|
|
|
|
|
t.Fatalf("bad: %#v", b.config.ISOUrls)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test both set
|
|
|
|
|
config["iso_url"] = "http://www.packer.io"
|
|
|
|
|
config["iso_urls"] = []string{"http://www.packer.io"}
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test just iso_urls set
|
|
|
|
|
delete(config, "iso_url")
|
|
|
|
|
config["iso_urls"] = []string{
|
|
|
|
|
"http://www.packer.io",
|
|
|
|
|
"http://www.hashicorp.com",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("should not have error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expected = []string{
|
|
|
|
|
"http://www.packer.io",
|
|
|
|
|
"http://www.hashicorp.com",
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(b.config.ISOUrls, expected) {
|
|
|
|
|
t.Fatalf("bad: %#v", b.config.ISOUrls)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuilderPrepare_OutputDir(t *testing.T) {
|
|
|
|
|
@ -338,6 +386,7 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
|
|
config["output_directory"] = dir
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
@ -345,6 +394,7 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
|
config["output_directory"] = "i-hope-i-dont-exist"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -364,6 +414,7 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
|
config["shutdown_timeout"] = "5s"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -377,6 +428,7 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
|
|
|
|
|
// Bad
|
|
|
|
|
config["ssh_host_port_min"] = 1000
|
|
|
|
|
config["ssh_host_port_max"] = 500
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err := b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
@ -384,6 +436,7 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Bad
|
|
|
|
|
config["ssh_host_port_min"] = -500
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
@ -392,6 +445,7 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
|
|
|
|
|
// Good
|
|
|
|
|
config["ssh_host_port_min"] = 500
|
|
|
|
|
config["ssh_host_port_max"] = 1000
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -403,12 +457,14 @@ func TestBuilderPrepare_SSHUser(t *testing.T) {
|
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
|
|
config["ssh_username"] = ""
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err := b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config["ssh_username"] = "exists"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -432,6 +488,7 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test with a bad value
|
|
|
|
|
config["ssh_wait_timeout"] = "this is not good"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
@ -439,6 +496,7 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
|
config["ssh_wait_timeout"] = "5s"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
|