|
@@ -351,30 +351,6 @@ func (mt *MQLTest) RunMQLTryOnce(t *testing.T, ctx context.Context,
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func matchvalue(matcher any, matchingvalue any) (bool, string) {
|
|
|
|
|
- switch m := matcher.(type) {
|
|
|
|
|
- case *regexp.Regexp:
|
|
|
|
|
- switch v := matchingvalue.(type) {
|
|
|
|
|
- case string:
|
|
|
|
|
- return m.MatchString(v), v
|
|
|
|
|
- default:
|
|
|
|
|
- sv := fmt.Sprintf("%#v", matchingvalue)
|
|
|
|
|
- return m.MatchString(sv), sv
|
|
|
|
|
- }
|
|
|
|
|
- case string:
|
|
|
|
|
- sv := ""
|
|
|
|
|
- switch matchingvalue.(type) {
|
|
|
|
|
- case int, uint, int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64, bool:
|
|
|
|
|
- sv = fmt.Sprintf("%v", matchingvalue)
|
|
|
|
|
- default:
|
|
|
|
|
- sv = fmt.Sprintf("%#v", matchingvalue)
|
|
|
|
|
- }
|
|
|
|
|
- return sv == m, sv
|
|
|
|
|
- default:
|
|
|
|
|
- panic("未定义的匹配类型")
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption *OnErrorOption, rtn *odb.Result, actions []*Action, mql string) (seriouserror bool, err error) {
|
|
func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption *OnErrorOption, rtn *odb.Result, actions []*Action, mql string) (seriouserror bool, err error) {
|
|
|
if len(actions) > 0 {
|
|
if len(actions) > 0 {
|
|
|
if rtn == nil {
|
|
if rtn == nil {
|
|
@@ -553,6 +529,11 @@ func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption
|
|
|
}
|
|
}
|
|
|
m = r
|
|
m = r
|
|
|
}
|
|
}
|
|
|
|
|
+ case *Action:
|
|
|
|
|
+ switch arg.Name {
|
|
|
|
|
+ case "<FUZZY>":
|
|
|
|
|
+ m = arg
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if m == nil {
|
|
if m == nil {
|
|
|
m = fmt.Sprintf("%#v", args[i+1])
|
|
m = fmt.Sprintf("%#v", args[i+1])
|
|
@@ -573,88 +554,7 @@ func (mt *MQLTest) doFollowThroughActions(t *testing.T, testname string, toption
|
|
|
seriouserror = true
|
|
seriouserror = true
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- x := 0
|
|
|
|
|
- var matchingvalues [][]any
|
|
|
|
|
- var matchingvalue any
|
|
|
|
|
- for _, dat := range rtn.Data {
|
|
|
|
|
- matchingvalues = append(matchingvalues, []any{})
|
|
|
|
|
- m := false
|
|
|
|
|
- sv := ""
|
|
|
|
|
- match := true
|
|
|
|
|
- for i, k := range ks {
|
|
|
|
|
- matchingvalue = dat[k]
|
|
|
|
|
- m, sv = matchvalue(ms[i], matchingvalue)
|
|
|
|
|
- if !m {
|
|
|
|
|
- ks := strings.Split(k, ".")
|
|
|
|
|
- if len(ks) <= 1 {
|
|
|
|
|
- match = false
|
|
|
|
|
- break
|
|
|
|
|
- } else {
|
|
|
|
|
- k := ""
|
|
|
|
|
- for i := 0; match && i < len(ks); i++ {
|
|
|
|
|
- if matchingvalue == nil {
|
|
|
|
|
- if k != "" {
|
|
|
|
|
- k += "."
|
|
|
|
|
- }
|
|
|
|
|
- k += ks[i]
|
|
|
|
|
- matchingvalue = dat[k]
|
|
|
|
|
- if matchingvalue == nil && ks[i] == "len" {
|
|
|
|
|
- matchingvalue = 0
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- switch mv := matchingvalue.(type) {
|
|
|
|
|
- case map[string]interface{}:
|
|
|
|
|
- matchingvalue = mv[ks[i]]
|
|
|
|
|
- if matchingvalue == nil && ks[i] == "len" {
|
|
|
|
|
- matchingvalue = len(mv)
|
|
|
|
|
- }
|
|
|
|
|
- case []interface{}:
|
|
|
|
|
- if ks[i] == "len" {
|
|
|
|
|
- matchingvalue = len(mv)
|
|
|
|
|
- } else {
|
|
|
|
|
- n, e := cast.ToIntE(ks[i])
|
|
|
|
|
- if e != nil {
|
|
|
|
|
- match = false
|
|
|
|
|
- break
|
|
|
|
|
- }
|
|
|
|
|
- matchingvalue = mv[n]
|
|
|
|
|
- }
|
|
|
|
|
- case string:
|
|
|
|
|
- if ks[i] == "len" {
|
|
|
|
|
- matchingvalue = len(mv)
|
|
|
|
|
- } else {
|
|
|
|
|
- n, e := cast.ToIntE(ks[i])
|
|
|
|
|
- if e != nil {
|
|
|
|
|
- match = false
|
|
|
|
|
- break
|
|
|
|
|
- }
|
|
|
|
|
- matchingvalue = mv[n]
|
|
|
|
|
- }
|
|
|
|
|
- default:
|
|
|
|
|
- if ks[i] == "len" {
|
|
|
|
|
- matchingvalue = 0
|
|
|
|
|
- } else {
|
|
|
|
|
- matchingvalue = nil
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- m, sv = matchvalue(ms[i], matchingvalue)
|
|
|
|
|
- if !m {
|
|
|
|
|
- match = false
|
|
|
|
|
- break
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- matchingvalues[len(matchingvalues)-1] = append(matchingvalues[len(matchingvalues)-1], sv)
|
|
|
|
|
- }
|
|
|
|
|
- if match {
|
|
|
|
|
- x++
|
|
|
|
|
- matchingvalues = matchingvalues[:len(matchingvalues)-1]
|
|
|
|
|
- } else {
|
|
|
|
|
- matchingvalues[len(matchingvalues)-1] = append(matchingvalues[len(matchingvalues)-1], sv)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ x, matchingvalues := MatchValues(rtn, ks, ms)
|
|
|
if n != x {
|
|
if n != x {
|
|
|
if len(rtn.Data) == 0 {
|
|
if len(rtn.Data) == 0 {
|
|
|
err = merrs.New("%s", fmt.Sprint("没有找到记录与期望值(", n, ")不符"))
|
|
err = merrs.New("%s", fmt.Sprint("没有找到记录与期望值(", n, ")不符"))
|