-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_Vmware-labsYaml-jsonpath.go
More file actions
60 lines (52 loc) · 1.05 KB
/
exec_Vmware-labsYaml-jsonpath.go
File metadata and controls
60 lines (52 loc) · 1.05 KB
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
53
54
55
56
57
58
59
60
package jsonpath_benchmark
import (
"encoding/json"
"testing"
"github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath"
"gopkg.in/yaml.v3"
)
func Execute_vmware_labs_YAML_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
}
yamlData, err := yaml.Marshal(src)
if err != nil {
b.Skip(err)
return
}
var srcYamlNode yaml.Node
if err := yaml.Unmarshal(yamlData, &srcYamlNode); err != nil {
b.Skip(err)
return
}
path, err := yamlpath.NewPath(jsonPath)
if err != nil {
b.Skip(err)
return
}
nodes, err := path.Find(&srcYamlNode)
if err != nil {
b.Skip(err)
return
}
var result []any
for _, node := range nodes {
var v any
if err := node.Decode(&v); err == nil {
result = append(result, v)
}
}
if ok, reason := expect.validateSlice(result); !ok {
if reason != "" {
b.Skipf("precheck failed: %s", reason)
} else {
b.Skip("precheck failed")
}
return
}
for b.Loop() {
path.Find(&srcYamlNode)
}
}