-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_PaesslerAGJSONPath.go
More file actions
52 lines (46 loc) · 895 Bytes
/
exec_PaesslerAGJSONPath.go
File metadata and controls
52 lines (46 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package jsonpath_benchmark
import (
"context"
"encoding/json"
"testing"
"github.com/PaesslerAG/jsonpath"
)
func Execute_PaesslerAG_JSONPath(b *testing.B, srcJSON string, jsonPath string, expect *BenchExpect) {
var src any
if err := json.Unmarshal([]byte(srcJSON), &src); err != nil {
b.Skip(err)
return
}
eval, err := jsonpath.New(jsonPath)
if err != nil {
b.Skip(err)
return
}
value, err := eval(context.Background(), src)
if err != nil {
b.Skip(err)
return
}
result, ok := value.([]any)
if ok {
if len(result) == 1 {
_result, ok := result[0].([]any)
if ok {
result = _result
}
}
} else {
result = []any{value}
}
if ok, reason := expect.validateSlice(result); !ok {
if reason != "" {
b.Skipf("precheck failed: %s", reason)
} else {
b.Skip("precheck failed")
}
return
}
for b.Loop() {
eval(context.Background(), src)
}
}