-
Notifications
You must be signed in to change notification settings - Fork 5
/
mboxparser_test.go
59 lines (49 loc) · 1.01 KB
/
mboxparser_test.go
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
54
55
56
57
58
59
package mboxparser
import (
"io/ioutil"
"strings"
"testing"
)
func TestNotFound(t *testing.T) {
_, err := ReadFile("testdata/not_found.mbox")
if err == nil {
t.Fatal(err)
}
}
func TestReadFile(t *testing.T) {
mbox, err := ReadFile("testdata/simple.mbox")
if err != nil {
t.Fatal(err)
}
if len(mbox.Messages) != 1 {
t.Fatalf("invalid messages count: %d", len(mbox.Messages))
}
}
func TestNoBody(t *testing.T) {
mbox, err := ReadFile("testdata/nobody.mbox")
if err != nil {
t.Fatal(err)
}
message := mbox.Messages[0]
if len(message.Bodies) != 0 {
t.Fatal("Invalid body found")
}
}
func TestPlain(t *testing.T) {
mbox, err := ReadFile("testdata/plain.mbox")
if err != nil {
t.Fatal(err)
}
message := mbox.Messages[0]
if len(message.Bodies) != 1 {
t.Fatal("Invalid body found")
}
body := message.Bodies[0]
text, err := ioutil.ReadAll(body.Content)
if err != nil {
t.Fatal(err)
}
if strings.TrimSpace(string(text)) != "This is a test" {
t.Fatalf("Invalid body: %s", string(text))
}
}