packer-cn/builder/virtualbox/common/vbox_version_config_test.go

80 lines
1.7 KiB
Go
Raw Normal View History

2013-12-22 14:50:29 -05:00
package common
import (
"testing"
)
func TestVBoxVersionConfigPrepare_BootWait(t *testing.T) {
var c *VBoxVersionConfig
var errs []error
// Test empty
c = new(VBoxVersionConfig)
errs = c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("should not have error: %s", errs)
}
if *c.VBoxVersionFile != ".vbox_version" {
t.Fatalf("bad value: %s", *c.VBoxVersionFile)
2013-12-22 14:50:29 -05:00
}
// Test with a good one
c = new(VBoxVersionConfig)
filename := "foo"
c.VBoxVersionFile = &filename
2013-12-22 14:50:29 -05:00
errs = c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("should not have error: %s", errs)
}
if *c.VBoxVersionFile != "foo" {
t.Fatalf("bad value: %s", *c.VBoxVersionFile)
}
}
func TestVBoxVersionConfigPrepare_empty(t *testing.T) {
var c *VBoxVersionConfig
var errs []error
// Test with nil value
c = new(VBoxVersionConfig)
c.VBoxVersionFile = nil
errs = c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("should not have error: %s", errs)
}
if *c.VBoxVersionFile != ".vbox_version" {
t.Fatalf("bad value: %s", *c.VBoxVersionFile)
}
// Test with empty name
c = new(VBoxVersionConfig)
filename := ""
c.VBoxVersionFile = &filename
errs = c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("should not have error: %s", errs)
}
if *c.VBoxVersionFile != "" {
t.Fatalf("bad value: %s", *c.VBoxVersionFile)
2013-12-22 14:50:29 -05:00
}
}
func TestVBoxVersionConfigPrepare_communicator(t *testing.T) {
var c *VBoxVersionConfig
var errs []error
// Test with 'none' communicator and non-empty virtualbox_version_file
c = new(VBoxVersionConfig)
filename := "test"
c.VBoxVersionFile = &filename
c.Communicator = "none"
errs = c.Prepare(testConfigTemplate(t))
if len(errs) == 0 {
t.Fatalf("should have an error")
}
}