forked from brandur/sorg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_test.go
69 lines (55 loc) · 1.62 KB
/
send_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
package main
import (
"context"
"testing"
assert "github.com/stretchr/testify/require"
)
func TestMatchNewsletter(t *testing.T) {
{
info, draft := matchNewsletter("./content/nanoglyphs-drafts/999-placeholder.md")
assert.Equal(t, newsletterInfoNanoglyphs, info)
assert.True(t, draft)
}
{
info, draft := matchNewsletter("./content/nanoglyphs/001-first.md")
assert.Equal(t, newsletterInfoNanoglyphs, info)
assert.False(t, draft)
}
{
info, draft := matchNewsletter("./content/passages-drafts/999-placeholder.md")
assert.Equal(t, newsletterInfoPassages, info)
assert.True(t, draft)
}
{
info, draft := matchNewsletter("./content/passages/001-first.md")
assert.Equal(t, newsletterInfoPassages, info)
assert.False(t, draft)
}
{
info, _ := matchNewsletter("./content/articles/article.md")
assert.Equal(t, (*newsletterInfo)(nil), info)
}
}
func TestRenderAndSend(t *testing.T) {
ctx := context.Background()
oldMailgunKey := conf.MailgunAPIKey
defer func() {
conf.MailgunAPIKey = oldMailgunKey
}()
conf.MailgunAPIKey = ""
{
err := renderAndSend(ctx, nil, "./content/passages/001-first.md", true, false)
assert.Error(t, err, "MAILGUN_API_KEY must be configured in the environment")
}
conf.MailgunAPIKey = "key"
{
err := renderAndSend(ctx, nil, "./content/articles/article.md", true, false)
assert.Error(t, err,
"'./content/articles/article.md' does not appear to be a known newsletter (check its path)")
}
{
err := renderAndSend(ctx, nil, "./content/passages-drafts/999-placeholder.md", true, false)
assert.Error(t, err,
"refusing to send a draft newsletter to a live list")
}
}