builder/virtualbox: Tests for the defaults [GH-44]

This commit is contained in:
Mitchell Hashimoto 2013-06-28 16:00:42 -04:00
parent e920c49e8f
commit 5786f6ad5a
2 changed files with 20 additions and 5 deletions

View File

@ -181,6 +181,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b.config.RawShutdownTimeout = "5m" b.config.RawShutdownTimeout = "5m"
} }
if b.config.RawSSHWaitTimeout == "" {
b.config.RawSSHWaitTimeout = "20m"
}
b.config.ShutdownTimeout, err = time.ParseDuration(b.config.RawShutdownTimeout) b.config.ShutdownTimeout, err = time.ParseDuration(b.config.RawShutdownTimeout)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err)) errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err))
@ -194,10 +198,6 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs = append(errs, errors.New("An ssh_username must be specified.")) errs = append(errs, errors.New("An ssh_username must be specified."))
} }
if b.config.RawSSHWaitTimeout == "" {
b.config.RawSSHWaitTimeout = "20m"
}
b.config.SSHWaitTimeout, err = time.ParseDuration(b.config.RawSSHWaitTimeout) b.config.SSHWaitTimeout, err = time.ParseDuration(b.config.RawSSHWaitTimeout)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing ssh_wait_timeout: %s", err)) errs = append(errs, fmt.Errorf("Failed parsing ssh_wait_timeout: %s", err))

View File

@ -68,6 +68,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
if b.config.RawBootWait != "10s" {
t.Fatalf("bad value: %s", b.config.RawBootWait)
}
// Test with a bad boot_wait // Test with a bad boot_wait
config["boot_wait"] = "this is not good" config["boot_wait"] = "this is not good"
err = b.Prepare(config) err = b.Prepare(config)
@ -324,9 +328,20 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
var b Builder var b Builder
config := testConfig() config := testConfig()
// Test a default boot_wait
delete(config, "ssh_wait_timeout")
err := b.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if b.config.RawSSHWaitTimeout != "20m" {
t.Fatalf("bad value: %s", b.config.RawSSHWaitTimeout)
}
// Test with a bad value // Test with a bad value
config["ssh_wait_timeout"] = "this is not good" config["ssh_wait_timeout"] = "this is not good"
err := b.Prepare(config) err = b.Prepare(config)
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }