I have run some test below TEST1,I want the error happened( variables have no cpu1 struct),but It just return false
Also I do TEST2 like below , just change field 'cpu1' to 'request1' , It works (it return err , can not fetch cpu from nil )
again I do TEST3 like below , just change '==' to '>' , It works (it return err invalid operation: < float64 (1:27))
any ideas?
-
TEST1
`{
name: "number expr",
matchExpr: "test.hello.request.cpu1 == 0.15",
variables: map[string]interface{}{
"test": map[string]interface{}{
"hello": map[string]interface{}{
"request": map[string]interface{}{
"cpu": 0.2,
},
},
},
},
},`
-
TEST2
`{
name: "number expr",
matchExpr: "test.hello.request1.cpu == 0.15",
variables: map[string]interface{}{
"test": map[string]interface{}{
"hello": map[string]interface{}{
"request": map[string]interface{}{
"cpu": 0.2,
},
},
},
},
},`
-
TEST3
`{
name: "number expr",
matchExpr: "test.hello.request.cpu1 < 0.15",
variables: map[string]interface{}{
"test": map[string]interface{}{
"hello": map[string]interface{}{
"request": map[string]interface{}{
"cpu": 0.2,
},
},
},
},
},`
-
Eval expression code
func MatchExprEval(matchExpr string, variables map[string]interface{}) (bool, error) {
program, err := expr.Compile(matchExpr, expr.Env(variables), expr.AsBool())
if err != nil {
return false, err
}
output, err := expr.Run(program, variables)
if err != nil {
return false, err
}
var outputBool, ok bool
if outputBool, ok = output.(bool); !ok {
return false, fmt.Errorf("not a bool result")
}
return outputBool, nil
}
I have run some test below TEST1,I want the error happened( variables have no cpu1 struct),but It just return false
Also I do TEST2 like below , just change field 'cpu1' to 'request1' , It works (it return err , can not fetch cpu from nil )
again I do TEST3 like below , just change '==' to '>' , It works (it return err invalid operation: < float64 (1:27))
any ideas?
TEST1
TEST2
TEST3
Eval expression code