add fixer for manifest filename->output
This commit is contained in:
parent
b29d0b4378
commit
e3acd19cb7
|
@ -29,6 +29,7 @@ func init() {
|
|||
"parallels-headless": new(FixerParallelsHeadless),
|
||||
"parallels-deprecations": new(FixerParallelsDeprecations),
|
||||
"sshkeypath": new(FixerSSHKeyPath),
|
||||
"manifest-filename": new(FixerManifestFilename),
|
||||
}
|
||||
|
||||
FixerOrder = []string{
|
||||
|
@ -41,5 +42,6 @@ func init() {
|
|||
"parallels-headless",
|
||||
"parallels-deprecations",
|
||||
"sshkeypath",
|
||||
"manifest-filename",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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".`
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue