Skip to content

Commit

Permalink
Improve content type handling in tests for FreeBSD and UTF-8.
Browse files Browse the repository at this point in the history
Refactored test cases to adjust `Content-Type` based on runtime OS. Removed redundant `charset=utf-8` where it was already covered by the file content type definition, ensuring consistency and correct MIME type handling across platforms.
  • Loading branch information
wneessen committed Jan 19, 2025
1 parent b57dd96 commit 267da1a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5955,6 +5955,10 @@ func TestMsg_WriteTo(t *testing.T) {
if _, err := message.WriteTo(buffer); err != nil {
t.Fatalf("failed to write message to buffer: %s", err)
}
fileContentType := "text/plain; charset=utf-8"
if runtime.GOOS == "freebsd" {
fileContentType = "application/octet-stream"
}
wants := []msgContentTest{
{0, "Date:", false, true, false},
{1, "MIME-Version: 1.0", true, true, false},
Expand All @@ -5971,7 +5975,7 @@ func TestMsg_WriteTo(t *testing.T) {
{16, "--", false, true, false},
{17, `Content-Disposition: attachment; filename="attachment.txt"`, true, true, false},
{18, `Content-Transfer-Encoding: base64`, true, true, false},
{19, `Content-Type: text/plain; charset=utf-8; name="attachment.txt"`, true, true, false},
{19, `Content-Type: ` + fileContentType + `; name="attachment.txt"`, true, true, false},
{20, "", true, false, false},
{21, "VGhpcyBpcyBhIHRlc3Qg", false, true, false},
{22, "", true, false, false},
Expand Down Expand Up @@ -6057,7 +6061,7 @@ func TestMsg_WriteTo(t *testing.T) {
if _, err := message.WriteTo(buffer); err != nil {
t.Fatalf("failed to write message to buffer: %s", err)
}
fileContentType := "text/plain"
fileContentType := "text/plain; charset=utf-8"
if runtime.GOOS == "freebsd" {
fileContentType = "application/octet-stream"
}
Expand Down Expand Up @@ -6095,7 +6099,7 @@ func TestMsg_WriteTo(t *testing.T) {
{32, `Content-Disposition: inline; filename="embed.txt"`, true, true, false},
{33, "Content-Id: <embed.txt>", true, true, false},
{34, "Content-Transfer-Encoding: base64", true, true, false},
{35, `Content-Type: ` + fileContentType + `; charset=utf-8; name="embed.txt"`, true, true, false},
{35, `Content-Type: ` + fileContentType + `; name="embed.txt"`, true, true, false},
{36, "", true, false, false},
{37, "VGhp", false, true, false},
{38, "", true, false, false},
Expand All @@ -6104,7 +6108,7 @@ func TestMsg_WriteTo(t *testing.T) {
{41, "--", false, true, false},
{42, `Content-Disposition: attachment; filename="attachment.txt"`, true, true, false},
{43, "Content-Transfer-Encoding: base64", true, true, false},
{44, `Content-Type: ` + fileContentType + `; charset=utf-8; name="attachment.txt"`, true, true, false},
{44, `Content-Type: ` + fileContentType + `; name="attachment.txt"`, true, true, false},
{45, "", true, false, false},
{46, "VGhp", false, true, false},
{47, "", true, false, false},
Expand All @@ -6128,7 +6132,7 @@ func TestMsg_WriteTo(t *testing.T) {
if _, err := message.WriteTo(buffer); err != nil {
t.Fatalf("failed to write message to buffer: %s", err)
}
fileContentType := "text/plain"
fileContentType := "text/plain; charset=utf-8"
if runtime.GOOS == "freebsd" {
fileContentType = "application/octet-stream"
}
Expand Down Expand Up @@ -6173,7 +6177,7 @@ func TestMsg_WriteTo(t *testing.T) {
{36, `Content-Disposition: inline; filename="embed.txt"`, true, true, false},
{37, "Content-Id: <embed.txt>", true, true, false},
{38, "Content-Transfer-Encoding: base64", true, true, false},
{39, `Content-Type: ` + fileContentType + `; charset=utf-8; name="embed.txt"`, true, true, false},
{39, `Content-Type: ` + fileContentType + `; name="embed.txt"`, true, true, false},
{40, "", true, false, false},
{41, "VGhp", false, true, false},
{42, "", true, false, false},
Expand All @@ -6182,7 +6186,7 @@ func TestMsg_WriteTo(t *testing.T) {
{45, "--", false, true, false},
{46, `Content-Disposition: attachment; filename="attachment.txt"`, true, true, false},
{47, "Content-Transfer-Encoding: base64", true, true, false},
{48, `Content-Type: ` + fileContentType + `; charset=utf-8; name="attachment.txt"`, true, true, false},
{48, `Content-Type: ` + fileContentType + `; name="attachment.txt"`, true, true, false},
{49, "", true, false, false},
{50, "VGhp", false, true, false},
{51, "", true, false, false},
Expand Down

0 comments on commit 267da1a

Please sign in to comment.