-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathxmlpath_test.go
66 lines (58 loc) · 1.64 KB
/
xmlpath_test.go
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
61
62
63
64
65
66
package forest
import (
"net/http"
"testing"
)
func TestXMLPath(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/xmldoc"))
v := XMLPath(t, r, "/Root/Child/Value")
if v != "1" {
t.Errorf("got %v but want 1", v)
}
}
// TODO
func TestXMLPathAllChilds(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/xmldoc"))
m := new(mockedT)
kids := XMLPath(m, r, "Root//Child")
t.Logf("%#v", kids)
}
func TestXMLPathWrongPath(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/xmldoc"))
m := new(mockedT)
XMLPath(m, r, "/Root/Child/ValueX")
if m.logMessage != "XMLPath: no value for path: /Root/Child/ValueX" {
t.Errorf("expected other message than:[%s]", m.errorMessage)
}
}
func TestXMLPathInvalidPath(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/xmldoc"))
m := new(mockedT)
XMLPath(m, r, "/{Root}")
if m.logMessage != "XMLPath: invalid xpath expression:compiling xml path \"/{Root}\":1: missing name" {
t.Errorf("expected other message than:[%s]", m.errorMessage)
}
}
func TestXMLPathNoResponse(t *testing.T) {
m := new(mockedT)
XMLPath(m, nil, "/Root")
if m.logMessage != "XMLPath: no response to read body from" {
t.Errorf("expected other message than:[%s]", m.fatalMessage)
}
}
func TestXMLPathNoBody(t *testing.T) {
m := new(mockedT)
r := new(http.Response)
XMLPath(m, r, "/Root")
if m.logMessage != "XMLPath: no response body to read" {
t.Errorf("expected other message than:[%s]", m.fatalMessage)
}
}
func TestXMLPathNoDocument(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/404"))
m := new(mockedT)
XMLPath(m, r, "/Root")
if m.logMessage != "XMLPath: no value for path: /Root" {
t.Errorf("expected other message than:[%s]", m.errorMessage)
}
}