-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathpresence_test.go
63 lines (52 loc) · 1.79 KB
/
presence_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
package stanza_test
import (
"encoding/xml"
"testing"
"github.com/google/go-cmp/cmp"
"gosrc.io/xmpp/stanza"
)
func TestGeneratePresence(t *testing.T) {
presence := stanza.NewPresence(stanza.Attrs{From: "admin@localhost", To: "test@localhost", Id: "1"})
presence.Show = stanza.PresenceShowChat
data, err := xml.Marshal(presence)
if err != nil {
t.Errorf("cannot marshal xml structure")
}
var parsedPresence stanza.Presence
if err = xml.Unmarshal(data, &parsedPresence); err != nil {
t.Errorf("Unmarshal(%s) returned error", data)
}
if !xmlEqual(parsedPresence, presence) {
t.Errorf("non matching items\n%s", cmp.Diff(parsedPresence, presence))
}
}
func TestPresenceSubElt(t *testing.T) {
// Test structure to ensure that show, status and priority are correctly defined as presence
// package sub-elements
type pres struct {
Show stanza.PresenceShow `xml:"show"`
Status string `xml:"status"`
Priority int8 `xml:"priority"`
}
presence := stanza.NewPresence(stanza.Attrs{From: "admin@localhost", To: "test@localhost", Id: "1"})
presence.Show = stanza.PresenceShowXA
presence.Status = "Coding"
presence.Priority = 10
data, err := xml.Marshal(presence)
if err != nil {
t.Errorf("cannot marshal xml structure")
}
var parsedPresence pres
if err = xml.Unmarshal(data, &parsedPresence); err != nil {
t.Errorf("Unmarshal(%s) returned error", data)
}
if parsedPresence.Show != presence.Show {
t.Errorf("cannot read 'show' as presence subelement (%s)", parsedPresence.Show)
}
if parsedPresence.Status != presence.Status {
t.Errorf("cannot read 'status' as presence subelement (%s)", parsedPresence.Status)
}
if parsedPresence.Priority != presence.Priority {
t.Errorf("cannot read 'priority' as presence subelement (%d)", parsedPresence.Priority)
}
}