From 4abd1c22c173a0cedb540ee090fda94f01aec881 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 28 Jun 2013 15:58:32 -0400 Subject: [PATCH] builder/virtualbox: Set the default boot_wait [GH-44] --- builder/virtualbox/builder.go | 12 +++++++----- builder/virtualbox/builder_test.go | 9 ++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index 1cdc13b0d..e82af8d20 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -89,6 +89,10 @@ func (b *Builder) Prepare(raws ...interface{}) error { b.config.OutputDir = "virtualbox" } + if b.config.RawBootWait == "" { + b.config.RawBootWait = "10s" + } + if b.config.SSHHostPortMin == 0 { b.config.SSHHostPortMin = 2222 } @@ -168,11 +172,9 @@ func (b *Builder) Prepare(raws ...interface{}) error { errs = append(errs, errors.New("Output directory already exists. It must not exist.")) } - if b.config.RawBootWait != "" { - b.config.BootWait, err = time.ParseDuration(b.config.RawBootWait) - if err != nil { - errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err)) - } + b.config.BootWait, err = time.ParseDuration(b.config.RawBootWait) + if err != nil { + errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err)) } if b.config.RawShutdownTimeout == "" { diff --git a/builder/virtualbox/builder_test.go b/builder/virtualbox/builder_test.go index e509cbcc9..de880beb7 100644 --- a/builder/virtualbox/builder_test.go +++ b/builder/virtualbox/builder_test.go @@ -61,9 +61,16 @@ func TestBuilderPrepare_BootWait(t *testing.T) { var b Builder config := testConfig() + // Test a default boot_wait + delete(config, "boot_wait") + err := b.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + // Test with a bad boot_wait config["boot_wait"] = "this is not good" - err := b.Prepare(config) + err = b.Prepare(config) if err == nil { t.Fatal("should have error") }