@@ -31,11 +31,13 @@ func TestSimpleXListed(t *testing.T) {
3131 Labels : []string {"LABEL_MERGE" },
3232 Comments : []string {"FULL_COMMENT_PLZ_MERGE" },
3333 CommentSubstrings : []string {":+1:" },
34+ PRBodySubstrings : []string {"BODY_MERGE_PLZ" },
3435 },
3536 Blacklist : Signals {
3637 Labels : []string {"LABEL_NOMERGE" },
3738 Comments : []string {"NO_WAY" },
3839 CommentSubstrings : []string {":-1:" },
40+ PRBodySubstrings : []string {"BODY_NOMERGE" },
3941 },
4042 }
4143
@@ -167,6 +169,114 @@ func TestSimpleXListed(t *testing.T) {
167169 assert .True (t , actualWhitelist )
168170 assert .Equal (t , "PR label matches one of specified whitelist labels: \" LABEL_MERGE\" " , actualWhitelistReason )
169171 })
172+
173+ t .Run ("bodyCausesWhitelist" , func (t * testing.T ) {
174+ pc := & pulltest.MockPullContext {
175+ BodyValue : "My PR Body\n \n \n BODY_MERGE_PLZ" ,
176+ }
177+
178+ actualWhitelist , actualWhitelistReason , err := IsPRWhitelisted (ctx , pc , mergeConfig .Whitelist )
179+ require .Nil (t , err )
180+ assert .True (t , actualWhitelist )
181+ assert .Equal (t , "PR body matches one of specified whitelist substrings: \" BODY_MERGE_PLZ\" " , actualWhitelistReason )
182+ })
183+
184+ t .Run ("bodyCausesCommentSubstringWhitelist" , func (t * testing.T ) {
185+ pc := & pulltest.MockPullContext {
186+ BodyValue : "My PR Body\n \n \n :+1:" ,
187+ }
188+
189+ actualWhitelist , actualWhitelistReason , err := IsPRWhitelisted (ctx , pc , mergeConfig .Whitelist )
190+ require .Nil (t , err )
191+ assert .True (t , actualWhitelist )
192+ assert .Equal (t , "PR body matches one of specified whitelist comment substrings: \" :+1:\" " , actualWhitelistReason )
193+ })
194+
195+ t .Run ("bodyCausesCommentWhitelist" , func (t * testing.T ) {
196+ pc := & pulltest.MockPullContext {
197+ BodyValue : "FULL_COMMENT_PLZ_MERGE" ,
198+ }
199+
200+ actualWhitelist , actualWhitelistReason , err := IsPRWhitelisted (ctx , pc , mergeConfig .Whitelist )
201+ require .Nil (t , err )
202+ assert .True (t , actualWhitelist )
203+ assert .Equal (t , "PR body matches one of specified whitelist comments: \" FULL_COMMENT_PLZ_MERGE\" " , actualWhitelistReason )
204+ })
205+
206+ t .Run ("bodyCausesBlacklist" , func (t * testing.T ) {
207+ pc := & pulltest.MockPullContext {
208+ BodyValue : "My PR Body\n \n \n BODY_NOMERGE" ,
209+ }
210+
211+ actualBlacklist , actualBlacklistReason , err := IsPRBlacklisted (ctx , pc , mergeConfig .Blacklist )
212+ require .Nil (t , err )
213+ assert .True (t , actualBlacklist )
214+ assert .Equal (t , "PR body matches one of specified blacklist substrings: \" BODY_NOMERGE\" " , actualBlacklistReason )
215+ })
216+
217+ t .Run ("bodyCausesCommentSubstringBlacklist" , func (t * testing.T ) {
218+ pc := & pulltest.MockPullContext {
219+ BodyValue : "My PR Body\n \n \n :-1:" ,
220+ }
221+
222+ actualBlacklist , actualBlacklistReason , err := IsPRBlacklisted (ctx , pc , mergeConfig .Blacklist )
223+ require .Nil (t , err )
224+ assert .True (t , actualBlacklist )
225+ assert .Equal (t , "PR body matches one of specified blacklist comment substrings: \" :-1:\" " , actualBlacklistReason )
226+ })
227+
228+ t .Run ("bodyCausesCommentBlacklist" , func (t * testing.T ) {
229+ pc := & pulltest.MockPullContext {
230+ BodyValue : "NO_WAY" ,
231+ }
232+
233+ actualBlacklist , actualBlacklistReason , err := IsPRBlacklisted (ctx , pc , mergeConfig .Blacklist )
234+ require .Nil (t , err )
235+ assert .True (t , actualBlacklist )
236+ assert .Equal (t , "PR body matches one of specified blacklist comments: \" NO_WAY\" " , actualBlacklistReason )
237+ })
238+
239+ t .Run ("errBodyFailsClosedBlacklist" , func (t * testing.T ) {
240+ pc := & pulltest.MockPullContext {
241+ BodyValue : "My PR Body" ,
242+ BodyErrValue : errors .New ("failure" ),
243+ }
244+
245+ actualBlacklist , _ , err := IsPRBlacklisted (ctx , pc , mergeConfig .Blacklist )
246+ require .NotNil (t , err )
247+ assert .True (t , actualBlacklist )
248+ })
249+
250+ t .Run ("errBodyFailsClosedWhitelist" , func (t * testing.T ) {
251+ pc := & pulltest.MockPullContext {
252+ BodyValue : "My PR Body" ,
253+ BodyErrValue : errors .New ("failure" ),
254+ }
255+
256+ actualWhitelist , _ , err := IsPRWhitelisted (ctx , pc , mergeConfig .Whitelist )
257+ require .NotNil (t , err )
258+ assert .False (t , actualWhitelist )
259+ })
260+
261+ t .Run ("errLabelFailsClosedWhitelist" , func (t * testing.T ) {
262+ pc := & pulltest.MockPullContext {
263+ LabelErrValue : errors .New ("failure" ),
264+ }
265+
266+ actualWhitelist , _ , err := IsPRWhitelisted (ctx , pc , mergeConfig .Whitelist )
267+ require .NotNil (t , err )
268+ assert .False (t , actualWhitelist )
269+ })
270+
271+ t .Run ("errCommentsFailsClosedWhitelist" , func (t * testing.T ) {
272+ pc := & pulltest.MockPullContext {
273+ CommentErrValue : errors .New ("failure" ),
274+ }
275+
276+ actualWhitelist , _ , err := IsPRWhitelisted (ctx , pc , mergeConfig .Whitelist )
277+ require .NotNil (t , err )
278+ assert .False (t , actualWhitelist )
279+ })
170280}
171281
172282func TestShouldMerge (t * testing.T ) {
0 commit comments