forked from emersion/go-message
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer_test.go
51 lines (42 loc) · 1.3 KB
/
writer_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 message
import (
"bytes"
"io"
"testing"
)
func TestWriter_multipartWithoutCreatePart(t *testing.T) {
var h Header
h.Set("Content-Type", "multipart/alternative; boundary=IMTHEBOUNDARY")
var b bytes.Buffer
mw, err := CreateWriter(&b, h)
if err != nil {
t.Fatal("Expected no error while creating message writer, got:", err)
}
io.WriteString(mw, testMultipartBody)
mw.Close()
if s := b.String(); s != testMultipartText {
t.Errorf("Expected output to be \n%s\n but go \n%s", testMultipartText, s)
}
}
func TestWriter_multipartWithoutBoundary(t *testing.T) {
var h Header
h.Set("Content-Type", "multipart/alternative")
var b bytes.Buffer
mw, err := CreateWriter(&b, h)
if err != nil {
t.Fatal("Expected no error while creating message writer, got:", err)
}
mw.Close()
e, err := Read(&b)
if err != nil {
t.Fatal("Expected no error while reading message, got:", err)
}
mediaType, mediaParams, err := e.Header.ContentType()
if err != nil {
t.Fatal("Expected no error while parsing Content-Type, got:", err)
} else if mediaType != "multipart/alternative" {
t.Errorf("Expected media type to be %q, but got %q", "multipart/alternative", mediaType)
} else if boundary, ok := mediaParams["boundary"]; !ok || boundary == "" {
t.Error("Expected boundary to be automatically generated")
}
}