-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
163 lines (141 loc) · 3.39 KB
/
main_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"bytes"
"testing"
)
func TestTemplates(t *testing.T) {
tests := []struct {
name string
input commentData
expectedComment string
expectedCommit string
}{
{
"NoChangesOrNew",
commentData{},
`## Article Sync Summary
After merge, 0 new article will be created and 0 existing article will be updated.`,
`completed sync: 0 new, 0 updated
`,
},
{
"OneNewArticle",
commentData{
NewArticles: []*Article{{
Title: "My New Article",
URL: "dev.to",
}},
},
`## Article Sync Summary
After merge, 1 new article will be created and 0 existing article will be updated.
### New Articles
- My New Article`,
`completed sync: 1 new, 0 updated
- new: My New Article (dev.to)`,
},
{
"TwoNewArticles",
commentData{
NewArticles: []*Article{
{
Title: "My New Article",
URL: "dev.to",
},
{
Title: "My Other New Article",
URL: "dev.to",
}},
},
`## Article Sync Summary
After merge, 2 new article will be created and 0 existing article will be updated.
### New Articles
- My New Article
- My Other New Article`,
`completed sync: 2 new, 0 updated
- new: My New Article (dev.to)
- new: My Other New Article (dev.to)`,
},
{
"OneUpdatedArticle",
commentData{
UpdatedArticles: []*Article{{
Title: "My Updated Article",
URL: "dev.to",
}},
},
`## Article Sync Summary
After merge, 0 new article will be created and 1 existing article will be updated.
### Updated Articles
- [My Updated Article](dev.to)`,
`completed sync: 0 new, 1 updated
- updated: My Updated Article (dev.to)`,
},
{
"TwoUpdatedArticles",
commentData{
UpdatedArticles: []*Article{
{
Title: "My Updated Article",
URL: "dev.to",
},
{
Title: "My Other Updated Article",
URL: "dev.to",
},
},
},
`## Article Sync Summary
After merge, 0 new article will be created and 2 existing article will be updated.
### Updated Articles
- [My Updated Article](dev.to)
- [My Other Updated Article](dev.to)`,
`completed sync: 0 new, 2 updated
- updated: My Updated Article (dev.to)
- updated: My Other Updated Article (dev.to)`,
},
{
"UpdatedAndNewArticles",
commentData{
NewArticles: []*Article{{
Title: "My New Article",
URL: "dev.to",
}},
UpdatedArticles: []*Article{{
Title: "My Updated Article",
URL: "dev.to",
}},
},
`## Article Sync Summary
After merge, 1 new article will be created and 1 existing article will be updated.
### New Articles
- My New Article
### Updated Articles
- [My Updated Article](dev.to)`,
`completed sync: 1 new, 1 updated
- new: My New Article (dev.to)
- updated: My Updated Article (dev.to)`,
},
}
for _, tt := range tests {
t.Run(tt.name+"Comment", func(t *testing.T) {
var result bytes.Buffer
err := renderTemplate(commentTemplate, tt.input, &result)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if result.String() != tt.expectedComment {
t.Fatalf("unexpected result: %s", result.String())
}
})
t.Run(tt.name+"Commit", func(t *testing.T) {
var result bytes.Buffer
err := renderTemplate(commitTemplate, tt.input, &result)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if result.String() != tt.expectedCommit {
t.Fatalf("unexpected result: %s", result.String())
}
})
}
}