E2e test for run with json

This commit is contained in:
Phani Teja Marupaka
2020-06-08 20:51:01 -07:00
parent b39c522cc1
commit e994b3b566
9 changed files with 76 additions and 122 deletions

View File

@@ -722,33 +722,24 @@ func (rn *RNode) UnmarshalJSON(b []byte) error {
return nil
}
// ConvertJSONToYAMLNode parses input json string and returns equivalent yaml node
func ConvertJSONToYAMLNode(jsonStr string) (*RNode, error) {
yml, err := ConvertJSONToYAMLString(jsonStr)
// ConvertJSONToYamlNode parses input json string and returns equivalent yaml node
func ConvertJSONToYamlNode(jsonStr string) (*RNode, error) {
var body map[string]interface{}
err := json.Unmarshal([]byte(jsonStr), &body)
if err != nil {
return nil, err
}
node, err := Parse(yml)
yml, err := yaml.Marshal(body)
if err != nil {
return nil, err
}
node, err := Parse(string(yml))
if err != nil {
return nil, err
}
return node, nil
}
// ConvertJSONToYAMLString parses input json string and returns equivalent yaml string
func ConvertJSONToYAMLString(jsonStr string) (string, error) {
var body map[string]interface{}
err := json.Unmarshal([]byte(jsonStr), &body)
if err != nil {
return "", err
}
yml, err := yaml.Marshal(body)
if err != nil {
return "", err
}
return string(yml), nil
}
// checkKey returns true if all elems have the key
func checkKey(key string, elems []*Node) bool {
count := 0