-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattachment_test.go
More file actions
53 lines (48 loc) · 1.47 KB
/
Copy pathattachment_test.go
File metadata and controls
53 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package mdsend
import (
"path/filepath"
"testing"
"github.com/dkotik/mdsend/media"
)
func TestAttachments(t *testing.T) {
loader, err := New(media.NewUnsafeUnconstrainedFileSystem(), Defaults{})
if err != nil {
t.Fatal(err)
}
_, attachments, err := loader.LoadLetter(
t.Context(),
filepath.Join("testdata", "attachments", "letter.md"),
)
if err != nil {
t.Fatal(err)
}
if len(attachments) != 4 {
t.Errorf("expected 4 attachments, got %d", len(attachments))
}
tcs := []struct {
Name string
ContentID string
ContentType string
}{
{Name: "cat.jpg", ContentID: "", ContentType: "image/jpeg"},
{Name: "attachment.txt", ContentID: "", ContentType: "text/plain; charset=utf-8"},
{Name: "chamillion.jpg", ContentID: "hydNeKLUx3Y@test.com", ContentType: "image/jpeg"},
{Name: "panda.jpg", ContentID: "S2EnMRZNrA7@test.com", ContentType: "image/jpeg"},
}
for i, attachment := range attachments {
if i > len(tcs)-1 {
t.Error("extra attachment", i+1, attachment.Name)
continue
}
t.Log("Attached:", attachment.Name)
if attachment.Name != tcs[i].Name {
t.Errorf("expected attachment name %s, got %s", tcs[i].Name, attachment.Name)
}
if attachment.ContentID != tcs[i].ContentID {
t.Errorf("expected attachment content ID %q, got %q", tcs[i].ContentID, attachment.ContentID)
}
if attachment.ContentType != tcs[i].ContentType {
t.Errorf("expected attachment content type %s, got %s", tcs[i].ContentType, attachment.ContentType)
}
}
}