mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-21 01:52:01 -08:00
Add basic test for messages
This commit is contained in:
parent
7ae2adca9f
commit
28fb5bf61b
13
message.go
13
message.go
@ -21,6 +21,19 @@ func (Message) Name() string {
|
||||
return "message"
|
||||
}
|
||||
|
||||
func NewMessage(msgtype, from, to, id, lang string) Message {
|
||||
return Message{
|
||||
XMLName: xml.Name{Local: "message"},
|
||||
PacketAttrs: PacketAttrs{
|
||||
Id: id,
|
||||
From: from,
|
||||
To: to,
|
||||
Type: msgtype,
|
||||
Lang: lang,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type messageDecoder struct{}
|
||||
|
||||
var message messageDecoder
|
||||
|
28
message_test.go
Normal file
28
message_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestGenerateMessage(t *testing.T) {
|
||||
message := NewMessage("chat", "admin@localhost", "test@localhost", "1", "en")
|
||||
message.Body = "Hi"
|
||||
message.Subject = "Msg Subject"
|
||||
|
||||
data, err := xml.Marshal(message)
|
||||
if err != nil {
|
||||
t.Errorf("cannot marshal xml structure")
|
||||
}
|
||||
|
||||
parsedMessage := Message{}
|
||||
if err = xml.Unmarshal(data, &parsedMessage); err != nil {
|
||||
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))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user