Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a42d7a

Browse files
CopilotJoannaaKL
andauthored
Chore: Add testify-based HTTP mocking infrastructure and pilot migration (#1606)
* Initial plan* Add testify/mock-based HTTP mocking infrastructure and migrate git_test.go- Add MockHTTPClientWithHandlers helper function for HTTP-level mocking- Add path pattern matching support for GitHub API endpoints- Migrate pkg/github/git_test.go from go-github-mock to new infrastructure- Keep go-github-mock dependency for now (other files still use it)Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>* Complete pilot migration and add migration documentation- Migrate pkg/github/code_scanning_test.go to new infrastructure- Add comprehensive migration documentation in docs/testing-migration.md- Fix linter warning in helper_test.go- All tests and lint checks pass- 2 of 16 test files migrated, 14 remaining for incremental migrationCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>* Address code review feedback: consolidate transport implementations- Remove unused OnAny method- Extract executeHandler helper to eliminate code duplication- Consolidate MockHTTPClientWithHandler to use MockHTTPClientWithHandlers- Simplify transport implementation (single multiHandlerTransport)- All tests and lint checks passCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>* Remove docs/testing-migration.md per review feedbackCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>* Reuse mock.EndpointPattern constants instead of hardcoded paths- Add mock import to code_scanning_test.go and git_test.go- Replace hardcoded paths with mock.GetRepos*.Pattern references- Ensures consistency with existing test patterns and easier maintenanceCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>* Define endpoint path constants in this repo instead of reusing go-github-mock- Add endpoint pattern constants to helper_test.go- Update code_scanning_test.go to use new constants- Update git_test.go to use new constants- Removes dependency on go-github-mock endpoint patterns- Prepares for eventual removal of go-github-mock dependencyCo-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>---------Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>Co-authored-by: JoannaaKL <joannaakl@github.com>
1 parenta897d70 commit5a42d7a

File tree

5 files changed

+275
-80
lines changed

5 files changed

+275
-80
lines changed

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/gorilla/muxv1.8.0// indirect
2424
github.com/josharian/internv1.0.0// indirect
2525
github.com/mailru/easyjsonv0.7.7// indirect
26+
github.com/stretchr/objxv0.5.2// indirect
2627
github.com/yudai/golcsv0.0.0-20170316035057-ecda9a501e82// indirect
2728
go.yaml.in/yaml/v3v3.0.4// indirect
2829
golang.org/x/expv0.0.0-20240719175910-8a7402abbf56// indirect

‎go.sum‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3A
8888
github.com/spf13/viperv1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
8989
github.com/spf13/viperv1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
9090
github.com/stretchr/objxv0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
91+
github.com/stretchr/objxv0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
92+
github.com/stretchr/objxv0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
9193
github.com/stretchr/testifyv1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
9294
github.com/stretchr/testifyv1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
9395
github.com/stretchr/testifyv1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=

‎pkg/github/code_scanning_test.go‎

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/github/github-mcp-server/pkg/translations"
1111
"github.com/google/go-github/v79/github"
1212
"github.com/google/jsonschema-go/jsonschema"
13-
"github.com/migueleliasweb/go-github-mock/src/mock"
1413
"github.com/stretchr/testify/assert"
1514
"github.com/stretchr/testify/require"
1615
)
@@ -50,12 +49,9 @@ func Test_GetCodeScanningAlert(t *testing.T) {
5049
}{
5150
{
5251
name:"successful alert fetch",
53-
mockedClient:mock.NewMockedHTTPClient(
54-
mock.WithRequestMatch(
55-
mock.GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber,
56-
mockAlert,
57-
),
58-
),
52+
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
53+
GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber:mockResponse(t,http.StatusOK,mockAlert),
54+
}),
5955
requestArgs:map[string]interface{}{
6056
"owner":"owner",
6157
"repo":"repo",
@@ -66,15 +62,12 @@ func Test_GetCodeScanningAlert(t *testing.T) {
6662
},
6763
{
6864
name:"alert fetch fails",
69-
mockedClient:mock.NewMockedHTTPClient(
70-
mock.WithRequestMatchHandler(
71-
mock.GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber,
72-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
73-
w.WriteHeader(http.StatusNotFound)
74-
_,_=w.Write([]byte(`{"message": "Not Found"}`))
75-
}),
76-
),
77-
),
65+
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
66+
GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
67+
w.WriteHeader(http.StatusNotFound)
68+
_,_=w.Write([]byte(`{"message": "Not Found"}`))
69+
}),
70+
}),
7871
requestArgs:map[string]interface{}{
7972
"owner":"owner",
8073
"repo":"repo",
@@ -171,19 +164,16 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
171164
}{
172165
{
173166
name:"successful alerts listing",
174-
mockedClient:mock.NewMockedHTTPClient(
175-
mock.WithRequestMatchHandler(
176-
mock.GetReposCodeScanningAlertsByOwnerByRepo,
177-
expectQueryParams(t,map[string]string{
178-
"ref":"main",
179-
"state":"open",
180-
"severity":"high",
181-
"tool_name":"codeql",
182-
}).andThen(
183-
mockResponse(t,http.StatusOK,mockAlerts),
184-
),
167+
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
168+
GetReposCodeScanningAlertsByOwnerByRepo:expectQueryParams(t,map[string]string{
169+
"ref":"main",
170+
"state":"open",
171+
"severity":"high",
172+
"tool_name":"codeql",
173+
}).andThen(
174+
mockResponse(t,http.StatusOK,mockAlerts),
185175
),
186-
),
176+
}),
187177
requestArgs:map[string]interface{}{
188178
"owner":"owner",
189179
"repo":"repo",
@@ -197,15 +187,12 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
197187
},
198188
{
199189
name:"alerts listing fails",
200-
mockedClient:mock.NewMockedHTTPClient(
201-
mock.WithRequestMatchHandler(
202-
mock.GetReposCodeScanningAlertsByOwnerByRepo,
203-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
204-
w.WriteHeader(http.StatusUnauthorized)
205-
_,_=w.Write([]byte(`{"message": "Unauthorized access"}`))
206-
}),
207-
),
208-
),
190+
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
191+
GetReposCodeScanningAlertsByOwnerByRepo:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
192+
w.WriteHeader(http.StatusUnauthorized)
193+
_,_=w.Write([]byte(`{"message": "Unauthorized access"}`))
194+
}),
195+
}),
209196
requestArgs:map[string]interface{}{
210197
"owner":"owner",
211198
"repo":"repo",

‎pkg/github/git_test.go‎

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/github/github-mcp-server/pkg/translations"
1212
"github.com/google/go-github/v79/github"
1313
"github.com/google/jsonschema-go/jsonschema"
14-
"github.com/migueleliasweb/go-github-mock/src/mock"
1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
1716
)
@@ -71,33 +70,21 @@ func Test_GetRepositoryTree(t *testing.T) {
7170
}{
7271
{
7372
name:"successfully get repository tree",
74-
mockedClient:mock.NewMockedHTTPClient(
75-
mock.WithRequestMatchHandler(
76-
mock.GetReposByOwnerByRepo,
77-
mockResponse(t,http.StatusOK,mockRepo),
78-
),
79-
mock.WithRequestMatchHandler(
80-
mock.GetReposGitTreesByOwnerByRepoByTreeSha,
81-
mockResponse(t,http.StatusOK,mockTree),
82-
),
83-
),
73+
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
74+
GetReposByOwnerByRepo:mockResponse(t,http.StatusOK,mockRepo),
75+
GetReposGitTreesByOwnerByRepoByTree:mockResponse(t,http.StatusOK,mockTree),
76+
}),
8477
requestArgs:map[string]interface{}{
8578
"owner":"owner",
8679
"repo":"repo",
8780
},
8881
},
8982
{
9083
name:"successfully get repository tree with path filter",
91-
mockedClient:mock.NewMockedHTTPClient(
92-
mock.WithRequestMatchHandler(
93-
mock.GetReposByOwnerByRepo,
94-
mockResponse(t,http.StatusOK,mockRepo),
95-
),
96-
mock.WithRequestMatchHandler(
97-
mock.GetReposGitTreesByOwnerByRepoByTreeSha,
98-
mockResponse(t,http.StatusOK,mockTree),
99-
),
100-
),
84+
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
85+
GetReposByOwnerByRepo:mockResponse(t,http.StatusOK,mockRepo),
86+
GetReposGitTreesByOwnerByRepoByTree:mockResponse(t,http.StatusOK,mockTree),
87+
}),
10188
requestArgs:map[string]interface{}{
10289
"owner":"owner",
10390
"repo":"repo",
@@ -106,15 +93,12 @@ func Test_GetRepositoryTree(t *testing.T) {
10693
},
10794
{
10895
name:"repository not found",
109-
mockedClient:mock.NewMockedHTTPClient(
110-
mock.WithRequestMatchHandler(
111-
mock.GetReposByOwnerByRepo,
112-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
113-
w.WriteHeader(http.StatusNotFound)
114-
_,_=w.Write([]byte(`{"message": "Not Found"}`))
115-
}),
116-
),
117-
),
96+
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
97+
GetReposByOwnerByRepo:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
98+
w.WriteHeader(http.StatusNotFound)
99+
_,_=w.Write([]byte(`{"message": "Not Found"}`))
100+
}),
101+
}),
118102
requestArgs:map[string]interface{}{
119103
"owner":"owner",
120104
"repo":"nonexistent",
@@ -124,19 +108,13 @@ func Test_GetRepositoryTree(t *testing.T) {
124108
},
125109
{
126110
name:"tree not found",
127-
mockedClient:mock.NewMockedHTTPClient(
128-
mock.WithRequestMatchHandler(
129-
mock.GetReposByOwnerByRepo,
130-
mockResponse(t,http.StatusOK,mockRepo),
131-
),
132-
mock.WithRequestMatchHandler(
133-
mock.GetReposGitTreesByOwnerByRepoByTreeSha,
134-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
135-
w.WriteHeader(http.StatusNotFound)
136-
_,_=w.Write([]byte(`{"message": "Not Found"}`))
137-
}),
138-
),
139-
),
111+
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
112+
GetReposByOwnerByRepo:mockResponse(t,http.StatusOK,mockRepo),
113+
GetReposGitTreesByOwnerByRepoByTree:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
114+
w.WriteHeader(http.StatusNotFound)
115+
_,_=w.Write([]byte(`{"message": "Not Found"}`))
116+
}),
117+
}),
140118
requestArgs:map[string]interface{}{
141119
"owner":"owner",
142120
"repo":"repo",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp