Commit 4d351eda authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/virtualbox: improved validation

parent 24895069
......@@ -109,6 +109,10 @@ func (b *Builder) Prepare(raw interface{}) error {
}
}
if b.config.SSHHostPortMin > b.config.SSHHostPortMax {
errs = append(errs, errors.New("ssh_host_port_min must be less than ssh_host_port_max"))
}
b.driver, err = b.newDriver()
if err != nil {
errs = append(errs, fmt.Errorf("Failed creating VirtualBox driver: %s", err))
......
......@@ -122,3 +122,32 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
t.Fatalf("iso_url should be modified: %s", b.config.ISOUrl)
}
}
func TestBuilderPrepare_SSHHostPort(t *testing.T) {
var b Builder
config := testConfig()
// Bad
config["ssh_host_port_min"] = 1000
config["ssh_host_port_max"] = 500
err := b.Prepare(config)
if err == nil {
t.Fatal("should have error")
}
// Bad
config["ssh_host_port_min"] = -500
err = b.Prepare(config)
if err == nil {
t.Fatal("should have error")
}
// Good
config["ssh_host_port_min"] = 500
config["ssh_host_port_max"] = 1000
err = b.Prepare(config)
if err != nil {
t.Fatalf("should not have error: %s", err)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment