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
/
postmark_test.go
73 lines (61 loc) · 1.63 KB
/
postmark_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
package postmark
import (
"testing"
"os"
)
// Probably should figure out a way to run these tests without
// burning credits..
func setup(t *testing.T) map[string]string {
cfg := make(map[string]string)
cfg["key"] = os.Getenv("POSTMARK_API_KEY")
cfg["to"] = os.Getenv("POSTMARK_TO")
cfg["from"] = os.Getenv("POSTMARK_FROM")
if len(cfg["key"]) <= 0 {
t.Fatal("Need to setup POSTMARK_API_KEY")
}
return cfg
}
func TestSend(t *testing.T){
cfg := setup(t)
println(cfg["key"])
p := NewPostmark(cfg["key"])
if p == nil {
t.Fatal("NewPostmark (check api key)")
}
r, e := p.Send(&Message{
From: cfg["from"],
To: cfg["to"],
Subject: "TestSend",
TextBody: "TestSend Body",
})
if e != nil {
t.Fatal("Send failed! ", e.Error())
}
if r == nil || r.ErrorCode != 0 {
t.Fatal("Response fail. ", r.String())
}
}
func TestAttachment(t *testing.T){
cfg := setup(t)
msg := &Message{
From: cfg["from"],
To: cfg["to"],
Subject: "TestAttach",
TextBody: "Test attach body",
}
err := msg.Attach("testdata/attachment.txt")
println(msg.String())
if err != nil {
t.Fatal("Attach failed. ", err.Error())
}
p := NewPostmark(cfg["key"])
if p == nil {
t.Fatal("NewPostmark (check api key)")
}
rsp, err := p.Send(msg)
if err != nil {
t.Fatal("Send failed.", err.Error())
}
if rsp.ErrorCode != 0 {
t.Fatal("Response fail. ", rsp.String()) }
}