MCPcopy Create free account
hub / github.com/pydio/cells / TestBleveQueryToJSONPathData

Function TestBleveQueryToJSONPathData

common/storage/boltdb/query_test.go:76–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestBleveQueryToJSONPathData(t *testing.T) {
77
78 Convey("Test JsonPath - Actual Data", t, func() {
79 var jsonData map[string]interface{}
80 So(json.Unmarshal([]byte(activities), &jsonData), ShouldBeNil)
81
82 {
83 eval, jpath, er := BleveQueryToJSONPath("id:\"/activity-13843\"", "$.items", false, id, true)
84 So(er, ShouldBeNil)
85 So(eval, ShouldNotBeNil)
86 So(jpath, ShouldEqual, "length($.items[?(@.id==\"/activity-13843\")])")
87 s, er := eval.EvalInt(context.Background(), jsonData)
88 So(er, ShouldBeNil)
89 So(s, ShouldEqual, 1)
90 }
91
92 {
93 eval, jpath, er := BleveQueryToJSONPath("object.id:\"c6592312-d7c1-45fe-a283-93eee6e53e44\"", "$.items", false, id, true)
94 So(er, ShouldBeNil)
95 So(eval, ShouldNotBeNil)
96 So(jpath, ShouldEqual, "length($.items[?(@.object.id==\"c6592312-d7c1-45fe-a283-93eee6e53e44\")])")
97 s, er := eval.EvalInt(context.Background(), jsonData)
98 So(er, ShouldBeNil)
99 So(s, ShouldEqual, 1)
100 }
101
102 {
103 eval, _, er := BleveQueryToJSONPath("object.name:\"accounting-2019*\"", "$.items", false, id, true)
104 So(er, ShouldBeNil)
105 So(eval, ShouldNotBeNil)
106 s, er := eval.EvalInt(context.Background(), jsonData)
107 So(er, ShouldBeNil)
108 So(s, ShouldEqual, 1)
109 }
110
111 {
112 eval, _, er := BleveQueryToJSONPath("id:\"*activity*\"", "$.items", false, id, true)
113 So(er, ShouldBeNil)
114 So(eval, ShouldNotBeNil)
115 s, er := eval.EvalInt(context.Background(), jsonData)
116 So(er, ShouldBeNil)
117 So(s, ShouldEqual, 2)
118 }
119
120 {
121 eval, _, er := BleveQueryToJSONPath("id:\"/activity*\"", "$.items", false, id, false)
122 So(er, ShouldBeNil)
123 So(eval, ShouldNotBeNil)
124 res, er := eval(context.Background(), jsonData)
125 So(er, ShouldBeNil)
126 results := res.([]interface{})
127 So(results, ShouldHaveLength, 2)
128 }
129
130 {
131 eval, _, er := BleveQueryToJSONPath("id:\"/activity-13843\" id:\"/activity-13837\"", "$.items", false, id, true)
132 So(er, ShouldBeNil)
133 So(eval, ShouldNotBeNil)

Callers

nothing calls this directly

Calls 2

BleveQueryToJSONPathFunction · 0.85
UnmarshalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…