mirror of https://github.com/hashicorp/packer
parent
525802e9e6
commit
eeadafc452
@ -0,0 +1,32 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
type DriverConfig struct {
|
||||
FusionAppPath string `mapstructure:"fusion_app_path"`
|
||||
}
|
||||
|
||||
func (c *DriverConfig) Prepare(t *packer.ConfigTemplate) []error {
|
||||
if c.FusionAppPath == "" {
|
||||
c.FusionAppPath = "/Applications/VMware Fusion.app"
|
||||
}
|
||||
|
||||
templates := map[string]*string{
|
||||
"fusion_app_path": &c.FusionAppPath,
|
||||
}
|
||||
|
||||
var err error
|
||||
errs := make([]error, 0)
|
||||
for n, ptr := range templates {
|
||||
*ptr, err = t.Process(*ptr, nil)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDriverConfigPrepare(t *testing.T) {
|
||||
var c *DriverConfig
|
||||
|
||||
// Test a default boot_wait
|
||||
c = new(DriverConfig)
|
||||
errs := c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("bad: %#v", errs)
|
||||
}
|
||||
if c.FusionAppPath != "/Applications/VMware Fusion.app" {
|
||||
t.Fatalf("bad value: %s", c.FusionAppPath)
|
||||
}
|
||||
|
||||
// Test with a good one
|
||||
c = new(DriverConfig)
|
||||
c.FusionAppPath = "foo"
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("bad: %#v", errs)
|
||||
}
|
||||
if c.FusionAppPath != "foo" {
|
||||
t.Fatalf("bad value: %s", c.FusionAppPath)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue