99 "github.com/github/github-mcp-server/internal/toolsnaps"
1010 "github.com/github/github-mcp-server/pkg/translations"
1111 "github.com/google/go-github/v79/github"
12- "github.com/migueleliasweb/go-github-mock/src/mock"
1312 "github.com/stretchr/testify/assert"
1413 "github.com/stretchr/testify/require"
1514)
@@ -42,12 +41,9 @@ func Test_GetDependabotAlert(t *testing.T) {
4241 }{
4342 {
4443 name : "successful alert fetch" ,
45- mockedClient : mock .NewMockedHTTPClient (
46- mock .WithRequestMatch (
47- mock .GetReposDependabotAlertsByOwnerByRepoByAlertNumber ,
48- mockAlert ,
49- ),
50- ),
44+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
45+ GetReposDependabotAlertsByOwnerByRepoByAlertNumber : mockResponse (t , http .StatusOK , mockAlert ),
46+ }),
5147 requestArgs : map [string ]interface {}{
5248 "owner" : "owner" ,
5349 "repo" : "repo" ,
@@ -58,15 +54,12 @@ func Test_GetDependabotAlert(t *testing.T) {
5854 },
5955 {
6056 name : "alert fetch fails" ,
61- mockedClient : mock .NewMockedHTTPClient (
62- mock .WithRequestMatchHandler (
63- mock .GetReposDependabotAlertsByOwnerByRepoByAlertNumber ,
64- http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
65- w .WriteHeader (http .StatusNotFound )
66- _ , _ = w .Write ([]byte (`{"message": "Not Found"}` ))
67- }),
68- ),
69- ),
57+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
58+ GetReposDependabotAlertsByOwnerByRepoByAlertNumber : http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
59+ w .WriteHeader (http .StatusNotFound )
60+ _ , _ = w .Write ([]byte (`{"message": "Not Found"}` ))
61+ }),
62+ }),
7063 requestArgs : map [string ]interface {}{
7164 "owner" : "owner" ,
7265 "repo" : "repo" ,
@@ -154,16 +147,13 @@ func Test_ListDependabotAlerts(t *testing.T) {
154147 }{
155148 {
156149 name : "successful open alerts listing" ,
157- mockedClient : mock .NewMockedHTTPClient (
158- mock .WithRequestMatchHandler (
159- mock .GetReposDependabotAlertsByOwnerByRepo ,
160- expectQueryParams (t , map [string ]string {
161- "state" : "open" ,
162- }).andThen (
163- mockResponse (t , http .StatusOK , []* github.DependabotAlert {& criticalAlert }),
164- ),
150+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
151+ GetReposDependabotAlertsByOwnerByRepo : expectQueryParams (t , map [string ]string {
152+ "state" : "open" ,
153+ }).andThen (
154+ mockResponse (t , http .StatusOK , []* github.DependabotAlert {& criticalAlert }),
165155 ),
166- ),
156+ } ),
167157 requestArgs : map [string ]interface {}{
168158 "owner" : "owner" ,
169159 "repo" : "repo" ,
@@ -174,16 +164,13 @@ func Test_ListDependabotAlerts(t *testing.T) {
174164 },
175165 {
176166 name : "successful severity filtered listing" ,
177- mockedClient : mock .NewMockedHTTPClient (
178- mock .WithRequestMatchHandler (
179- mock .GetReposDependabotAlertsByOwnerByRepo ,
180- expectQueryParams (t , map [string ]string {
181- "severity" : "high" ,
182- }).andThen (
183- mockResponse (t , http .StatusOK , []* github.DependabotAlert {& highSeverityAlert }),
184- ),
167+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
168+ GetReposDependabotAlertsByOwnerByRepo : expectQueryParams (t , map [string ]string {
169+ "severity" : "high" ,
170+ }).andThen (
171+ mockResponse (t , http .StatusOK , []* github.DependabotAlert {& highSeverityAlert }),
185172 ),
186- ),
173+ } ),
187174 requestArgs : map [string ]interface {}{
188175 "owner" : "owner" ,
189176 "repo" : "repo" ,
@@ -194,14 +181,11 @@ func Test_ListDependabotAlerts(t *testing.T) {
194181 },
195182 {
196183 name : "successful all alerts listing" ,
197- mockedClient : mock .NewMockedHTTPClient (
198- mock .WithRequestMatchHandler (
199- mock .GetReposDependabotAlertsByOwnerByRepo ,
200- expectQueryParams (t , map [string ]string {}).andThen (
201- mockResponse (t , http .StatusOK , []* github.DependabotAlert {& criticalAlert , & highSeverityAlert }),
202- ),
184+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
185+ GetReposDependabotAlertsByOwnerByRepo : expectQueryParams (t , map [string ]string {}).andThen (
186+ mockResponse (t , http .StatusOK , []* github.DependabotAlert {& criticalAlert , & highSeverityAlert }),
203187 ),
204- ),
188+ } ),
205189 requestArgs : map [string ]interface {}{
206190 "owner" : "owner" ,
207191 "repo" : "repo" ,
@@ -211,15 +195,12 @@ func Test_ListDependabotAlerts(t *testing.T) {
211195 },
212196 {
213197 name : "alerts listing fails" ,
214- mockedClient : mock .NewMockedHTTPClient (
215- mock .WithRequestMatchHandler (
216- mock .GetReposDependabotAlertsByOwnerByRepo ,
217- http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
218- w .WriteHeader (http .StatusUnauthorized )
219- _ , _ = w .Write ([]byte (`{"message": "Unauthorized access"}` ))
220- }),
221- ),
222- ),
198+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
199+ GetReposDependabotAlertsByOwnerByRepo : http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
200+ w .WriteHeader (http .StatusUnauthorized )
201+ _ , _ = w .Write ([]byte (`{"message": "Unauthorized access"}` ))
202+ }),
203+ }),
223204 requestArgs : map [string ]interface {}{
224205 "owner" : "owner" ,
225206 "repo" : "repo" ,
0 commit comments