forked from jshiffer/go-xmpp
Fix session element parsing on IQ
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// Check that we can detect optional session from advertised stream features
|
||||
func TestSession(t *testing.T) {
|
||||
func TestSessionFeatures(t *testing.T) {
|
||||
streamFeatures := stanza.StreamFeatures{Session: stanza.StreamSession{Optional: true}}
|
||||
|
||||
data, err := xml.Marshal(streamFeatures)
|
||||
@@ -18,10 +18,38 @@ func TestSession(t *testing.T) {
|
||||
|
||||
parsedStream := stanza.StreamFeatures{}
|
||||
if err = xml.Unmarshal(data, &parsedStream); err != nil {
|
||||
t.Errorf("Unmarshal(%s) returned error", data)
|
||||
t.Errorf("Unmarshal(%s) returned error: %s", data, err)
|
||||
}
|
||||
|
||||
if !parsedStream.Session.Optional {
|
||||
if !parsedStream.Session.IsOptional() {
|
||||
t.Error("Session should be optional")
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the Session tag can be used in IQ decoding
|
||||
func TestSessionIQ(t *testing.T) {
|
||||
iq := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeSet, Id: "session"})
|
||||
iq.Payload = &stanza.StreamSession{XMLName: xml.Name{Local: "session"}, Optional: true}
|
||||
|
||||
data, err := xml.Marshal(iq)
|
||||
if err != nil {
|
||||
t.Errorf("cannot marshal xml structure: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
parsedIQ := stanza.IQ{}
|
||||
if err = xml.Unmarshal(data, &parsedIQ); err != nil {
|
||||
t.Errorf("Unmarshal(%s) returned error: %s", data, err)
|
||||
return
|
||||
}
|
||||
|
||||
session, ok := parsedIQ.Payload.(*stanza.StreamSession)
|
||||
if !ok {
|
||||
t.Error("Missing session payload")
|
||||
return
|
||||
}
|
||||
|
||||
if !session.IsOptional() {
|
||||
t.Error("Session should be optional")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user