2018-01-25 16:04:19 +00:00
|
|
|
package xmpp // import "fluux.io/xmpp"
|
2018-01-24 08:38:02 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2018-01-25 10:00:20 +00:00
|
|
|
if !xmlEqual(parsedMessage, message) {
|
|
|
|
t.Errorf("non matching items\n%s", cmp.Diff(parsedMessage, message))
|
2018-01-24 08:38:02 +00:00
|
|
|
}
|
|
|
|
}
|