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

82 lines
1.8 KiB
Go
Raw Normal View History

2013-12-22 14:50:29 -05:00
package common
import (
"testing"
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
2013-12-22 14:50:29 -05:00
)
func TestVBoxVersionConfigPrepare_BootWait(t *testing.T) {
var c *VBoxVersionConfig
var errs []error
// Test empty
c = new(VBoxVersionConfig)
errs = c.Prepare(interpolate.NewContext())
2013-12-22 14:50:29 -05:00
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
errs = c.Prepare(interpolate.NewContext())
2013-12-22 14:50:29 -05:00
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(interpolate.NewContext())
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(interpolate.NewContext())
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(interpolate.NewContext())
if len(errs) == 0 {
t.Fatalf("should have an error")
}
}