mirror of
https://github.com/FluuxIO/go-xmpp
synced 2024-11-17 15:29:37 +00:00
ffcde39ba6
* Add test (and refactor them) for #15 * Update Dockerfile to support Go modules on Codeship
30 lines
680 B
Go
30 lines
680 B
Go
package xmpp_test // import "gosrc.io/xmpp_test"
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"gosrc.io/xmpp"
|
|
)
|
|
|
|
func TestGenerateMessage(t *testing.T) {
|
|
message := xmpp.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 := xmpp.Message{}
|
|
if err = xml.Unmarshal(data, &parsedMessage); err != nil {
|
|
t.Errorf("Unmarshal(%s) returned error", data)
|
|
}
|
|
|
|
if !xmlEqual(parsedMessage, message) {
|
|
t.Errorf("non matching items\n%s", cmp.Diff(parsedMessage, message))
|
|
}
|
|
}
|