Skip to content

Commit 3a3bd1e

Browse files
committed
Add test
1 parent 26e1b7a commit 3a3bd1e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

pkg/github/repositories_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,51 @@ func Test_GetFileContents(t *testing.T) {
245245
expectError: false,
246246
expectedResult: mockDirContent,
247247
},
248+
{
249+
name: "successful text content fetch with leading slash in path",
250+
mockedClient: mock.NewMockedHTTPClient(
251+
mock.WithRequestMatchHandler(
252+
mock.GetReposGitRefByOwnerByRepoByRef,
253+
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
254+
w.WriteHeader(http.StatusOK)
255+
_, _ = w.Write([]byte(`{"ref": "refs/heads/main", "object": {"sha": ""}}`))
256+
}),
257+
),
258+
mock.WithRequestMatchHandler(
259+
mock.GetReposContentsByOwnerByRepoByPath,
260+
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
261+
w.WriteHeader(http.StatusOK)
262+
fileContent := &github.RepositoryContent{
263+
Name: github.Ptr("README.md"),
264+
Path: github.Ptr("README.md"),
265+
SHA: github.Ptr("abc123"),
266+
Type: github.Ptr("file"),
267+
}
268+
contentBytes, _ := json.Marshal(fileContent)
269+
_, _ = w.Write(contentBytes)
270+
}),
271+
),
272+
mock.WithRequestMatchHandler(
273+
raw.GetRawReposContentsByOwnerByRepoByBranchByPath,
274+
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
275+
w.Header().Set("Content-Type", "text/markdown")
276+
_, _ = w.Write(mockRawContent)
277+
}),
278+
),
279+
),
280+
requestArgs: map[string]interface{}{
281+
"owner": "owner",
282+
"repo": "repo",
283+
"path": "/README.md",
284+
"ref": "refs/heads/main",
285+
},
286+
expectError: false,
287+
expectedResult: mcp.ResourceContents{
288+
URI: "repo://owner/repo/refs/heads/main/contents/README.md",
289+
Text: "# Test Repository\n\nThis is a test repository.",
290+
MIMEType: "text/markdown",
291+
},
292+
},
248293
{
249294
name: "content fetch fails",
250295
mockedClient: mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)