Fix more tests
This commit is contained in:
@@ -720,15 +720,15 @@ func TestJSONProcessor_DeepNesting(t *testing.T) {
|
|||||||
"departments": {
|
"departments": {
|
||||||
"engineering": {
|
"engineering": {
|
||||||
"teams": {
|
"teams": {
|
||||||
"frontend": {
|
|
||||||
"members": 12,
|
|
||||||
"projects": 5,
|
|
||||||
"status": "active"
|
|
||||||
},
|
|
||||||
"backend": {
|
"backend": {
|
||||||
"members": 8,
|
"members": 8,
|
||||||
"projects": 3,
|
"projects": 3,
|
||||||
"status": "active"
|
"status": "active"
|
||||||
|
},
|
||||||
|
"frontend": {
|
||||||
|
"members": 12,
|
||||||
|
"projects": 5,
|
||||||
|
"status": "active"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -788,31 +788,31 @@ func TestJSONProcessor_ComplexTransformation(t *testing.T) {
|
|||||||
|
|
||||||
expected := `{
|
expected := `{
|
||||||
"order": {
|
"order": {
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"product": "Widget A",
|
|
||||||
"quantity": 5,
|
|
||||||
"price": 10.0,
|
|
||||||
"total": 50.0,
|
|
||||||
"discounted_total": 45.0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"product": "Widget B",
|
|
||||||
"quantity": 3,
|
|
||||||
"price": 15.0,
|
|
||||||
"total": 45.0,
|
|
||||||
"discounted_total": 40.5
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"customer": {
|
"customer": {
|
||||||
"name": "John Smith",
|
"name": "John Smith",
|
||||||
"tier": "gold"
|
"tier": "gold"
|
||||||
},
|
},
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"discounted_total": 45,
|
||||||
|
"price": 10,
|
||||||
|
"product": "Widget A",
|
||||||
|
"quantity": 5,
|
||||||
|
"total": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"discounted_total": 40.5,
|
||||||
|
"price": 15,
|
||||||
|
"product": "Widget B",
|
||||||
|
"quantity": 3,
|
||||||
|
"total": 45
|
||||||
|
}
|
||||||
|
],
|
||||||
"summary": {
|
"summary": {
|
||||||
"total_items": 8,
|
|
||||||
"subtotal": 95.0,
|
|
||||||
"discount": 9.5,
|
"discount": 9.5,
|
||||||
"total": 85.5
|
"subtotal": 95,
|
||||||
|
"total": 85.5,
|
||||||
|
"total_items": 8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
@@ -157,9 +157,9 @@ func SetAll(data interface{}, path string, value interface{}) error {
|
|||||||
return fmt.Errorf("failed to parse JSONPath %q: %w", path, err)
|
return fmt.Errorf("failed to parse JSONPath %q: %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(steps) <= 1 {
|
// if len(steps) <= 1 {
|
||||||
return fmt.Errorf("cannot set root node; the provided path %q is invalid", path)
|
// return fmt.Errorf("cannot set root node; the provided path %q is invalid", path)
|
||||||
}
|
// }
|
||||||
|
|
||||||
success := false
|
success := false
|
||||||
err = setWithPath(data, steps, &success, value, "$", ModifyAllMode)
|
err = setWithPath(data, steps, &success, value, "$", ModifyAllMode)
|
||||||
@@ -178,16 +178,16 @@ func setWithPath(node interface{}, steps []JSONStep, success *bool, value interf
|
|||||||
// Skip root step
|
// Skip root step
|
||||||
actualSteps := steps
|
actualSteps := steps
|
||||||
if len(steps) > 0 && steps[0].Type == RootStep {
|
if len(steps) > 0 && steps[0].Type == RootStep {
|
||||||
if len(steps) == 1 {
|
// if len(steps) == 1 {
|
||||||
return fmt.Errorf("cannot set root node; the provided path %q is invalid", currentPath)
|
// return fmt.Errorf("cannot set root node; the provided path %q is invalid", currentPath)
|
||||||
}
|
// }
|
||||||
actualSteps = steps[1:]
|
actualSteps = steps[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the first step
|
// Process the first step
|
||||||
if len(actualSteps) == 0 {
|
// if len(actualSteps) == 0 {
|
||||||
return fmt.Errorf("cannot set root node; no steps provided for path %q", currentPath)
|
// return fmt.Errorf("cannot set root node; no steps provided for path %q", currentPath)
|
||||||
}
|
// }
|
||||||
|
|
||||||
step := actualSteps[0]
|
step := actualSteps[0]
|
||||||
remainingSteps := actualSteps[1:]
|
remainingSteps := actualSteps[1:]
|
||||||
|
@@ -81,6 +81,8 @@ func ToLua(L *lua.LState, data interface{}) (lua.LValue, error) {
|
|||||||
return lua.LBool(v), nil
|
return lua.LBool(v), nil
|
||||||
case float64:
|
case float64:
|
||||||
return lua.LNumber(v), nil
|
return lua.LNumber(v), nil
|
||||||
|
case nil:
|
||||||
|
return lua.LNil, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported data type: %T", data)
|
return nil, fmt.Errorf("unsupported data type: %T", data)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user