Skip to content

Commit 20c45d9

Browse files
committed
Final removal
1 parent c85cbf3 commit 20c45d9

File tree

15 files changed

+728
-1026
lines changed

15 files changed

+728
-1026
lines changed

docs/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project uses a combination of unit tests and end-to-end (e2e) tests to ensu
77
- Unit tests are located alongside implementation, with filenames ending in `_test.go`.
88
- Currently the preference is to use internal tests i.e. test files do not have `_test` package suffix.
99
- Tests use [testify](https://github.com/stretchr/testify) for assertions and require statements. Use `require` when continuing the test is not meaningful, for example it is almost never correct to continue after an error expectation.
10-
- Mocking is performed using [go-github-mock](https://github.com/migueleliasweb/go-github-mock) or `githubv4mock` for simulating GitHub rest and GQL API responses.
10+
- REST mocking is performed with the in-repo `MockHTTPClientWithHandlers` helpers; GraphQL mocking uses `githubv4mock`.
1111
- Each tool's schema is snapshotted and checked for changes using the `toolsnaps` utility (see below).
1212
- Tests are designed to be explicit and verbose to aid maintainability and clarity.
1313
- Handler unit tests should take the form of:

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/google/jsonschema-go v0.4.2
88
github.com/josephburnett/jd v1.9.2
99
github.com/microcosm-cc/bluemonday v1.0.27
10-
github.com/migueleliasweb/go-github-mock v1.3.0
1110
github.com/muesli/cache2go v0.0.0-20221011235721-518229cd8021
1211
github.com/spf13/cobra v1.10.2
1312
github.com/spf13/viper v1.21.0
@@ -18,9 +17,7 @@ require (
1817
github.com/aymerick/douceur v0.2.0 // indirect
1918
github.com/go-openapi/jsonpointer v0.19.5 // indirect
2019
github.com/go-openapi/swag v0.21.1 // indirect
21-
github.com/google/go-github/v71 v71.0.0 // indirect
2220
github.com/gorilla/css v1.0.1 // indirect
23-
github.com/gorilla/mux v1.8.0 // indirect
2421
github.com/josharian/intern v1.0.0 // indirect
2522
github.com/mailru/easyjson v0.7.7 // indirect
2623
github.com/stretchr/objx v0.5.2 // indirect
@@ -53,7 +50,6 @@ require (
5350
golang.org/x/oauth2 v0.30.0 // indirect
5451
golang.org/x/sys v0.31.0 // indirect
5552
golang.org/x/text v0.28.0 // indirect
56-
golang.org/x/time v0.5.0 // indirect
5753
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
5854
gopkg.in/yaml.v3 v3.0.1 // indirect
5955
)

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVI
2222
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2323
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
2424
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
25-
github.com/google/go-github/v71 v71.0.0 h1:Zi16OymGKZZMm8ZliffVVJ/Q9YZreDKONCr+WUd0Z30=
26-
github.com/google/go-github/v71 v71.0.0/go.mod h1:URZXObp2BLlMjwu0O8g4y6VBneUj2bCHgnI8FfgZ51M=
2725
github.com/google/go-github/v79 v79.0.0 h1:MdodQojuFPBhmtwHiBcIGLw/e/wei2PvFX9ndxK0X4Y=
2826
github.com/google/go-github/v79 v79.0.0/go.mod h1:OAFbNhq7fQwohojb06iIIQAB9CBGYLq999myfUFnrS4=
2927
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
@@ -32,8 +30,6 @@ github.com/google/jsonschema-go v0.4.2 h1:tmrUohrwoLZZS/P3x7ex0WAVknEkBZM46iALbc
3230
github.com/google/jsonschema-go v0.4.2/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
3331
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
3432
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
35-
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
36-
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
3733
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3834
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
3935
github.com/josephburnett/jd v1.9.2 h1:ECJRRFXCCqbtidkAHckHGSZm/JIaAxS1gygHLF8MI5Y=
@@ -55,8 +51,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
5551
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
5652
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
5753
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
58-
github.com/migueleliasweb/go-github-mock v1.3.0 h1:2sVP9JEMB2ubQw1IKto3/fzF51oFC6eVWOOFDgQoq88=
59-
github.com/migueleliasweb/go-github-mock v1.3.0/go.mod h1:ipQhV8fTcj/G6m7BKzin08GaJ/3B5/SonRAkgrk0zCY=
6054
github.com/modelcontextprotocol/go-sdk v1.2.0 h1:Y23co09300CEk8iZ/tMxIX1dVmKZkzoSBZOpJwUnc/s=
6155
github.com/modelcontextprotocol/go-sdk v1.2.0/go.mod h1:6fM3LCm3yV7pAs8isnKLn07oKtB0MP9LHd3DfAcKw10=
6256
github.com/muesli/cache2go v0.0.0-20221011235721-518229cd8021 h1:31Y+Yu373ymebRdJN1cWLLooHH8xAr0MhKTEJGV/87g=
@@ -114,8 +108,6 @@ golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
114108
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
115109
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
116110
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
117-
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
118-
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
119111
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
120112
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
121113
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

pkg/github/helper_test.go

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/modelcontextprotocol/go-sdk/mcp"
1313
"github.com/stretchr/testify/assert"
14-
"github.com/stretchr/testify/mock"
14+
testifymock "github.com/stretchr/testify/mock"
1515
"github.com/stretchr/testify/require"
1616
)
1717

@@ -41,9 +41,9 @@ const (
4141

4242
// Git endpoints
4343
GetReposGitTreesByOwnerByRepoByTree = "GET /repos/{owner}/{repo}/git/trees/{tree}"
44-
GetReposGitRefByOwnerByRepoByRef = "GET /repos/{owner}/{repo}/git/ref/{ref}"
44+
GetReposGitRefByOwnerByRepoByRef = "GET /repos/{owner}/{repo}/git/ref/{ref:.*}"
4545
PostReposGitRefsByOwnerByRepo = "POST /repos/{owner}/{repo}/git/refs"
46-
PatchReposGitRefsByOwnerByRepoByRef = "PATCH /repos/{owner}/{repo}/git/refs/{ref}"
46+
PatchReposGitRefsByOwnerByRepoByRef = "PATCH /repos/{owner}/{repo}/git/refs/{ref:.*}"
4747
GetReposGitCommitsByOwnerByRepoByCommitSHA = "GET /repos/{owner}/{repo}/git/commits/{commit_sha}"
4848
PostReposGitCommitsByOwnerByRepo = "POST /repos/{owner}/{repo}/git/commits"
4949
GetReposGitTagsByOwnerByRepoByTagSHA = "GET /repos/{owner}/{repo}/git/tags/{tag_sha}"
@@ -133,8 +133,8 @@ const (
133133
// Search endpoints
134134
GetSearchCode = "GET /search/code"
135135
GetSearchIssues = "GET /search/issues"
136-
GetSearchRepositories = "GET /search/repositories"
137136
GetSearchUsers = "GET /search/users"
137+
GetSearchRepositories = "GET /search/repositories"
138138

139139
// Raw content endpoints (used for GitHub raw content API, not standard API)
140140
// These are used with the raw content client that interacts with raw.githubusercontent.com
@@ -434,7 +434,7 @@ func getResourceResult(t *testing.T, result *mcp.CallToolResult) *mcp.ResourceCo
434434

435435
// MockRoundTripper is a mock HTTP transport using testify/mock
436436
type MockRoundTripper struct {
437-
mock.Mock
437+
testifymock.Mock
438438
handlers map[string]http.HandlerFunc
439439
}
440440

@@ -590,6 +590,64 @@ func MockHTTPClientWithHandlers(handlers map[string]http.HandlerFunc) *http.Clie
590590
return &http.Client{Transport: transport}
591591
}
592592

593+
// Compatibility helpers to replace github.com/migueleliasweb/go-github-mock in tests
594+
type EndpointPattern string
595+
596+
type MockBackendOption func(map[string]http.HandlerFunc)
597+
598+
func parseEndpointPattern(p EndpointPattern) (string, string) {
599+
parts := strings.SplitN(string(p), " ", 2)
600+
if len(parts) != 2 {
601+
return http.MethodGet, string(p)
602+
}
603+
return parts[0], parts[1]
604+
}
605+
606+
func WithRequestMatch(pattern EndpointPattern, response any) MockBackendOption {
607+
return func(handlers map[string]http.HandlerFunc) {
608+
method, path := parseEndpointPattern(pattern)
609+
handlers[method+" "+path] = func(w http.ResponseWriter, _ *http.Request) {
610+
w.WriteHeader(http.StatusOK)
611+
switch v := response.(type) {
612+
case string:
613+
_, _ = w.Write([]byte(v))
614+
case []byte:
615+
_, _ = w.Write(v)
616+
default:
617+
data, err := json.Marshal(v)
618+
if err == nil {
619+
_, _ = w.Write(data)
620+
}
621+
}
622+
}
623+
}
624+
}
625+
626+
func WithRequestMatchHandler(pattern EndpointPattern, handler http.HandlerFunc) MockBackendOption {
627+
return func(handlers map[string]http.HandlerFunc) {
628+
method, path := parseEndpointPattern(pattern)
629+
handlers[method+" "+path] = handler
630+
}
631+
}
632+
633+
func NewMockedHTTPClient(options ...MockBackendOption) *http.Client {
634+
handlers := map[string]http.HandlerFunc{}
635+
for _, opt := range options {
636+
if opt != nil {
637+
opt(handlers)
638+
}
639+
}
640+
return MockHTTPClientWithHandlers(handlers)
641+
}
642+
643+
func MustMarshal(v any) []byte {
644+
data, err := json.Marshal(v)
645+
if err != nil {
646+
panic(err)
647+
}
648+
return data
649+
}
650+
593651
type multiHandlerTransport struct {
594652
handlers map[string]http.HandlerFunc
595653
}

0 commit comments

Comments
 (0)