2013-12-22 14:50:29 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-06-14 04:55:10 -04:00
|
|
|
|
2020-11-11 13:21:37 -05:00
|
|
|
"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)
|
2019-06-14 04:55:10 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-03-16 21:04:36 -04:00
|
|
|
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)
|
2017-03-16 21:04:36 -04:00
|
|
|
filename := "foo"
|
|
|
|
c.VBoxVersionFile = &filename
|
2019-06-14 04:55:10 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-03-16 21:04:36 -04:00
|
|
|
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
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2017-03-16 21:04:36 -04: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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with empty name
|
|
|
|
c = new(VBoxVersionConfig)
|
|
|
|
filename := ""
|
|
|
|
c.VBoxVersionFile = &filename
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2017-03-16 21:04:36 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2019-03-16 12:18:29 -04: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"
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2019-03-16 12:18:29 -04:00
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatalf("should have an error")
|
|
|
|
}
|
|
|
|
}
|