command/fix: rename vmware to vmware-iso
This commit is contained in:
parent
ca867cdbb1
commit
87f9eca511
|
@ -25,6 +25,7 @@ func init() {
|
|||
"pp-vagrant-override": new(FixerVagrantPPOverride),
|
||||
"virtualbox-gaattach": new(FixerVirtualBoxGAAttach),
|
||||
"virtualbox-rename": new(FixerVirtualBoxRename),
|
||||
"vmware-rename": new(FixerVMwareRename),
|
||||
}
|
||||
|
||||
FixerOrder = []string{
|
||||
|
@ -33,5 +34,6 @@ func init() {
|
|||
"virtualbox-gaattach",
|
||||
"pp-vagrant-override",
|
||||
"virtualbox-rename",
|
||||
"vmware-rename",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// FixerVMwareRename changes "virtualbox" builders to "virtualbox-iso"
|
||||
type FixerVMwareRename struct{}
|
||||
|
||||
func (FixerVMwareRename) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
||||
// The type we'll decode into; we only care about builders
|
||||
type template struct {
|
||||
Builders []map[string]interface{}
|
||||
}
|
||||
|
||||
// Decode the input into our structure, if we can
|
||||
var tpl template
|
||||
if err := mapstructure.Decode(input, &tpl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, builder := range tpl.Builders {
|
||||
builderTypeRaw, ok := builder["type"]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
builderType, ok := builderTypeRaw.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if builderType != "vmware" {
|
||||
continue
|
||||
}
|
||||
|
||||
builder["type"] = "vmware-iso"
|
||||
}
|
||||
|
||||
input["builders"] = tpl.Builders
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (FixerVMwareRename) Synopsis() string {
|
||||
return `Updates "vmware" builders to "vmware-iso"`
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFixerVMwareRename_impl(t *testing.T) {
|
||||
var _ Fixer = new(FixerVMwareRename)
|
||||
}
|
||||
|
||||
func TestFixerVMwareRename_Fix(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input map[string]interface{}
|
||||
Expected map[string]interface{}
|
||||
}{
|
||||
// No attach field
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "vmware",
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "vmware-iso",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
var f FixerVMwareRename
|
||||
|
||||
input := map[string]interface{}{
|
||||
"builders": []map[string]interface{}{tc.Input},
|
||||
}
|
||||
|
||||
expected := map[string]interface{}{
|
||||
"builders": []map[string]interface{}{tc.Expected},
|
||||
}
|
||||
|
||||
output, err := f.Fix(input)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(output, expected) {
|
||||
t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue