2013-12-22 12:24:29 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2019-06-14 04:55:10 -04:00
|
|
|
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-12-22 12:24:29 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVBoxManageConfigPrepare_VBoxManage(t *testing.T) {
|
|
|
|
// Test with empty
|
|
|
|
c := new(VBoxManageConfig)
|
2019-06-14 04:55:10 -04:00
|
|
|
errs := c.Prepare(interpolate.NewContext())
|
2013-12-22 12:24:29 -05:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("err: %#v", errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(c.VBoxManage, [][]string{}) {
|
|
|
|
t.Fatalf("bad: %#v", c.VBoxManage)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
c = new(VBoxManageConfig)
|
|
|
|
c.VBoxManage = [][]string{
|
|
|
|
{"foo", "bar", "baz"},
|
|
|
|
}
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2013-12-22 12:24:29 -05:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("err: %#v", errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := [][]string{
|
2016-11-01 17:08:04 -04:00
|
|
|
{"foo", "bar", "baz"},
|
2013-12-22 12:24:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(c.VBoxManage, expected) {
|
|
|
|
t.Fatalf("bad: %#v", c.VBoxManage)
|
|
|
|
}
|
|
|
|
}
|
2019-06-19 11:07:23 -04:00
|
|
|
|
|
|
|
func TestVBoxManageConfigPrepare_PostVBoxManage(t *testing.T) {
|
|
|
|
// Test with empty
|
|
|
|
c := new(VBoxManageConfig)
|
|
|
|
errs := c.Prepare(interpolate.NewContext())
|
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("err: %#v", errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(c.VBoxManagePost, [][]string{}) {
|
|
|
|
t.Fatalf("bad: %#v", c.VBoxManagePost)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
c = new(VBoxManageConfig)
|
|
|
|
c.VBoxManagePost = [][]string{
|
|
|
|
{"foo", "bar", "baz"},
|
|
|
|
}
|
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("err: %#v", errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := [][]string{
|
|
|
|
{"foo", "bar", "baz"},
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(c.VBoxManagePost, expected) {
|
|
|
|
t.Fatalf("bad: %#v", c.VBoxManagePost)
|
|
|
|
}
|
|
|
|
}
|