mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Add test for GetAttachments method with no attachment
Introduced a new test case to check `GetAttachments` when no attachments are present in the message object. Removed the redundant `TestMsg_GetAttachments` function to simplify the test suite.
This commit is contained in:
parent
babf7b9780
commit
66e25d82d3
1 changed files with 10 additions and 47 deletions
57
msg_test.go
57
msg_test.go
|
@ -3276,6 +3276,16 @@ func TestMsg_GetAttachments(t *testing.T) {
|
|||
messageBuf.String())
|
||||
}
|
||||
})
|
||||
t.Run("GetAttachments with no attachment", func(t *testing.T) {
|
||||
message := NewMsg()
|
||||
if message == nil {
|
||||
t.Fatal("message is nil")
|
||||
}
|
||||
attachments := message.GetAttachments()
|
||||
if len(attachments) != 0 {
|
||||
t.Fatalf("GetAttachments: expected 1 attachment, got: %d", len(attachments))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// checkAddrHeader verifies the correctness of an AddrHeader in a Msg based on the provided criteria.
|
||||
|
@ -3488,53 +3498,6 @@ func checkGenHeader(t *testing.T, message *Msg, header Header, fn string, field,
|
|||
}
|
||||
}
|
||||
|
||||
// TestMsg_GetAttachments tests the Msg.GetAttachments method
|
||||
|
||||
func TestMsg_GetAttachments(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
files []string
|
||||
}{
|
||||
{"File: README.md", []string{"README.md"}},
|
||||
{"File: doc.go", []string{"doc.go"}},
|
||||
{"File: README.md and doc.go", []string{"README.md", "doc.go"}},
|
||||
{"File: nonexisting", nil},
|
||||
}
|
||||
m := NewMsg()
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
for _, f := range tt.files {
|
||||
m.AttachFile(f, WithFileName(f), nil)
|
||||
}
|
||||
if len(m.attachments) != len(tt.files) {
|
||||
t.Errorf("AttachFile() failed. Number of attachments expected: %d, got: %d", len(tt.files),
|
||||
len(m.attachments))
|
||||
return
|
||||
}
|
||||
ff := m.GetAttachments()
|
||||
if len(m.attachments) != len(ff) {
|
||||
t.Errorf("GetAttachments() failed. Number of attachments expected: %d, got: %d", len(m.attachments),
|
||||
len(ff))
|
||||
return
|
||||
}
|
||||
var fn []string
|
||||
for _, f := range ff {
|
||||
fn = append(fn, f.Name)
|
||||
}
|
||||
sort.Strings(fn)
|
||||
sort.Strings(tt.files)
|
||||
for i, f := range tt.files {
|
||||
if f != fn[i] {
|
||||
t.Errorf("GetAttachments() failed. Attachment name expected: %s, got: %s", f,
|
||||
fn[i])
|
||||
return
|
||||
}
|
||||
}
|
||||
m.Reset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsg_SetAttachments tests the Msg.GetAttachments method
|
||||
|
||||
func TestMsg_SetAttachments(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue