Remove newline characters in test data strings

Trim newline characters from test attachment and embed strings. Updated assertions to compare strings without trailing newlines for consistency.
This commit is contained in:
Winni Neessen 2024-10-27 12:05:18 +01:00
parent cb5ac8b0e2
commit 056ec60734
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -3239,9 +3239,9 @@ func TestMsg_GetAttachments(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("writer func failed: %s", err) t.Errorf("writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test attachment\n") { got := strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test attachment\n", if !strings.EqualFold(got, "This is a test attachment") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test attachment", got)
} }
}) })
t.Run("GetAttachments with multiple attachments", func(t *testing.T) { t.Run("GetAttachments with multiple attachments", func(t *testing.T) {
@ -3271,18 +3271,18 @@ func TestMsg_GetAttachments(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("writer func failed: %s", err) t.Errorf("writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test attachment\n") { got := strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test attachment\n", if !strings.EqualFold(got, "This is a test attachment") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test attachment", got)
} }
messageBuf.Reset() messageBuf.Reset()
_, err = attachments[1].Writer(messageBuf) _, err = attachments[1].Writer(messageBuf)
if err != nil { if err != nil {
t.Errorf("writer func failed: %s", err) t.Errorf("writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test attachment\n") { got = strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test attachment\n", if !strings.EqualFold(got, "This is a test attachment") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test attachment", got)
} }
}) })
t.Run("GetAttachments with no attachment", func(t *testing.T) { t.Run("GetAttachments with no attachment", func(t *testing.T) {
@ -3329,7 +3329,7 @@ func TestMsg_SetAttachments(t *testing.T) {
Desc: "Test file", Desc: "Test file",
Name: "attachment.txt", Name: "attachment.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is a test attachment\n")) buf := bytes.NewBuffer([]byte("This is a test attachment"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3351,9 +3351,9 @@ func TestMsg_SetAttachments(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("writer func failed: %s", err) t.Errorf("writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test attachment\n") { got := strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test attachment\n", if !strings.EqualFold(got, "This is a test attachment") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test attachment", got)
} }
}) })
t.Run("SetAttachments with multiple files", func(t *testing.T) { t.Run("SetAttachments with multiple files", func(t *testing.T) {
@ -3366,7 +3366,7 @@ func TestMsg_SetAttachments(t *testing.T) {
Desc: "Test file", Desc: "Test file",
Name: "attachment.txt", Name: "attachment.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is a test attachment\n")) buf := bytes.NewBuffer([]byte("This is a test attachment"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3376,7 +3376,7 @@ func TestMsg_SetAttachments(t *testing.T) {
Desc: "Test file no. 2", Desc: "Test file no. 2",
Name: "attachment2.txt", Name: "attachment2.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is also a test attachment\n")) buf := bytes.NewBuffer([]byte("This is also a test attachment"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3402,18 +3402,18 @@ func TestMsg_SetAttachments(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("writer func failed: %s", err) t.Errorf("writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test attachment\n") { got := strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test attachment\n", if !strings.EqualFold(messageBuf.String(), "This is a test attachment") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test attachment", got)
} }
messageBuf.Reset() messageBuf.Reset()
_, err = attachments[1].Writer(messageBuf) _, err = attachments[1].Writer(messageBuf)
if err != nil { if err != nil {
t.Errorf("writer func failed: %s", err) t.Errorf("writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is also a test attachment\n") { got = strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is also a test attachment\n", if !strings.EqualFold(got, "This is also a test attachment") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is also a test attachment", got)
} }
}) })
t.Run("SetAttachments with no file", func(t *testing.T) { t.Run("SetAttachments with no file", func(t *testing.T) {
@ -3446,7 +3446,7 @@ func TestMsg_UnsetAllAttachments(t *testing.T) {
Desc: "Test file", Desc: "Test file",
Name: "attachment.txt", Name: "attachment.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is a test attachment\n")) buf := bytes.NewBuffer([]byte("This is a test attachment"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3456,7 +3456,7 @@ func TestMsg_UnsetAllAttachments(t *testing.T) {
Desc: "Test file no. 2", Desc: "Test file no. 2",
Name: "attachment2.txt", Name: "attachment2.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is also a test attachment\n")) buf := bytes.NewBuffer([]byte("This is also a test attachment"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3495,9 +3495,9 @@ func TestMsg_GetEmbeds(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Writer func failed: %s", err) t.Errorf("Writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test embed\n") { got := strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test embed\n", if !strings.EqualFold(got, "This is a test embed") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test embed", got)
} }
}) })
t.Run("GetEmbeds with multiple embeds", func(t *testing.T) { t.Run("GetEmbeds with multiple embeds", func(t *testing.T) {
@ -3527,18 +3527,18 @@ func TestMsg_GetEmbeds(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Writer func failed: %s", err) t.Errorf("Writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test embed\n") { got := strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test embed\n", if !strings.EqualFold(got, "This is a test embed") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test embed", got)
} }
messageBuf.Reset() messageBuf.Reset()
_, err = embeds[1].Writer(messageBuf) _, err = embeds[1].Writer(messageBuf)
if err != nil { if err != nil {
t.Errorf("Writer func failed: %s", err) t.Errorf("Writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test embed\n") { got = strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test embed\n", if !strings.EqualFold(got, "This is a test embed") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test embed", got)
} }
}) })
t.Run("GetEmbeds with no embeds", func(t *testing.T) { t.Run("GetEmbeds with no embeds", func(t *testing.T) {
@ -3564,7 +3564,7 @@ func TestMsg_SetEmbeds(t *testing.T) {
Desc: "Test file", Desc: "Test file",
Name: "embed.txt", Name: "embed.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is a test embed\n")) buf := bytes.NewBuffer([]byte("This is a test embed"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3586,9 +3586,9 @@ func TestMsg_SetEmbeds(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Writer func failed: %s", err) t.Errorf("Writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test embed\n") { got := strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test embed\n", if !strings.EqualFold(got, "This is a test embed") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test embed", got)
} }
}) })
t.Run("SetEmbeds with multiple files", func(t *testing.T) { t.Run("SetEmbeds with multiple files", func(t *testing.T) {
@ -3601,7 +3601,7 @@ func TestMsg_SetEmbeds(t *testing.T) {
Desc: "Test file", Desc: "Test file",
Name: "embed.txt", Name: "embed.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is a test embed\n")) buf := bytes.NewBuffer([]byte("This is a test embed"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3611,7 +3611,7 @@ func TestMsg_SetEmbeds(t *testing.T) {
Desc: "Test file no. 2", Desc: "Test file no. 2",
Name: "embed2.txt", Name: "embed2.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is also a test embed\n")) buf := bytes.NewBuffer([]byte("This is also a test embed"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3637,18 +3637,18 @@ func TestMsg_SetEmbeds(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Writer func failed: %s", err) t.Errorf("Writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is a test embed\n") { got := strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is a test embed\n", if !strings.EqualFold(got, "This is a test embed") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is a test embed", got)
} }
messageBuf.Reset() messageBuf.Reset()
_, err = embeds[1].Writer(messageBuf) _, err = embeds[1].Writer(messageBuf)
if err != nil { if err != nil {
t.Errorf("Writer func failed: %s", err) t.Errorf("Writer func failed: %s", err)
} }
if !strings.EqualFold(messageBuf.String(), "This is also a test embed\n") { got = strings.TrimSpace(messageBuf.String())
t.Errorf("expected message body to be %s, got: %s", "This is also a test embed\n", if !strings.EqualFold(got, "This is also a test embed") {
messageBuf.String()) t.Errorf("expected message body to be %s, got: %s", "This is also a test embed", got)
} }
}) })
t.Run("SetEmbeds with no file", func(t *testing.T) { t.Run("SetEmbeds with no file", func(t *testing.T) {
@ -3674,7 +3674,7 @@ func TestMsg_UnsetAllEmbeds(t *testing.T) {
Desc: "Test file", Desc: "Test file",
Name: "embed.txt", Name: "embed.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is a test embed\n")) buf := bytes.NewBuffer([]byte("This is a test embed"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3684,7 +3684,7 @@ func TestMsg_UnsetAllEmbeds(t *testing.T) {
Desc: "Test file no. 2", Desc: "Test file no. 2",
Name: "embed2.txt", Name: "embed2.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is also a test embed\n")) buf := bytes.NewBuffer([]byte("This is also a test embed"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3710,7 +3710,7 @@ func TestMsg_UnsetAllParts(t *testing.T) {
Desc: "Test file", Desc: "Test file",
Name: "embed.txt", Name: "embed.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is a test embed\n")) buf := bytes.NewBuffer([]byte("This is a test embed"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },
@ -3720,7 +3720,7 @@ func TestMsg_UnsetAllParts(t *testing.T) {
Desc: "Test file no. 2", Desc: "Test file no. 2",
Name: "embed2.txt", Name: "embed2.txt",
Writer: func(w io.Writer) (int64, error) { Writer: func(w io.Writer) (int64, error) {
buf := bytes.NewBuffer([]byte("This is also a test embed\n")) buf := bytes.NewBuffer([]byte("This is also a test embed"))
n, err := w.Write(buf.Bytes()) n, err := w.Write(buf.Bytes())
return int64(n), err return int64(n), err
}, },