mirror of https://github.com/hashicorp/packer
Merge pull request #946 from jhelwig/vboxmanage-before-export
Add ability to run vboxmanage commands just before exporting [GH-664]pull/1089/head
commit
6373529af8
@ -0,0 +1,28 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
)
|
||||
|
||||
type VBoxManagePostConfig struct {
|
||||
VBoxManagePost [][]string `mapstructure:"vboxmanage_post"`
|
||||
}
|
||||
|
||||
func (c *VBoxManagePostConfig) Prepare(t *packer.ConfigTemplate) []error {
|
||||
if c.VBoxManagePost == nil {
|
||||
c.VBoxManagePost = make([][]string, 0)
|
||||
}
|
||||
|
||||
errs := make([]error, 0)
|
||||
for i, args := range c.VBoxManagePost {
|
||||
for j, arg := range args {
|
||||
if err := t.Validate(arg); err != nil {
|
||||
errs = append(errs,
|
||||
fmt.Errorf("Error processing vboxmanage_post[%d][%d]: %s", i, j, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVBoxManagePostConfigPrepare_VBoxManage(t *testing.T) {
|
||||
// Test with empty
|
||||
c := new(VBoxManagePostConfig)
|
||||
errs := c.Prepare(testConfigTemplate(t))
|
||||
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(VBoxManagePostConfig)
|
||||
c.VBoxManagePost = [][]string{
|
||||
{"foo", "bar", "baz"},
|
||||
}
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("err: %#v", errs)
|
||||
}
|
||||
|
||||
expected := [][]string{
|
||||
[]string{"foo", "bar", "baz"},
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(c.VBoxManagePost, expected) {
|
||||
t.Fatalf("bad: %#v", c.VBoxManagePost)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue