mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Adjust tests to handle platform-specific differences.
Added platform-specific checks for header and attachment content in `msgwriter_test.go`. This ensures compatibility and correct behavior on different operating systems, such as Windows and FreeBSD.
This commit is contained in:
parent
3a046d728e
commit
b63a3dab9a
1 changed files with 82 additions and 18 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -312,14 +313,28 @@ func TestMsgWriter_addFiles(t *testing.T) {
|
||||||
if msgwriter.err != nil {
|
if msgwriter.err != nil {
|
||||||
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
switch runtime.GOOS {
|
||||||
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
case "windows":
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
||||||
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Type: text/plain; charset=utf-8; name="attachment.txt"`) {
|
switch runtime.GOOS {
|
||||||
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
case "freebsd":
|
||||||
|
if !strings.Contains(buffer.String(), `Content-Type: application/octet-stream; name="attachment.txt"`) {
|
||||||
|
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), `Content-Type: text/plain; charset=utf-8; name="attachment.txt"`) {
|
||||||
|
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("message with a single file attached no extension", func(t *testing.T) {
|
t.Run("message with a single file attached no extension", func(t *testing.T) {
|
||||||
|
@ -331,8 +346,15 @@ func TestMsgWriter_addFiles(t *testing.T) {
|
||||||
if msgwriter.err != nil {
|
if msgwriter.err != nil {
|
||||||
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
switch runtime.GOOS {
|
||||||
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
case "windows":
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment"`) {
|
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment"`) {
|
||||||
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
@ -350,8 +372,15 @@ func TestMsgWriter_addFiles(t *testing.T) {
|
||||||
if msgwriter.err != nil {
|
if msgwriter.err != nil {
|
||||||
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
switch runtime.GOOS {
|
||||||
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
case "windows":
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
||||||
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
@ -375,8 +404,15 @@ func TestMsgWriter_addFiles(t *testing.T) {
|
||||||
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
||||||
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `text/plain; charset=utf-8; name="attachment.txt"`) {
|
switch runtime.GOOS {
|
||||||
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
case "freebsd":
|
||||||
|
if !strings.Contains(buffer.String(), `Content-Type: application/octet-stream; name="attachment.txt"`) {
|
||||||
|
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), `Content-Type: text/plain; charset=utf-8; name="attachment.txt"`) {
|
||||||
|
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Transfer-Encoding: 7bit`) {
|
if !strings.Contains(buffer.String(), `Content-Transfer-Encoding: 7bit`) {
|
||||||
t.Errorf("Content-Transfer-Encoding header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Transfer-Encoding header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
@ -391,14 +427,28 @@ func TestMsgWriter_addFiles(t *testing.T) {
|
||||||
if msgwriter.err != nil {
|
if msgwriter.err != nil {
|
||||||
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), "\r\n\r\nVGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
switch runtime.GOOS {
|
||||||
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
case "windows":
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
||||||
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `text/plain; charset=utf-8; name="attachment.txt"`) {
|
switch runtime.GOOS {
|
||||||
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
case "freebsd":
|
||||||
|
if !strings.Contains(buffer.String(), `Content-Type: application/octet-stream; name="attachment.txt"`) {
|
||||||
|
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), `Content-Type: text/plain; charset=utf-8; name="attachment.txt"`) {
|
||||||
|
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Transfer-Encoding: base64`) {
|
if !strings.Contains(buffer.String(), `Content-Transfer-Encoding: base64`) {
|
||||||
t.Errorf("Content-Transfer-Encoding header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Transfer-Encoding header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
@ -417,14 +467,28 @@ func TestMsgWriter_addFiles(t *testing.T) {
|
||||||
if msgwriter.err != nil {
|
if msgwriter.err != nil {
|
||||||
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
t.Errorf("msgWriter failed to write: %s", msgwriter.err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), "\r\n\r\nVGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
switch runtime.GOOS {
|
||||||
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
case "windows":
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), "VGhpcyBpcyBhIHRlc3QgYXR0YWNobWVudAo=") {
|
||||||
|
t.Errorf("attachment not found in mail message. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
if !strings.Contains(buffer.String(), `Content-Disposition: attachment; filename="attachment.txt"`) {
|
||||||
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Dispositon header not found for attachment. Mail: %s", buffer.String())
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `text/plain; charset=utf-8; name="attachment.txt"`) {
|
switch runtime.GOOS {
|
||||||
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
case "freebsd":
|
||||||
|
if !strings.Contains(buffer.String(), `Content-Type: application/octet-stream; name="attachment.txt"`) {
|
||||||
|
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !strings.Contains(buffer.String(), `Content-Type: text/plain; charset=utf-8; name="attachment.txt"`) {
|
||||||
|
t.Errorf("Content-Type header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !strings.Contains(buffer.String(), `Content-Transfer-Encoding: base64`) {
|
if !strings.Contains(buffer.String(), `Content-Transfer-Encoding: base64`) {
|
||||||
t.Errorf("Content-Transfer-Encoding header not found for attachment. Mail: %s", buffer.String())
|
t.Errorf("Content-Transfer-Encoding header not found for attachment. Mail: %s", buffer.String())
|
||||||
|
|
Loading…
Reference in a new issue