-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjson_test.go
41 lines (33 loc) · 891 Bytes
/
json_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
package marcel
import (
"encoding/json"
"io/ioutil"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJSONMarshalAndUnmarshal(t *testing.T) {
data := strings.NewReader("oh hi I am an attachment")
email := Email{
To: "[email protected]",
From: "[email protected]",
ReplyTo: "[email protected]",
Text: "this is the text part of a test run",
HTML: "this <i>is the HTML part of a test</i> run",
Subject: "test run",
Attachments: []Attachment{
Attachment{
ContentType: "text/plain",
Data: data,
Filename: "test_data.txt",
},
},
}
result, err := json.Marshal(email)
assert.Nil(t, err)
newEmail := Email{}
assert.Nil(t, json.Unmarshal(result, &newEmail))
contents, err := ioutil.ReadAll(newEmail.Attachments[0].Data)
assert.Nil(t, err)
assert.Equal(t, string(contents), "oh hi I am an attachment")
}