8
8
"github.com/stretchr/testify/assert"
9
9
)
10
10
11
- const inputCheckExists = `{
11
+ const inputExists = `{
12
12
"store": {
13
13
"book": [
14
14
{
@@ -35,7 +35,7 @@ const inputCheckExists = `{
35
35
36
36
func TestFnCheckExists (t * testing.T ) {
37
37
var inputJSON interface {}
38
- err := json .Unmarshal ([]byte (inputCheckExists ), & inputJSON )
38
+ err := json .Unmarshal ([]byte (inputExists ), & inputJSON )
39
39
assert .Nil (t , err )
40
40
41
41
f := & fnExists {}
@@ -44,35 +44,46 @@ func TestFnCheckExists(t *testing.T) {
44
44
assert .Equal (t , true , v )
45
45
}
46
46
47
- func TestFnCheckExistsLoop (t * testing.T ) {
47
+ func TestFnExistsLoop (t * testing.T ) {
48
48
var inputJSON interface {}
49
- err := json .Unmarshal ([]byte (inputCheckExists ), & inputJSON )
49
+ err := json .Unmarshal ([]byte (inputExists ), & inputJSON )
50
50
assert .Nil (t , err )
51
51
52
52
f := & fnExists {}
53
53
v , err := function .Eval (f , inputJSON , "$loop.store.book[?(@.price == 22.99)].price[0]" )
54
- assert .NotNil (t , err )
54
+ assert .Nil (t , err )
55
55
assert .Equal (t , false , v )
56
56
}
57
57
58
- func TestFnCheckExistsNegative (t * testing.T ) {
58
+ func TestFnExistsNegative (t * testing.T ) {
59
59
var inputJSON interface {}
60
- err := json .Unmarshal ([]byte (inputCheckExists ), & inputJSON )
60
+ err := json .Unmarshal ([]byte (inputExists ), & inputJSON )
61
61
assert .Nil (t , err )
62
62
63
63
f := & fnExists {}
64
64
v , err := function .Eval (f , inputJSON , "$.store.abc" )
65
- assert .NotNil (t , err )
65
+ assert .Nil (t , err )
66
66
assert .Equal (t , false , v )
67
67
}
68
68
69
- func TestFnCheckExistsEmpty (t * testing.T ) {
69
+ func TestFnExistsEmpty (t * testing.T ) {
70
70
var inputJSON interface {}
71
- err := json .Unmarshal ([]byte (inputCheckExists ), & inputJSON )
71
+ err := json .Unmarshal ([]byte (inputExists ), & inputJSON )
72
72
assert .Nil (t , err )
73
73
74
74
f := & fnExists {}
75
75
v , err := function .Eval (f , inputJSON , "$.emptyString" )
76
76
assert .Nil (t , err )
77
77
assert .Equal (t , true , v )
78
78
}
79
+
80
+ func TestFnExistsWithoutJSONPath (t * testing.T ) {
81
+ var inputJSON interface {}
82
+ err := json .Unmarshal ([]byte (inputExists ), & inputJSON )
83
+ assert .Nil (t , err )
84
+
85
+ f := & fnExists {}
86
+ v , err := function .Eval (f , inputJSON , "expensive" )
87
+ assert .Nil (t , err )
88
+ assert .Equal (t , true , v )
89
+ }
0 commit comments