2019-05-16 09:03:12 -07:00
|
|
|
package xmpp_test
|
2018-01-24 00:38:02 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
2019-02-10 08:53:18 -08:00
|
|
|
"gosrc.io/xmpp"
|
2018-01-24 00:38:02 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerateMessage(t *testing.T) {
|
2019-02-10 08:53:18 -08:00
|
|
|
message := xmpp.NewMessage("chat", "admin@localhost", "test@localhost", "1", "en")
|
2018-01-24 00:38:02 -08:00
|
|
|
message.Body = "Hi"
|
|
|
|
message.Subject = "Msg Subject"
|
|
|
|
|
|
|
|
data, err := xml.Marshal(message)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("cannot marshal xml structure")
|
|
|
|
}
|
|
|
|
|
2019-02-10 08:53:18 -08:00
|
|
|
parsedMessage := xmpp.Message{}
|
2018-01-24 00:38:02 -08:00
|
|
|
if err = xml.Unmarshal(data, &parsedMessage); err != nil {
|
|
|
|
t.Errorf("Unmarshal(%s) returned error", data)
|
|
|
|
}
|
|
|
|
|
2018-01-25 02:00:20 -08:00
|
|
|
if !xmlEqual(parsedMessage, message) {
|
|
|
|
t.Errorf("non matching items\n%s", cmp.Diff(parsedMessage, message))
|
2018-01-24 00:38:02 -08:00
|
|
|
}
|
|
|
|
}
|