-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_test.go
82 lines (78 loc) · 1.41 KB
/
email_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
78
79
80
81
82
package emailt
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"golang.org/x/net/html"
)
func TestEmail_Render(t *testing.T) {
type fields struct {
elements []Element
}
tests := []struct {
name string
fields fields
want string
wantErr bool
}{
{
name: "regular",
fields: fields{
elements: []Element{
&Table{
dataset: []TestStruct1{
{
A: "a1",
B: 1,
},
{
A: "a2",
B: 2,
},
{
A: "a3",
B: 3,
},
},
columns: []Column{
{
Name: "列1",
Template: "{{.A}}",
},
{
Name: "列2",
Template: "{{.B}}",
},
{
Name: "列3",
Template: "{{.A}}({{.B}})",
},
},
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := NewEmail().Add(tt.fields.elements...)
got := bytes.NewBuffer(nil)
err := e.Render(got)
if (err != nil) != tt.wantErr {
t.Errorf("Render() error = %v, wantErr %v", err, tt.wantErr)
return
}
if _, err := html.Parse(bytes.NewReader(got.Bytes())); err != nil {
t.Error(err)
}
t.Log(got.String())
dir := "output"
_ = os.Mkdir(dir, 0755)
_ = ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("TestEmail_Render.%s.html", tt.name)), got.Bytes(), 0644)
})
}
}