@@ -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)
@@ -70,33 +69,21 @@ func Test_GetRepositoryTree(t *testing.T) {
7069 }{
7170 {
7271 name : "successfully get repository tree" ,
73- mockedClient : mock .NewMockedHTTPClient (
74- mock .WithRequestMatchHandler (
75- mock .GetReposByOwnerByRepo ,
76- mockResponse (t , http .StatusOK , mockRepo ),
77- ),
78- mock .WithRequestMatchHandler (
79- mock .GetReposGitTreesByOwnerByRepoByTreeSha ,
80- mockResponse (t , http .StatusOK , mockTree ),
81- ),
82- ),
72+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
73+ GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , mockRepo ),
74+ GetReposGitTreesByOwnerByRepoByTree : mockResponse (t , http .StatusOK , mockTree ),
75+ }),
8376 requestArgs : map [string ]interface {}{
8477 "owner" : "owner" ,
8578 "repo" : "repo" ,
8679 },
8780 },
8881 {
8982 name : "successfully get repository tree with path filter" ,
90- mockedClient : mock .NewMockedHTTPClient (
91- mock .WithRequestMatchHandler (
92- mock .GetReposByOwnerByRepo ,
93- mockResponse (t , http .StatusOK , mockRepo ),
94- ),
95- mock .WithRequestMatchHandler (
96- mock .GetReposGitTreesByOwnerByRepoByTreeSha ,
97- mockResponse (t , http .StatusOK , mockTree ),
98- ),
99- ),
83+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
84+ GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , mockRepo ),
85+ GetReposGitTreesByOwnerByRepoByTree : mockResponse (t , http .StatusOK , mockTree ),
86+ }),
10087 requestArgs : map [string ]interface {}{
10188 "owner" : "owner" ,
10289 "repo" : "repo" ,
@@ -105,15 +92,12 @@ func Test_GetRepositoryTree(t *testing.T) {
10592 },
10693 {
10794 name : "repository not found" ,
108- mockedClient : mock .NewMockedHTTPClient (
109- mock .WithRequestMatchHandler (
110- mock .GetReposByOwnerByRepo ,
111- http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
112- w .WriteHeader (http .StatusNotFound )
113- _ , _ = w .Write ([]byte (`{"message": "Not Found"}` ))
114- }),
115- ),
116- ),
95+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
96+ GetReposByOwnerByRepo : http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
97+ w .WriteHeader (http .StatusNotFound )
98+ _ , _ = w .Write ([]byte (`{"message": "Not Found"}` ))
99+ }),
100+ }),
117101 requestArgs : map [string ]interface {}{
118102 "owner" : "owner" ,
119103 "repo" : "nonexistent" ,
@@ -123,19 +107,13 @@ func Test_GetRepositoryTree(t *testing.T) {
123107 },
124108 {
125109 name : "tree not found" ,
126- mockedClient : mock .NewMockedHTTPClient (
127- mock .WithRequestMatchHandler (
128- mock .GetReposByOwnerByRepo ,
129- mockResponse (t , http .StatusOK , mockRepo ),
130- ),
131- mock .WithRequestMatchHandler (
132- mock .GetReposGitTreesByOwnerByRepoByTreeSha ,
133- http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
134- w .WriteHeader (http .StatusNotFound )
135- _ , _ = w .Write ([]byte (`{"message": "Not Found"}` ))
136- }),
137- ),
138- ),
110+ mockedClient : MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
111+ GetReposByOwnerByRepo : mockResponse (t , http .StatusOK , mockRepo ),
112+ GetReposGitTreesByOwnerByRepoByTree : http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
113+ w .WriteHeader (http .StatusNotFound )
114+ _ , _ = w .Write ([]byte (`{"message": "Not Found"}` ))
115+ }),
116+ }),
139117 requestArgs : map [string ]interface {}{
140118 "owner" : "owner" ,
141119 "repo" : "repo" ,
0 commit comments