func (s *XmppSuite) TestParseRoster(c *C) { iq := data.ClientIQ{} iq.Query = []byte(` <query xmlns='jabber:iq:roster'> <item jid='*****@*****.**' name='Romeo' subscription='both'> <group>Friends</group> </item> <item jid='*****@*****.**' name='Mercutio' subscription='from'> <group>Friends</group> </item> <item jid='*****@*****.**' name='Benvolio' subscription='both'> <group>Friends</group> </item> </query> `) reply := data.Stanza{ Value: &iq, } rosterEntrys, err := data.ParseRoster(reply) c.Assert(rosterEntrys, NotNil) c.Assert(err, IsNil) }
func (s *RosterXMPPSuite) Test_ParseRoster_failsIfItDoesntReceiveAClientIQ(c *C) { rep := data.Stanza{ Name: xml.Name{Local: "Foobarium"}, Value: testStanzaValue{}, } _, err := data.ParseRoster(rep) c.Assert(err.Error(), Equals, "xmpp: roster request resulted in tag of type Foobarium") }
func (s *RosterXMPPSuite) Test_ParseRoster_failsIfTheRosterContentIsIncorrect(c *C) { rep := data.Stanza{ Name: xml.Name{Local: "iq"}, Value: &data.ClientIQ{ Query: []byte("<foo></bar>"), }, } _, err := data.ParseRoster(rep) c.Assert(err.Error(), Equals, "expected element type <query> but have <foo>") }
func (s *session) requestRoster() bool { conn, ok := s.connection() if !ok { return false } s.info("Fetching roster") delim, err := conn.GetRosterDelimiter() if err != nil || delim == "" { delim = defaultDelimiter } s.groupDelimiter = delim rosterReply, _, err := conn.RequestRoster() if err != nil { s.alert("Failed to request roster: " + err.Error()) return true } rosterStanza, ok := <-rosterReply if !ok { //TODO: should we retry the request in such case? log.Println("session: roster request cancelled or timedout") return true } rst, err := data.ParseRoster(rosterStanza) if err != nil { s.alert("Failed to parse roster: " + err.Error()) return true } for _, rr := range rst { s.addOrMergeNewPeer(rr, s.GetConfig()) } s.rosterReceived() return true }