-
Notifications
You must be signed in to change notification settings - Fork 1
/
alerts_test.go
48 lines (42 loc) · 1.27 KB
/
alerts_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
package common_test
import (
"bytes"
"strings"
"testing"
"github.com/APTrust/registry/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var templateNames = []string{
"alerts/deletion_cancelled.txt",
"alerts/deletion_completed.txt",
"alerts/deletion_confirmed.txt",
"alerts/deletion_requested.txt",
"alerts/failed_fixity.txt",
"alerts/restoration_completed.txt",
}
// Make sure these templates are loaded, and that they have
// content. Unlike our HTML templates, if we include "define"
// directives in the text templates, they will silently fail
// and return no content after execution.
func TestAlertTemplates(t *testing.T) {
require.NotNil(t, common.TextTemplates)
for _, name := range templateNames {
assert.NotNil(t, common.TextTemplates[name])
}
name := "Spongebob"
link := "https://example.com/confirm?token=ABCD"
data := map[string]string{
"requesterName": name,
"deletionReviewURL": link,
}
tmpl := common.TextTemplates["alerts/deletion_requested.txt"]
require.NotNil(t, tmpl)
var buf bytes.Buffer
err := tmpl.Execute(&buf, data)
require.Nil(t, err)
content := buf.String()
assert.True(t, len(content) > 100)
assert.True(t, strings.Contains(content, name))
assert.True(t, strings.Contains(content, link))
}