@@ -109,46 +109,6 @@ func TestGetProjectListWithNextPage(t *testing.T) {
109109 mockService .AssertExpectations (t )
110110}
111111
112- type mockService struct {
113- mock.Mock
114- }
115-
116- func (c * mockService ) GetRepository (owner string , repo string ) (* github.Repository , * github.Response , error ) {
117- args := c .Called (owner , repo )
118- var r * github.Response
119- if resp := args .Get (1 ); resp != nil {
120- r = args .Get (1 ).(* github.Response )
121- }
122- return args .Get (0 ).(* github.Repository ), r , args .Error (2 )
123- }
124-
125- func (c * mockService ) GetOrganizationRepositories (org string , opts * github.RepositoryListByOrgOptions ) ([]* github.Repository , * github.Response , error ) {
126- args := c .Called (org , opts )
127- var r * github.Response
128- if resp := args .Get (1 ); resp != nil {
129- r = args .Get (1 ).(* github.Response )
130- }
131- return args .Get (0 ).([]* github.Repository ), r , args .Error (2 )
132- }
133-
134- func (c * mockService ) GetUserRepositories (user string , opts * github.RepositoryListByUserOptions ) ([]* github.Repository , * github.Response , error ) {
135- args := c .Called (user , opts )
136- var r * github.Response
137- if resp := args .Get (1 ); resp != nil {
138- r = args .Get (1 ).(* github.Response )
139- }
140- return args .Get (0 ).([]* github.Repository ), r , args .Error (2 )
141- }
142-
143- func (c * mockService ) GetArchiveLink (owner string , repo string , archiveFormat github.ArchiveFormat , opts * github.RepositoryContentGetOptions ) (* url.URL , * github.Response , error ) {
144- args := c .Called (owner , repo , archiveFormat , opts )
145- var r * github.Response
146- if resp := args .Get (1 ); resp != nil {
147- r = args .Get (1 ).(* github.Response )
148- }
149- return args .Get (0 ).(* url.URL ), r , args .Error (2 )
150- }
151-
152112func TestDownload (t * testing.T ) {
153113 // Create temporary directory for testing
154114 tempDir , err := os .MkdirTemp ("" , "sheriff-clone-test-" )
@@ -211,3 +171,113 @@ func TestDownload(t *testing.T) {
211171 _ , err = os .Stat (filepath .Join (tempDir , "src" ))
212172 assert .NoError (t , err , "src directory should exist" )
213173}
174+
175+ func TestOpenVulnerabilityIssue (t * testing.T ) {
176+ title := repository .VulnerabilityIssueTitle
177+ mockClient := mockService {}
178+ mockClient .On ("ListRepositoryIssues" , mock .Anything , mock .Anything , mock .Anything ).Return ([]* github.Issue {}, & github.Response {}, nil )
179+ mockClient .On ("CreateIssue" , mock .Anything , mock .Anything , mock .Anything ).Return (& github.Issue {Title : & title }, & github.Response {}, nil )
180+
181+ svc := githubService {client : & mockClient }
182+
183+ i , err := svc .OpenVulnerabilityIssue (repository.Project {GroupOrOwner : "group" , Name : "repo" }, "report" )
184+ assert .Nil (t , err )
185+ assert .NotNil (t , i )
186+ assert .Equal (t , repository .VulnerabilityIssueTitle , i .Title )
187+ mockClient .AssertExpectations (t )
188+ }
189+
190+ func TestCloseVulnerabilityIssue (t * testing.T ) {
191+ title := repository .VulnerabilityIssueTitle
192+ state := "open"
193+ mockClient := mockService {}
194+ mockClient .On ("ListRepositoryIssues" , mock .Anything , mock .Anything , mock .Anything ).Return ([]* github.Issue {{Title : & title , State : & state }}, & github.Response {}, nil )
195+ mockClient .On ("UpdateIssue" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (& github.Issue {}, & github.Response {}, nil )
196+
197+ svc := githubService {client : & mockClient }
198+
199+ err := svc .CloseVulnerabilityIssue (repository.Project {GroupOrOwner : "group" , Name : "repo" })
200+ assert .Nil (t , err )
201+ mockClient .AssertExpectations (t )
202+ }
203+
204+ func TestCloseVulnerabilityIssueNoIssue (t * testing.T ) {
205+ mockClient := mockService {}
206+ mockClient .On ("ListRepositoryIssues" , mock .Anything , mock .Anything , mock .Anything ).Return (nil , & github.Response {}, nil )
207+
208+ svc := githubService {client : & mockClient }
209+
210+ err := svc .CloseVulnerabilityIssue (repository.Project {GroupOrOwner : "group" , Name : "repo" })
211+ assert .Nil (t , err )
212+ mockClient .AssertExpectations (t )
213+ }
214+
215+ type mockService struct {
216+ mock.Mock
217+ }
218+
219+ func (c * mockService ) GetRepository (owner string , repo string ) (* github.Repository , * github.Response , error ) {
220+ args := c .Called (owner , repo )
221+ var r * github.Response
222+ if resp := args .Get (1 ); resp != nil {
223+ r = args .Get (1 ).(* github.Response )
224+ }
225+ return args .Get (0 ).(* github.Repository ), r , args .Error (2 )
226+ }
227+
228+ func (c * mockService ) GetOrganizationRepositories (org string , opts * github.RepositoryListByOrgOptions ) ([]* github.Repository , * github.Response , error ) {
229+ args := c .Called (org , opts )
230+ var r * github.Response
231+ if resp := args .Get (1 ); resp != nil {
232+ r = args .Get (1 ).(* github.Response )
233+ }
234+ return args .Get (0 ).([]* github.Repository ), r , args .Error (2 )
235+ }
236+
237+ func (c * mockService ) GetUserRepositories (user string , opts * github.RepositoryListByUserOptions ) ([]* github.Repository , * github.Response , error ) {
238+ args := c .Called (user , opts )
239+ var r * github.Response
240+ if resp := args .Get (1 ); resp != nil {
241+ r = args .Get (1 ).(* github.Response )
242+ }
243+ return args .Get (0 ).([]* github.Repository ), r , args .Error (2 )
244+ }
245+
246+ func (c * mockService ) GetArchiveLink (owner string , repo string , archiveFormat github.ArchiveFormat , opts * github.RepositoryContentGetOptions ) (* url.URL , * github.Response , error ) {
247+ args := c .Called (owner , repo , archiveFormat , opts )
248+ var r * github.Response
249+ if resp := args .Get (1 ); resp != nil {
250+ r = args .Get (1 ).(* github.Response )
251+ }
252+ return args .Get (0 ).(* url.URL ), r , args .Error (2 )
253+ }
254+
255+ func (c * mockService ) ListRepositoryIssues (owner string , repo string , opts * github.IssueListByRepoOptions ) ([]* github.Issue , * github.Response , error ) {
256+ args := c .Called (owner , repo , opts )
257+ var r * github.Response
258+ if resp := args .Get (1 ); resp != nil {
259+ r = args .Get (1 ).(* github.Response )
260+ }
261+ if args .Get (0 ) == nil {
262+ return nil , r , args .Error (2 )
263+ }
264+ return args .Get (0 ).([]* github.Issue ), r , args .Error (2 )
265+ }
266+
267+ func (c * mockService ) CreateIssue (owner string , repo string , issue * github.IssueRequest ) (* github.Issue , * github.Response , error ) {
268+ args := c .Called (owner , repo , issue )
269+ var r * github.Response
270+ if resp := args .Get (1 ); resp != nil {
271+ r = args .Get (1 ).(* github.Response )
272+ }
273+ return args .Get (0 ).(* github.Issue ), r , args .Error (2 )
274+ }
275+
276+ func (c * mockService ) UpdateIssue (owner string , repo string , number int , issue * github.IssueRequest ) (* github.Issue , * github.Response , error ) {
277+ args := c .Called (owner , repo , number , issue )
278+ var r * github.Response
279+ if resp := args .Get (1 ); resp != nil {
280+ r = args .Get (1 ).(* github.Response )
281+ }
282+ return args .Get (0 ).(* github.Issue ), r , args .Error (2 )
283+ }
0 commit comments