28 lines
1.5 KiB
Go
28 lines
1.5 KiB
Go
package packetlog
|
|
|
|
import "testing"
|
|
|
|
func TestParseMessageLogExtractsXMPPMessage(t *testing.T) {
|
|
plaintext := "--------------------------------------------------------------------------------------------------------------------------------------------\r\n2026/7/7 15:30:07\r\n<message id=\"2de080bf-f5cc-45e2-b229-2df6bcd4afe3\" from=\"sender@imopenfire1-lanzhou/imp_pc_4.1.2.6842\" to=\"receiver@imopenfire1-lanzhou\" type=\"chat\">\r\n <body>redacted.docx</body>\r\n <received xmlns=\"urn:xmpp:receipts\" id=\"167c08c3d710489f812c13dc23d4e404\" type=\"1\" stamp=\"\" />\r\n <subject>FILE_TRANSFER_CANCEL</subject>\r\n <isphere xmlns=\"isphere.im\" type=\"1001\" sendtime=\"1783423807000\" version=\"1\">\r\n <alert type=\"0\" />\r\n </isphere>\r\n <consumed />\r\n <readed />\r\n</message>"
|
|
|
|
got, err := ParseMessageLog(plaintext)
|
|
if err != nil {
|
|
t.Fatalf("ParseMessageLog returned error: %v", err)
|
|
}
|
|
if got.ID != "2de080bf-f5cc-45e2-b229-2df6bcd4afe3" {
|
|
t.Fatalf("ID = %q", got.ID)
|
|
}
|
|
if got.From != "sender@imopenfire1-lanzhou/imp_pc_4.1.2.6842" || got.To != "receiver@imopenfire1-lanzhou" {
|
|
t.Fatalf("from/to = %q/%q", got.From, got.To)
|
|
}
|
|
if got.Body != "redacted.docx" || got.Subject != "FILE_TRANSFER_CANCEL" {
|
|
t.Fatalf("body/subject = %q/%q", got.Body, got.Subject)
|
|
}
|
|
if got.SendTime != "1783423807000" || got.ReceiptID != "167c08c3d710489f812c13dc23d4e404" || got.ReceiptType != "1" {
|
|
t.Fatalf("receipt fields = %+v", got)
|
|
}
|
|
if !got.Consumed || !got.Read {
|
|
t.Fatalf("consumed/read = %v/%v", got.Consumed, got.Read)
|
|
}
|
|
}
|