mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-21 21:30:50 +01:00
Add tests for MsgWriter writePart functionality
Introduce tests to validate MsgWriter's handling of message parts. This includes ensuring charset defaulting behavior and proper inclusion of part descriptions.
This commit is contained in:
parent
8e11fabbaf
commit
dedb0e36c8
1 changed files with 38 additions and 0 deletions
|
@ -430,3 +430,41 @@ func TestMsgWriter_addFiles(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestMsgWriter_writePart(t *testing.T) {
|
||||
msgwriter := &msgWriter{
|
||||
charset: CharsetUTF8,
|
||||
encoder: getEncoder(EncodingQP),
|
||||
}
|
||||
t.Run("message with no part charset should use default message charset", func(t *testing.T) {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
msgwriter.writer = buffer
|
||||
message := testMessage(t, WithCharset(CharsetUTF7))
|
||||
message.AddAlternativeString(TypeTextPlain, "thisisatest")
|
||||
message.parts[1].charset = ""
|
||||
msgwriter.writeMsg(message)
|
||||
if msgwriter.err != nil {
|
||||
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
||||
}
|
||||
if !strings.Contains(buffer.String(), "ontent-Type: text/plain; charset=UTF-7\r\n\r\nTestmail") {
|
||||
t.Errorf("part not found in mail message. Mail: %s", buffer.String())
|
||||
}
|
||||
if !strings.Contains(buffer.String(), "ontent-Type: text/plain; charset=UTF-7\r\n\r\nthisisatest") {
|
||||
t.Errorf("part not found in mail message. Mail: %s", buffer.String())
|
||||
}
|
||||
})
|
||||
t.Run("message with parts that have a description", func(t *testing.T) {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
msgwriter.writer = buffer
|
||||
message := testMessage(t)
|
||||
message.AddAlternativeString(TypeTextPlain, "thisisatest")
|
||||
message.parts[1].description = "thisisadescription"
|
||||
msgwriter.writeMsg(message)
|
||||
if msgwriter.err != nil {
|
||||
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
||||
}
|
||||
if !strings.Contains(buffer.String(), "Content-Description: thisisadescription") {
|
||||
t.Errorf("part description not found in mail message. Mail: %s", buffer.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue