Skip to content

Commit d485855

Browse files
CopilotJoannaaKL
andcommitted
Replace go-github-mock usage in tests with shared HTTP mock helper
Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
1 parent 4f622c9 commit d485855

4 files changed

Lines changed: 67 additions & 262 deletions

File tree

pkg/github/actions_test.go

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ import (
1515
"github.com/github/github-mcp-server/internal/profiler"
1616
"github.com/github/github-mcp-server/internal/toolsnaps"
1717
buffer "github.com/github/github-mcp-server/pkg/buffer"
18-
mock "github.com/github/github-mcp-server/pkg/github/testmock"
1918
"github.com/github/github-mcp-server/pkg/translations"
2019
"github.com/google/go-github/v79/github"
2120
"github.com/google/jsonschema-go/jsonschema"
2221
"github.com/stretchr/testify/assert"
2322
"github.com/stretchr/testify/require"
2423
)
2524

25+
func newMockedHTTPClient(handlers map[string]http.HandlerFunc) *http.Client {
26+
return MockHTTPClientWithHandlers(handlers)
27+
}
28+
2629
func Test_ListWorkflows(t *testing.T) {
2730
// Verify tool definition once
2831
toolDef := ListWorkflows(translations.NullTranslationHelper)
@@ -1394,17 +1397,11 @@ func Test_RerunFailedJobs(t *testing.T) {
13941397
}{
13951398
{
13961399
name: "successful rerun of failed jobs",
1397-
mockedClient: mock.NewMockedHTTPClient(
1398-
mock.WithRequestMatchHandler(
1399-
mock.EndpointPattern{
1400-
Pattern: "/repos/owner/repo/actions/runs/12345/rerun-failed-jobs",
1401-
Method: "POST",
1402-
},
1403-
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
1404-
w.WriteHeader(http.StatusCreated)
1405-
}),
1406-
),
1407-
),
1400+
mockedClient: newMockedHTTPClient(map[string]http.HandlerFunc{
1401+
"POST /repos/owner/repo/actions/runs/12345/rerun-failed-jobs": http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
1402+
w.WriteHeader(http.StatusCreated)
1403+
}),
1404+
}),
14081405
requestArgs: map[string]any{
14091406
"owner": "owner",
14101407
"repo": "repo",
@@ -1414,7 +1411,7 @@ func Test_RerunFailedJobs(t *testing.T) {
14141411
},
14151412
{
14161413
name: "missing required parameter run_id",
1417-
mockedClient: mock.NewMockedHTTPClient(),
1414+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
14181415
requestArgs: map[string]any{
14191416
"owner": "owner",
14201417
"repo": "repo",
@@ -1486,7 +1483,7 @@ func Test_RerunWorkflowRun_Behavioral(t *testing.T) {
14861483
},
14871484
{
14881485
name: "missing required parameter run_id",
1489-
mockedClient: mock.NewMockedHTTPClient(),
1486+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
14901487
requestArgs: map[string]any{
14911488
"owner": "owner",
14921489
"repo": "repo",
@@ -1573,7 +1570,7 @@ func Test_ListWorkflowRuns_Behavioral(t *testing.T) {
15731570
},
15741571
{
15751572
name: "missing required parameter workflow_id",
1576-
mockedClient: mock.NewMockedHTTPClient(),
1573+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
15771574
requestArgs: map[string]any{
15781575
"owner": "owner",
15791576
"repo": "repo",
@@ -1649,7 +1646,7 @@ func Test_GetWorkflowRun_Behavioral(t *testing.T) {
16491646
},
16501647
{
16511648
name: "missing required parameter run_id",
1652-
mockedClient: mock.NewMockedHTTPClient(),
1649+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
16531650
requestArgs: map[string]any{
16541651
"owner": "owner",
16551652
"repo": "repo",
@@ -1719,7 +1716,7 @@ func Test_GetWorkflowRunLogs_Behavioral(t *testing.T) {
17191716
},
17201717
{
17211718
name: "missing required parameter run_id",
1722-
mockedClient: mock.NewMockedHTTPClient(),
1719+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
17231720
requestArgs: map[string]any{
17241721
"owner": "owner",
17251722
"repo": "repo",
@@ -1806,7 +1803,7 @@ func Test_ListWorkflowJobs_Behavioral(t *testing.T) {
18061803
},
18071804
{
18081805
name: "missing required parameter run_id",
1809-
mockedClient: mock.NewMockedHTTPClient(),
1806+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
18101807
requestArgs: map[string]any{
18111808
"owner": "owner",
18121809
"repo": "repo",
@@ -1908,7 +1905,7 @@ func Test_ActionsList_ListWorkflows(t *testing.T) {
19081905
},
19091906
{
19101907
name: "missing required parameter method",
1911-
mockedClient: mock.NewMockedHTTPClient(),
1908+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
19121909
requestArgs: map[string]any{
19131910
"owner": "owner",
19141911
"repo": "repo",
@@ -2204,7 +2201,7 @@ func Test_ActionsRunTrigger_RunWorkflow(t *testing.T) {
22042201
},
22052202
{
22062203
name: "missing required parameter workflow_id",
2207-
mockedClient: mock.NewMockedHTTPClient(),
2204+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
22082205
requestArgs: map[string]any{
22092206
"method": "run_workflow",
22102207
"owner": "owner",
@@ -2216,7 +2213,7 @@ func Test_ActionsRunTrigger_RunWorkflow(t *testing.T) {
22162213
},
22172214
{
22182215
name: "missing required parameter ref",
2219-
mockedClient: mock.NewMockedHTTPClient(),
2216+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
22202217
requestArgs: map[string]any{
22212218
"method": "run_workflow",
22222219
"owner": "owner",
@@ -2332,7 +2329,7 @@ func Test_ActionsRunTrigger_CancelWorkflowRun(t *testing.T) {
23322329
})
23332330

23342331
t.Run("missing run_id for non-run_workflow methods", func(t *testing.T) {
2335-
mockedClient := mock.NewMockedHTTPClient()
2332+
mockedClient := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{})
23362333

23372334
client := github.NewClient(mockedClient)
23382335
deps := BaseDeps{

pkg/github/issues_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/github/github-mcp-server/internal/githubv4mock"
1515
"github.com/github/github-mcp-server/internal/toolsnaps"
16-
mock "github.com/github/github-mcp-server/pkg/github/testmock"
1716
"github.com/github/github-mcp-server/pkg/lockdown"
1817
"github.com/github/github-mcp-server/pkg/translations"
1918
"github.com/google/go-github/v79/github"
@@ -23,6 +22,10 @@ import (
2322
"github.com/stretchr/testify/require"
2423
)
2524

25+
func newMockedHTTPClient(handlers map[string]http.HandlerFunc) *http.Client {
26+
return MockHTTPClientWithHandlers(handlers)
27+
}
28+
2629
var defaultGQLClient *githubv4.Client = githubv4.NewClient(newRepoAccessHTTPClient())
2730
var repoAccessCache *lockdown.RepoAccessCache = stubRepoAccessCache(defaultGQLClient, 15*time.Minute)
2831

@@ -1438,7 +1441,7 @@ func Test_UpdateIssue(t *testing.T) {
14381441
),
14391442
),
14401443
),
1441-
mockedGQLClient: githubv4mock.NewMockedHTTPClient(),
1444+
mockedGQLClient: githubv4MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
14421445
requestArgs: map[string]interface{}{
14431446
"method": "update",
14441447
"owner": "owner",
@@ -1461,7 +1464,7 @@ func Test_UpdateIssue(t *testing.T) {
14611464
}),
14621465
),
14631466
),
1464-
mockedGQLClient: githubv4mock.NewMockedHTTPClient(),
1467+
mockedGQLClient: githubv4MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
14651468
requestArgs: map[string]interface{}{
14661469
"method": "update",
14671470
"owner": "owner",
@@ -1748,8 +1751,8 @@ func Test_UpdateIssue(t *testing.T) {
17481751
},
17491752
{
17501753
name: "duplicate_of without duplicate state_reason should fail",
1751-
mockedRESTClient: mock.NewMockedHTTPClient(),
1752-
mockedGQLClient: githubv4mock.NewMockedHTTPClient(),
1754+
mockedRESTClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
1755+
mockedGQLClient: githubv4MockHTTPClientWithHandlers(map[string]http.HandlerFunc{}),
17531756
requestArgs: map[string]interface{}{
17541757
"method": "update",
17551758
"owner": "owner",

0 commit comments

Comments
 (0)