-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchemail_test.go
51 lines (44 loc) · 1.36 KB
/
fetchemail_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
package main
import (
"net/mail"
"strings"
"testing"
)
const testSrc = `
--0000000000003d878605a3bb155f
Content-Type: text/plain; charset="UTF-8"
https://golang.org/pkg/time/#Time
--0000000000003d878605a3bb155f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><a href=3D"https://golang.org/pkg/time/#Time" rel=3D"noref=
errer" target=3D"_blank">https://golang.org/pkg/time/#Time</a><div class=3D=
"gmail-adL"><br></div><div class=3D"gmail-adL"><a href=3D"https://golang.or=
g/pkg/time/#Time" rel=3D"noreferrer" target=3D"_blank">https://golang.org/p=
kg/time/#Time</a><div class=3D"gmail-adL"><a href=3D"/~https://github.com/der=
ekchuank/rss-email">/~https://github.com/derekchuank/rss-email</a></div><div =
class=3D"gmail-adL"><br></div></div></div>
--0000000000003d878605a3bb155f--
`
func Test_parseMultipart(t *testing.T) {
cases := []struct {
in *mail.Message
want string
}{
{&mail.Message{
Header: map[string][]string{
"Content-Type": {`multipart/alternative; boundary="0000000000003d878605a3bb155f"`},
},
Body: strings.NewReader(testSrc),
}, "https://golang.org/pkg/time/#Time\n"},
}
for _, c := range cases {
got, err := parseMultipart(c.in)
if err != nil {
t.Errorf("error %q", err)
}
if string(got) != c.want {
t.Errorf("parseMultipart(%q) == %q, want %q", c.in, got, c.want)
}
}
}