MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestXMLGetNodeValue

Function TestXMLGetNodeValue

pkg/exprhelpers/xml_test.go:71–118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestXMLGetNodeValue(t *testing.T) {
72 if err := Init(nil); err != nil {
73 t.Fatal(err)
74 }
75
76 tests := []struct {
77 name string
78 xmlString string
79 path string
80 expectResult string
81 }{
82 {
83 name: "XMLGetNodeValue",
84 xmlString: `<root><child>foobar</child></root>`,
85 path: "/root/child",
86 expectResult: "foobar",
87 },
88 {
89 name: "Non existing path for XMLGetNodeValue",
90 xmlString: `<root><child>foobar</child></root>`,
91 path: "/foo/bar",
92 expectResult: "",
93 },
94 {
95 name: "Invalid XML for XMLGetNodeValue",
96 xmlString: `<root><`,
97 path: "/foo/bar",
98 expectResult: "",
99 },
100 {
101 name: "Invalid path for XMLGetNodeValue",
102 xmlString: `<root><child>foobar</child></root>`,
103 path: "/foo/bar[@",
104 expectResult: "",
105 },
106 }
107
108 for _, test := range tests {
109 result, _ := XMLGetNodeValue(test.xmlString, test.path)
110
111 isOk := assert.Equal(t, test.expectResult, result)
112 if !isOk {
113 t.Fatalf("test '%s' failed", test.name)
114 }
115
116 log.Printf("test '%s' : OK", test.name)
117 }
118}

Callers

nothing calls this directly

Calls 2

InitFunction · 0.85
XMLGetNodeValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…