-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_test.go
More file actions
82 lines (73 loc) · 1.94 KB
/
error_test.go
File metadata and controls
82 lines (73 loc) · 1.94 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package xmpp
import (
"encoding/xml"
"testing"
)
const error1 = "<stream:error><system-shutdown xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xmlns='urn:ietf:params:xml:ns:xmpp-streams' xml:lang='en'>description</text></stream:error>"
const error2 = "<stream:error><system-shutdown xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xmlns='urn:ietf:params:xml:ns:xmpp-streams' xml:lang='en'>description</text><extra/></stream:error>"
const error3 = "<stream:error><system-shutdown xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><extra/></stream:error>"
func TestError_UnmarshalXML(t *testing.T) {
// condition + text
var err1 = &Error{}
if e := xml.Unmarshal([]byte(error1), err1); e != nil {
t.Error(e)
}
if err1.Condition != "system-shutdown" {
t.Error("invalid condition")
}
if err1.Text != "description" {
t.Error("invalid text")
}
if err1.Extra != nil {
t.Error("extra should be nil")
}
// condition + text + extra
var err2 = &Error{}
if e := xml.Unmarshal([]byte(error2), err2); e != nil {
t.Error(e)
}
if err2.Condition != "system-shutdown" {
t.Error("invalid condition")
}
if err2.Text != "description" {
t.Error("invalid text")
}
if err2.Extra == nil {
t.Error("missing extra")
}
// condition + extra
var err3 = &Error{}
if e := xml.Unmarshal([]byte(error3), err3); e != nil {
t.Error(e)
}
if err3.Condition != "system-shutdown" {
t.Error("invalid condition")
}
if err3.Text != "" {
t.Error("invalid text:", err1.Text)
}
if err3.Extra == nil {
t.Error("missing extra")
}
}
func TestError_MarshalXML(t *testing.T) {
orig := &Error{
Condition: "system-shutdown",
Text: "description",
Extra: nil,
}
bytes, err := xml.Marshal(orig)
if err != nil {
t.Error(err)
}
clone := &Error{}
if err := xml.Unmarshal(bytes, clone); err != nil {
t.Error(err)
}
if clone.Condition != orig.Condition {
t.Error("condition mismatch")
}
if clone.Text != orig.Text {
t.Error("text mismatch")
}
}