Skip to content

Commit 3bd9374

Browse files
Merge branch 'main' into actions-consolidation-ff
2 parents c294bd9 + 9bf5076 commit 3bd9374

File tree

10 files changed

+783
-917
lines changed

10 files changed

+783
-917
lines changed

pkg/github/actions_test.go

Lines changed: 240 additions & 307 deletions
Large diffs are not rendered by default.

pkg/github/context_tools_test.go

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/github/github-mcp-server/internal/toolsnaps"
1212
"github.com/github/github-mcp-server/pkg/translations"
1313
"github.com/google/go-github/v79/github"
14-
"github.com/migueleliasweb/go-github-mock/src/mock"
1514
"github.com/shurcooL/githubv4"
1615
"github.com/stretchr/testify/assert"
1716
"github.com/stretchr/testify/require"
@@ -57,24 +56,18 @@ func Test_GetMe(t *testing.T) {
5756
}{
5857
{
5958
name: "successful get user",
60-
mockedClient: mock.NewMockedHTTPClient(
61-
mock.WithRequestMatch(
62-
mock.GetUser,
63-
mockUser,
64-
),
65-
),
59+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
60+
GetUser: mockResponse(t, http.StatusOK, mockUser),
61+
}),
6662
requestArgs: map[string]any{},
6763
expectToolError: false,
6864
expectedUser: mockUser,
6965
},
7066
{
7167
name: "successful get user with reason",
72-
mockedClient: mock.NewMockedHTTPClient(
73-
mock.WithRequestMatch(
74-
mock.GetUser,
75-
mockUser,
76-
),
77-
),
68+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
69+
GetUser: mockResponse(t, http.StatusOK, mockUser),
70+
}),
7871
requestArgs: map[string]any{
7972
"reason": "Testing API",
8073
},
@@ -90,12 +83,9 @@ func Test_GetMe(t *testing.T) {
9083
},
9184
{
9285
name: "get user fails",
93-
mockedClient: mock.NewMockedHTTPClient(
94-
mock.WithRequestMatchHandler(
95-
mock.GetUser,
96-
badRequestHandler("expected test failure"),
97-
),
98-
),
86+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
87+
GetUser: badRequestHandler("expected test failure"),
88+
}),
9989
requestArgs: map[string]any{},
10090
expectToolError: true,
10191
expectedToolErrMsg: "expected test failure",
@@ -255,21 +245,15 @@ func Test_GetTeams(t *testing.T) {
255245

256246
// Factory function for mock HTTP clients with user response
257247
httpClientWithUser := func() *http.Client {
258-
return mock.NewMockedHTTPClient(
259-
mock.WithRequestMatch(
260-
mock.GetUser,
261-
mockUser,
262-
),
263-
)
248+
return MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
249+
GetUser: mockResponse(t, http.StatusOK, mockUser),
250+
})
264251
}
265252

266253
httpClientUserFails := func() *http.Client {
267-
return mock.NewMockedHTTPClient(
268-
mock.WithRequestMatchHandler(
269-
mock.GetUser,
270-
badRequestHandler("expected test failure"),
271-
),
272-
)
254+
return MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
255+
GetUser: badRequestHandler("expected test failure"),
256+
})
273257
}
274258

275259
tests := []struct {

pkg/github/dependabot_test.go

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
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

Comments
 (0)