@@ -158,3 +158,66 @@ func TestExtractOrgFromRepo(t *testing.T) {
158158 })
159159 }
160160}
161+
162+ // TestIsAlreadyTrackedAsBlocked tests that sprinkler correctly identifies blocked PRs
163+ func TestIsAlreadyTrackedAsBlocked (t * testing.T ) {
164+ app := & App {
165+ incoming : []PR {
166+ {URL : "https://github.com/org1/repo1/pull/1" , IsBlocked : true },
167+ {URL : "https://github.com/org1/repo1/pull/2" , IsBlocked : false },
168+ {URL : "https://github.com/org1/repo1/pull/3" , NeedsReview : true , IsBlocked : false }, // NeedsReview but not IsBlocked
169+ },
170+ outgoing : []PR {
171+ {URL : "https://github.com/org2/repo2/pull/10" , IsBlocked : true },
172+ {URL : "https://github.com/org2/repo2/pull/11" , IsBlocked : false },
173+ },
174+ }
175+
176+ sm := & sprinklerMonitor {app : app }
177+
178+ tests := []struct {
179+ name string
180+ url string
181+ want bool
182+ }{
183+ {
184+ name : "incoming PR is blocked" ,
185+ url : "https://github.com/org1/repo1/pull/1" ,
186+ want : true ,
187+ },
188+ {
189+ name : "incoming PR is not blocked" ,
190+ url : "https://github.com/org1/repo1/pull/2" ,
191+ want : false ,
192+ },
193+ {
194+ name : "incoming PR needs review but is not blocked" ,
195+ url : "https://github.com/org1/repo1/pull/3" ,
196+ want : false ,
197+ },
198+ {
199+ name : "outgoing PR is blocked" ,
200+ url : "https://github.com/org2/repo2/pull/10" ,
201+ want : true ,
202+ },
203+ {
204+ name : "outgoing PR is not blocked" ,
205+ url : "https://github.com/org2/repo2/pull/11" ,
206+ want : false ,
207+ },
208+ {
209+ name : "unknown PR" ,
210+ url : "https://github.com/org3/repo3/pull/99" ,
211+ want : false ,
212+ },
213+ }
214+
215+ for _ , tt := range tests {
216+ t .Run (tt .name , func (t * testing.T ) {
217+ got := sm .isAlreadyTrackedAsBlocked (tt .url , "test" , 1 )
218+ if got != tt .want {
219+ t .Errorf ("isAlreadyTrackedAsBlocked(%q) = %v, want %v" , tt .url , got , tt .want )
220+ }
221+ })
222+ }
223+ }
0 commit comments