Fix nested pp case
This commit is contained in:
parent
70ca8486ba
commit
58c5f8262a
|
@ -1,7 +1,6 @@
|
||||||
package fix
|
package fix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,28 +11,40 @@ func (FixerManifestFilename) Fix(input map[string]interface{}) (map[string]inter
|
||||||
|
|
||||||
// Our template type we'll use for this fixer only
|
// Our template type we'll use for this fixer only
|
||||||
type template struct {
|
type template struct {
|
||||||
PostProcessors []map[string]interface{} `mapstructure:"post-processors"`
|
PostProcessors []interface{} `mapstructure:"post-processors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the input into our structure, if we can
|
// Decode the input into our structure, if we can
|
||||||
fmt.Println("Got 0")
|
|
||||||
var tpl template
|
var tpl template
|
||||||
if err := mapstructure.Decode(input, &tpl); err != nil {
|
if err := mapstructure.Decode(input, &tpl); err != nil {
|
||||||
fmt.Println("Got 1")
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, pp := range tpl.PostProcessors {
|
|
||||||
|
// Go through each post-processor and get out all the complex configs
|
||||||
|
pps := make([]map[string]interface{}, 0, len(tpl.PostProcessors))
|
||||||
|
for _, rawPP := range tpl.PostProcessors {
|
||||||
|
switch pp := rawPP.(type) {
|
||||||
|
case string:
|
||||||
|
case map[string]interface{}:
|
||||||
|
pps = append(pps, pp)
|
||||||
|
case []interface{}:
|
||||||
|
for _, innerRawPP := range pp {
|
||||||
|
if innerPP, ok := innerRawPP.(map[string]interface{}); ok {
|
||||||
|
pps = append(pps, innerPP)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pp := range pps {
|
||||||
ppTypeRaw, ok := pp["type"]
|
ppTypeRaw, ok := pp["type"]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ppType, ok := ppTypeRaw.(string)
|
if ppType, ok := ppTypeRaw.(string); !ok {
|
||||||
if !ok {
|
|
||||||
continue
|
continue
|
||||||
}
|
} else if ppType != "manifest" {
|
||||||
|
|
||||||
if ppType != "manifest" {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,15 +53,13 @@ func (FixerManifestFilename) Fix(input map[string]interface{}) (map[string]inter
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
filename, ok := filenameRaw.(string)
|
if filename, ok := filenameRaw.(string); ok {
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(pp, "filename")
|
delete(pp, "filename")
|
||||||
pp["output"] = filename
|
pp["output"] = filename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
input["post-processors"] = tpl.PostProcessors
|
input["post-processors"] = tpl.PostProcessors
|
||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,20 +13,32 @@ func TestFixerManifestPPFilename_Fix(t *testing.T) {
|
||||||
var f FixerManifestFilename
|
var f FixerManifestFilename
|
||||||
|
|
||||||
input := map[string]interface{}{
|
input := map[string]interface{}{
|
||||||
"post-processors": []map[string]interface{}{
|
"post-processors": []interface{}{
|
||||||
{
|
map[string]interface{}{
|
||||||
"type": "manifest",
|
"type": "manifest",
|
||||||
"filename": "foo",
|
"filename": "foo",
|
||||||
},
|
},
|
||||||
|
[]interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"type": "manifest",
|
||||||
|
"filename": "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]interface{}{
|
||||||
"post-processors": []map[string]interface{}{
|
"post-processors": []interface{}{
|
||||||
{
|
map[string]interface{}{
|
||||||
"type": "manifest",
|
"type": "manifest",
|
||||||
"output": "foo",
|
"output": "foo",
|
||||||
},
|
},
|
||||||
|
[]interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"type": "manifest",
|
||||||
|
"output": "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue