@@ -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,108 @@ 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 := "666"
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 , "666" , i .Title )
187+ }
188+
189+ func TestCloseVulnerabilityIssue (t * testing.T ) {
190+ title := "288"
191+ mockClient := mockService {}
192+ mockClient .On ("ListRepositoryIssues" , mock .Anything , mock .Anything , mock .Anything ).Return ([]* github.Issue {{Title : & title }}, & github.Response {}, nil )
193+
194+ svc := githubService {client : & mockClient }
195+
196+ err := svc .CloseVulnerabilityIssue (repository.Project {GroupOrOwner : "group" , Name : "repo" })
197+ assert .Nil (t , err )
198+ }
199+
200+ func TestCloseVulnerabilityIssueNoIssue (t * testing.T ) {
201+ mockClient := mockService {}
202+ mockClient .On ("ListRepositoryIssues" , mock .Anything , mock .Anything , mock .Anything ).Return (nil , & github.Response {}, nil )
203+
204+ svc := githubService {client : & mockClient }
205+
206+ err := svc .CloseVulnerabilityIssue (repository.Project {GroupOrOwner : "group" , Name : "repo" })
207+ assert .Nil (t , err )
208+ }
209+
210+ type mockService struct {
211+ mock.Mock
212+ }
213+
214+ func (c * mockService ) GetRepository (owner string , repo string ) (* github.Repository , * github.Response , error ) {
215+ args := c .Called (owner , repo )
216+ var r * github.Response
217+ if resp := args .Get (1 ); resp != nil {
218+ r = args .Get (1 ).(* github.Response )
219+ }
220+ return args .Get (0 ).(* github.Repository ), r , args .Error (2 )
221+ }
222+
223+ func (c * mockService ) GetOrganizationRepositories (org string , opts * github.RepositoryListByOrgOptions ) ([]* github.Repository , * github.Response , error ) {
224+ args := c .Called (org , opts )
225+ var r * github.Response
226+ if resp := args .Get (1 ); resp != nil {
227+ r = args .Get (1 ).(* github.Response )
228+ }
229+ return args .Get (0 ).([]* github.Repository ), r , args .Error (2 )
230+ }
231+
232+ func (c * mockService ) GetUserRepositories (user string , opts * github.RepositoryListByUserOptions ) ([]* github.Repository , * github.Response , error ) {
233+ args := c .Called (user , opts )
234+ var r * github.Response
235+ if resp := args .Get (1 ); resp != nil {
236+ r = args .Get (1 ).(* github.Response )
237+ }
238+ return args .Get (0 ).([]* github.Repository ), r , args .Error (2 )
239+ }
240+
241+ func (c * mockService ) GetArchiveLink (owner string , repo string , archiveFormat github.ArchiveFormat , opts * github.RepositoryContentGetOptions ) (* url.URL , * github.Response , error ) {
242+ args := c .Called (owner , repo , archiveFormat , opts )
243+ var r * github.Response
244+ if resp := args .Get (1 ); resp != nil {
245+ r = args .Get (1 ).(* github.Response )
246+ }
247+ return args .Get (0 ).(* url.URL ), r , args .Error (2 )
248+ }
249+
250+ func (c * mockService ) ListRepositoryIssues (owner , repo string , opts * github.IssueListByRepoOptions ) ([]* github.Issue , * github.Response , error ) {
251+ args := c .Called (owner , repo , opts )
252+ var r * github.Response
253+ if resp := args .Get (1 ); resp != nil {
254+ r = args .Get (1 ).(* github.Response )
255+ }
256+ if args .Get (0 ) == nil {
257+ return nil , r , args .Error (2 )
258+ }
259+ return args .Get (0 ).([]* github.Issue ), r , args .Error (2 )
260+ }
261+
262+ func (c * mockService ) CreateIssue (owner , repo string , issue * github.IssueRequest ) (* github.Issue , * github.Response , error ) {
263+ args := c .Called (owner , repo )
264+ var r * github.Response
265+ if resp := args .Get (1 ); resp != nil {
266+ r = args .Get (1 ).(* github.Response )
267+ }
268+ return args .Get (0 ).(* github.Issue ), r , args .Error (2 )
269+ }
270+
271+ func (c * mockService ) UpdateIssue (owner string , repo string , number int , issue * github.IssueRequest ) (* github.Issue , * github.Response , error ) {
272+ args := c .Called (owner , repo )
273+ var r * github.Response
274+ if resp := args .Get (1 ); resp != nil {
275+ r = args .Get (1 ).(* github.Response )
276+ }
277+ return args .Get (0 ).(* github.Issue ), r , args .Error (2 )
278+ }
0 commit comments