forked from jshiffer/go-xmpp
Improve presence / message test
This commit is contained in:
parent
28fb5bf61b
commit
7e50d313ea
@ -50,5 +50,3 @@ func (msg *Message) XMPPFormat() string {
|
||||
msg.To,
|
||||
xmlEscape(msg.Body))
|
||||
}
|
||||
|
||||
// TODO: Func new message to create an empty message structure without the XML tag matching elements
|
||||
|
@ -22,7 +22,7 @@ func TestGenerateMessage(t *testing.T) {
|
||||
t.Errorf("Unmarshal(%s) returned error", data)
|
||||
}
|
||||
|
||||
if !xmlEqual(parsedMessage.Body, message.Body) {
|
||||
t.Errorf("non matching items\n%s", cmp.Diff(parsedMessage.Body, message.Body))
|
||||
if !xmlEqual(parsedMessage, message) {
|
||||
t.Errorf("non matching items\n%s", cmp.Diff(parsedMessage, message))
|
||||
}
|
||||
}
|
||||
|
12
presence.go
12
presence.go
@ -18,6 +18,18 @@ func (Presence) Name() string {
|
||||
return "presence"
|
||||
}
|
||||
|
||||
func NewPresence(from, to, id, lang string) Presence {
|
||||
return Presence{
|
||||
XMLName: xml.Name{Local: "presence"},
|
||||
PacketAttrs: PacketAttrs{
|
||||
Id: id,
|
||||
From: from,
|
||||
To: to,
|
||||
Lang: lang,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type presenceDecoder struct{}
|
||||
|
||||
var presence presenceDecoder
|
||||
|
27
presence_test.go
Normal file
27
presence_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestGeneratePresence(t *testing.T) {
|
||||
presence := NewPresence("admin@localhost", "test@localhost", "1", "en")
|
||||
presence.Show = "chat"
|
||||
|
||||
data, err := xml.Marshal(presence)
|
||||
if err != nil {
|
||||
t.Errorf("cannot marshal xml structure")
|
||||
}
|
||||
|
||||
parsedPresence := 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))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user