test(transformer): add end-to-end coverage and fix silent error wrapping (#3873)

Signed-off-by: jingze <daijingze.djz@alibaba-inc.com>
This commit is contained in:
Jingze
2026-06-15 20:29:51 +08:00
committed by GitHub
parent bf0b1e96c5
commit 547b7bf45a
4 changed files with 1037 additions and 16 deletions

View File

@@ -709,8 +709,7 @@ func newTransformRule(rules []gjson.Result) (res []TransformRule, err error) {
var tRule TransformRule
tRule.operate = strings.ToLower(r.Get("operate").String())
if !isValidOperation(tRule.operate) {
errors.Wrapf(err, "invalid operate type %q", tRule.operate)
return
return nil, errors.Errorf("invalid operate type %q", tRule.operate)
}
if tRule.operate == "map" {
@@ -720,8 +719,7 @@ func newTransformRule(rules []gjson.Result) (res []TransformRule, err error) {
} else {
tRule.mapSource = mapSourceInJson.String()
if !isValidMapSource(tRule.mapSource) {
errors.Wrapf(err, "invalid map source %q", tRule.mapSource)
return
return nil, errors.Errorf("invalid map source %q", tRule.mapSource)
}
}
}
@@ -738,8 +736,7 @@ func newTransformRule(rules []gjson.Result) (res []TransformRule, err error) {
valueType = "string"
}
if !isValidJsonType(valueType) {
errors.Wrapf(err, "invalid body params type %q", valueType)
return
return nil, errors.Errorf("invalid body params type %q", valueType)
}
tRule.body = append(tRule.body, constructParam(b, tRule.operate, valueType))
}
@@ -1110,7 +1107,7 @@ func (h jsonHandler) handle(host, path string, oriData []byte, mapSourceData map
}
convertedAppendValue, err := convertByJsonType(valueType, appendValue)
if err != nil {
return nil, errors.Wrapf(err, errAppend.Error())
return nil, errors.Wrap(err, errAppend.Error())
}
oldValue := gjson.GetBytes(data, key)
if !oldValue.Exists() {
@@ -1332,7 +1329,7 @@ func newKvtGroup(rules []TransformRule, typ string) (g []kvtOperation, isChange
case "append":
kvtOp.kvtOpType = AppendK
default:
return nil, false, false, errors.Wrap(err, "invalid operation type")
return nil, false, false, errors.Errorf("invalid operation type %q", r.operate)
}
for _, p := range prams {
switch r.operate {