|
|
|
|
@ -52,6 +52,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)
|
|
|
|
|
@ -71,6 +72,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)
|
|
|
|
|
@ -94,6 +96,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)
|
|
|
|
|
@ -105,6 +108,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")
|
|
|
|
|
@ -202,6 +206,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")
|
|
|
|
|
@ -210,6 +215,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)
|
|
|
|
|
@ -231,18 +237,59 @@ func TestBuilderPrepare_InvalidKey(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) {
|
|
|
|
|
@ -257,6 +304,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")
|
|
|
|
|
@ -264,6 +312,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)
|
|
|
|
|
@ -283,6 +332,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)
|
|
|
|
|
@ -300,6 +350,7 @@ func TestBuilderPrepare_SSHUser(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config["ssh_username"] = "exists"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -347,6 +398,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)
|
|
|
|
|
@ -370,6 +422,7 @@ func TestBuilderPrepare_ToolsUploadPath(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test with a bad value
|
|
|
|
|
config["tools_upload_path"] = "{{{nope}"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
@ -377,6 +430,7 @@ func TestBuilderPrepare_ToolsUploadPath(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
|
config["tools_upload_path"] = "hey"
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
@ -397,6 +451,7 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Bad
|
|
|
|
|
config["vnc_port_min"] = -500
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
@ -405,6 +460,7 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
|
|
|
|
|
// Good
|
|
|
|
|
config["vnc_port_min"] = 500
|
|
|
|
|
config["vnc_port_max"] = 1000
|
|
|
|
|
b = Builder{}
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
|