MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestYAMLHelper

Function TestYAMLHelper

policy/yaml_test.go:23–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestYAMLHelper(t *testing.T) {
24 helper := YAMLHelper{}
25 tests := []struct {
26 name string
27 yaml string
28 want func(*testing.T, *yaml.Node)
29 }{
30 {
31 name: "list",
32 yaml: `
33- first
34- second
35- third`,
36 want: func(t *testing.T, node *yaml.Node) {
37 if !helper.IsList(node) {
38 t.Fatalf("IsList(node) returned false, want true")
39 }
40
41 helper.RangeList(node, func(i int, val *yaml.Node) bool {
42 switch i {
43 case 0:
44 if !helper.IsString(val) || val.Value != "first" {
45 t.Errorf("val[%d] = %q, want %q", i, val.Value, "first")
46 }
47 case 1:
48 if !helper.IsString(val) || val.Value != "second" {
49 t.Errorf("val[%d] = %q, want %q", i, val.Value, "second")
50 }
51 case 2:
52 if !helper.IsString(val) || val.Value != "third" {
53 t.Errorf("val[%d] = %q, want %q", i, val.Value, "third")
54 }
55 }
56 return true
57 })
58 },
59 },
60 {
61 name: "map",
62 yaml: `
63first: 1
64second: 2
65third: 3`,
66 want: func(t *testing.T, node *yaml.Node) {
67 if !helper.IsMap(node) {
68 t.Fatalf("IsMap(node) returned false, want true")
69 }
70 helper.RangeMap(node, func(key *yaml.Node, val *yaml.Node) bool {
71 if key.Value == "first" && helper.IsInteger(val) && val.Value != "1" {
72 t.Errorf("val[%q] = %q, want %q", key.Value, val.Value, "1")
73 }
74 if key.Value == "second" && helper.IsInteger(val) && val.Value != "2" {
75 t.Errorf("val[%q] = %q, want %q", key.Value, val.Value, "2")
76 }
77 if key.Value == "third" && helper.IsInteger(val) && val.Value != "3" {
78 t.Errorf("val[%q] = %q, want %q", key.Value, val.Value, "3")
79 }
80 return true

Callers

nothing calls this directly

Calls 11

IsListMethod · 0.95
RangeListMethod · 0.95
IsStringMethod · 0.95
IsMapMethod · 0.95
RangeMapMethod · 0.95
IsIntegerMethod · 0.95
IsNullMethod · 0.95
IsNumberMethod · 0.95
IsDoubleMethod · 0.95
IsBoolMethod · 0.95
IsTimestampMethod · 0.95

Tested by

no test coverage detected