@@ -20,8 +20,10 @@ package ql
2020
2121import (
2222 "errors"
23- "github.com/stretchr/testify/assert "
23+ "strings "
2424 "testing"
25+
26+ "github.com/stretchr/testify/assert"
2527)
2628
2729func TestParseFunction (t * testing.T ) {
@@ -32,7 +34,14 @@ func TestParseFunction(t *testing.T) {
3234 {expr : "cidr_contains(net.dip)" , err : errors .New ("CIDR_CONTAINS function requires 2 argument(s) but 1 argument(s) given" )},
3335 {expr : "cidr_contains(net.dip, 12)" , err : errors .New ("argument #2 (cidr) in function CIDR_CONTAINS should be one of: string" )},
3436 {expr : "cidr_contains(net.dip, '172.17.12.4/24')" },
35- {expr : "md('172.17.12.4')" , err : errors .New ("md function is undefined. Did you mean one of CIDR_CONTAINS|MD5?" )},
37+ {expr : "md('172.17.12.4')" , err : errors .New ("md function is undefined" )},
38+ {expr : "concat('hello ', 'world')" },
39+ {expr : "concat('hello')" , err : errors .New ("CONCAT function requires 2 argument(s) but 1 argument(s) given" )},
40+ {expr : "ltrim('hello world', 'hello ')" },
41+ {expr : "replace('hello world', 'hello', 'hell', 'world')" , err : errors .New ("old/new replacements mismatch" )},
42+ {expr : "replace('hello world', 'hello', 'hell', 'world', 'war', 'hello')" , err : errors .New ("old/new replacements mismatch" )},
43+ {expr : "replace('hello world', 'hello', 'hell', 'world', 'war', 'hello', 'warld', 'old', 'new', 'one')" , err : errors .New ("old/new replacements mismatch" )},
44+ {expr : "indexof('hello', 'h', 'frst')" , err : errors .New ("frst is not a valid index search order" )},
3645 }
3746
3847 for i , tt := range tests {
@@ -41,7 +50,7 @@ func TestParseFunction(t *testing.T) {
4150 if err == nil && tt .err != nil {
4251 t .Errorf ("%d. exp=%s expected error=%v" , i , tt .expr , tt .err )
4352 } else if err != nil {
44- assert .EqualError (t , err , tt .err .Error ())
53+ assert .True (t , strings . Contains ( err . Error () , tt .err .Error () ))
4554 } else if err != nil && tt .err == nil {
4655 t .Errorf ("%d. exp=%s got error=%v" , i , tt .expr , err )
4756 }
0 commit comments