add fixer for manifest filename->output

This commit is contained in:
Matthew Hooker 2016-11-21 15:34:50 -08:00
parent b29d0b4378
commit e3acd19cb7
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
3 changed files with 103 additions and 0 deletions

View File

@ -29,6 +29,7 @@ func init() {
"parallels-headless": new(FixerParallelsHeadless), "parallels-headless": new(FixerParallelsHeadless),
"parallels-deprecations": new(FixerParallelsDeprecations), "parallels-deprecations": new(FixerParallelsDeprecations),
"sshkeypath": new(FixerSSHKeyPath), "sshkeypath": new(FixerSSHKeyPath),
"manifest-filename": new(FixerManifestFilename),
} }
FixerOrder = []string{ FixerOrder = []string{
@ -41,5 +42,6 @@ func init() {
"parallels-headless", "parallels-headless",
"parallels-deprecations", "parallels-deprecations",
"sshkeypath", "sshkeypath",
"manifest-filename",
} }
} }

View File

@ -0,0 +1,60 @@
package fix
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
// FixerManifestFilename renames any Filename to Output
type FixerManifestFilename struct{}
func (FixerManifestFilename) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {
PostProcessors []map[string]interface{} `mapstructure:"post-processors"`
}
// Decode the input into our structure, if we can
fmt.Println("Got 0")
var tpl template
if err := mapstructure.Decode(input, &tpl); err != nil {
fmt.Println("Got 1")
return nil, err
}
for _, pp := range tpl.PostProcessors {
ppTypeRaw, ok := pp["type"]
if !ok {
continue
}
ppType, ok := ppTypeRaw.(string)
if !ok {
continue
}
if ppType != "manifest" {
continue
}
filenameRaw, ok := pp["filename"]
if !ok {
continue
}
filename, ok := filenameRaw.(string)
if !ok {
continue
}
delete(pp, "filename")
pp["output"] = filename
}
input["post-processors"] = tpl.PostProcessors
return input, nil
}
func (FixerManifestFilename) Synopsis() string {
return `Updates "manifest" post-processor so any "filename" field is renamed to "output".`
}

View File

@ -0,0 +1,41 @@
package fix
import (
"reflect"
"testing"
)
func TestFixerManifestPPFilename_Impl(t *testing.T) {
var _ Fixer = new(FixerVagrantPPOverride)
}
func TestFixerManifestPPFilename_Fix(t *testing.T) {
var f FixerManifestFilename
input := map[string]interface{}{
"post-processors": []map[string]interface{}{
{
"type": "manifest",
"filename": "foo",
},
},
}
expected := map[string]interface{}{
"post-processors": []map[string]interface{}{
{
"type": "manifest",
"output": "foo",
},
},
}
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)
}
}