mirror of https://github.com/hashicorp/packer
parent
5feb7bce18
commit
5f1c597269
@ -0,0 +1,31 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
type VBoxVersionConfig struct {
|
||||
VBoxVersionFile string `mapstructure:"virtualbox_version_file"`
|
||||
}
|
||||
|
||||
func (c *VBoxVersionConfig) Prepare(t *packer.ConfigTemplate) []error {
|
||||
if c.VBoxVersionFile == "" {
|
||||
c.VBoxVersionFile = ".vbox_version"
|
||||
}
|
||||
|
||||
templates := map[string]*string{
|
||||
"virtualbox_version_file": &c.VBoxVersionFile,
|
||||
}
|
||||
|
||||
errs := make([]error, 0)
|
||||
for n, ptr := range templates {
|
||||
var err error
|
||||
*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,33 @@
|
||||
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)
|
||||
}
|
||||
|
||||
// Test with a good one
|
||||
c = new(VBoxVersionConfig)
|
||||
c.VBoxVersionFile = "foo"
|
||||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue