This repository has been archived by the owner on Apr 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
message_test.go
77 lines (66 loc) · 2.02 KB
/
message_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package postmark
import (
"testing"
)
// From API demo
var jsonMsg string = `{
"From" : "[email protected]",
"To" : "[email protected]",
"Cc" : "[email protected]",
"Bcc": "[email protected]",
"Subject" : "Test",
"Tag" : "Invitation",
"HtmlBody" : "<b>Hello</b>",
"TextBody" : "Hello",
"ReplyTo" : "[email protected]",
"Headers" : [{ "Name" : "CUSTOM-HEADER", "Value" : "value" }]
}`
var jsonRsp string = `{
"ErrorCode" : 0,
"Message" : "OK",
"MessageID" : "b7bc2f4a-e38e-4336-af7d-e6c392c2f817",
"SubmittedAt" : "2010-11-26T12:01:05.1794748-05:00",
"To" : "[email protected]"
}`
func TestMarshal(t *testing.T){
email := &Message {
From : "[email protected]",
To : "[email protected]",
Cc : "[email protected]",
Bcc: "[email protected]",
Subject : "Test",
Tag : "Invitation",
HtmlBody : "<b>Hello</b>",
TextBody : "Hello",
ReplyTo : "[email protected]",
Headers : []Header{Header{Name: "CUSTOM-HEADER", Value: "value"}}}
msg,err := email.Marshal()
if err != nil {
t.Errorf("Can't marshal object to json: %s\n", err)
}
println(string(msg))
}
func TestUnmarshal(t *testing.T){
email, err := UnmarshalMessage([]byte(jsonMsg))
if err != nil {
t.Errorf("Can't unmarshal message: %s\n", err.Error())
}
println(email.String())
rsp, err := UnmarshalResponse([]byte(jsonRsp))
if err != nil {
t.Errorf("Can't unmarshal response: %s\n", err.Error())
}
println(rsp.String())
}
func TestAttach(t *testing.T){
// Load object from template json
email, err := UnmarshalMessage([]byte(jsonMsg))
if err != nil {
t.Errorf("Can't unmarshal mesage: %s\n", err.Error())
}
err = email.Attach("testdata/attachment.txt")
if err != nil {
t.Errorf("Failed to attach file: %s\n", err.Error())
}
println(email.String())
}