@@ -9,59 +9,21 @@ import (
99 "testing"
1010 "time"
1111
12- "github.com/github/github-mcp-server/internal/githubv4mock"
1312 "github.com/github/github-mcp-server/internal/toolsnaps"
1413 "github.com/github/github-mcp-server/pkg/raw"
1514 "github.com/github/github-mcp-server/pkg/translations"
1615 "github.com/google/go-github/v73/github"
1716 "github.com/mark3labs/mcp-go/mcp"
1817 "github.com/migueleliasweb/go-github-mock/src/mock"
19- "github.com/shurcooL/githubv4"
2018 "github.com/stretchr/testify/assert"
2119 "github.com/stretchr/testify/require"
2220)
2321
24- func mockGQLClientFileSHA (owner , repo , expression , expectedSHA string ) * githubv4.Client {
25- // Create the query structure that matches getFileSHA function
26- query := struct {
27- Repository struct {
28- Object struct {
29- Blob struct {
30- OID string
31- } `graphql:"... on Blob"`
32- } `graphql:"object(expression: $expression)"`
33- } `graphql:"repository(owner: $owner, name: $repo)"`
34- }{}
35-
36- // Match any variables, we don't care about the exact values in this test
37- variables := map [string ]interface {}{
38- "owner" : githubv4 .String (owner ),
39- "repo" : githubv4 .String (repo ),
40- "expression" : githubv4 .String (expression ),
41- }
42-
43- // Create the mock response with the expected SHA
44- mockResponse := githubv4mock .DataResponse (map [string ]any {
45- "repository" : map [string ]any {
46- "object" : map [string ]any {
47- "oid" : expectedSHA ,
48- },
49- },
50- })
51-
52- // Create the matcher and mock client
53- matcher := githubv4mock .NewQueryMatcher (query , variables , mockResponse )
54- httpClient := githubv4mock .NewMockedHTTPClient (matcher )
55-
56- return githubv4 .NewClient (httpClient )
57- }
58-
5922func Test_GetFileContents (t * testing.T ) {
6023 // Verify tool definition once
6124 mockClient := github .NewClient (nil )
6225 mockRawClient := raw .NewClient (mockClient , & url.URL {Scheme : "https" , Host : "raw.githubusercontent.com" , Path : "/" })
63- mockGQLClient := githubv4 .NewClient (nil )
64- tool , _ := GetFileContents (stubGetClientFn (mockClient ), stubGetRawClientFn (mockRawClient ), stubGetGQLClientFn (mockGQLClient ), translations .NullTranslationHelper )
26+ tool , _ := GetFileContents (stubGetClientFn (mockClient ), stubGetRawClientFn (mockRawClient ), translations .NullTranslationHelper )
6527 require .NoError (t , toolsnaps .Test (tool .Name , tool ))
6628
6729 assert .Equal (t , "get_file_contents" , tool .Name )
@@ -94,10 +56,10 @@ func Test_GetFileContents(t *testing.T) {
9456 HTMLURL : github .Ptr ("https://github.com/owner/repo/tree/main/src" ),
9557 },
9658 }
59+
9760 tests := []struct {
9861 name string
9962 mockedClient * http.Client
100- mockGQLClient * githubv4.Client
10163 requestArgs map [string ]interface {}
10264 expectError bool
10365 expectedResult interface {}
@@ -136,7 +98,6 @@ func Test_GetFileContents(t *testing.T) {
13698 }),
13799 ),
138100 ),
139- mockGQLClient : mockGQLClientFileSHA ("owner" , "repo" , "refs/heads/main:README.md" , "abc123" ),
140101 requestArgs : map [string ]interface {}{
141102 "owner" : "owner" ,
142103 "repo" : "repo" ,
@@ -182,7 +143,6 @@ func Test_GetFileContents(t *testing.T) {
182143 }),
183144 ),
184145 ),
185- mockGQLClient : mockGQLClientFileSHA ("owner" , "repo" , "refs/heads/main:test.png" , "def456" ),
186146 requestArgs : map [string ]interface {}{
187147 "owner" : "owner" ,
188148 "repo" : "repo" ,
@@ -228,7 +188,6 @@ func Test_GetFileContents(t *testing.T) {
228188 ),
229189 ),
230190 ),
231- mockGQLClient : nil ,
232191 requestArgs : map [string ]interface {}{
233192 "owner" : "owner" ,
234193 "repo" : "repo" ,
@@ -262,7 +221,6 @@ func Test_GetFileContents(t *testing.T) {
262221 }),
263222 ),
264223 ),
265- mockGQLClient : mockGQLClientFileSHA ("owner" , "repo" , "refs/heads/main:nonexistent.md" , "" ),
266224 requestArgs : map [string ]interface {}{
267225 "owner" : "owner" ,
268226 "repo" : "repo" ,
@@ -279,7 +237,7 @@ func Test_GetFileContents(t *testing.T) {
279237 // Setup client with mock
280238 client := github .NewClient (tc .mockedClient )
281239 mockRawClient := raw .NewClient (client , & url.URL {Scheme : "https" , Host : "raw.example.com" , Path : "/" })
282- _ , handler := GetFileContents (stubGetClientFn (client ), stubGetRawClientFn (mockRawClient ), stubGetGQLClientFn ( tc . mockGQLClient ), translations .NullTranslationHelper )
240+ _ , handler := GetFileContents (stubGetClientFn (client ), stubGetRawClientFn (mockRawClient ), translations .NullTranslationHelper )
283241
284242 // Create call request
285243 request := createMCPRequest (tc .requestArgs )
0 commit comments