- Notifications
You must be signed in to change notification settings - Fork936
Use Raw repo resources#70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
afcb99c
f1d6aa5
c699e24
0213f40
332b360
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,7 +2,6 @@ package github | ||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
@@ -13,28 +12,35 @@ import ( | ||
"github.com/stretchr/testify/require" | ||
) | ||
var GetRawReposContentsByOwnerByRepoByPath mock.EndpointPattern = mock.EndpointPattern{ | ||
Pattern: "/{owner}/{repo}/main/{path:.+}", | ||
Method: "GET", | ||
} | ||
func Test_repositoryResourceContentsHandler(t *testing.T) { | ||
mockDirContent := []*github.RepositoryContent{ | ||
{ | ||
Type: github.Ptr("file"), | ||
Name: github.Ptr("README.md"), | ||
Path: github.Ptr("README.md"), | ||
SHA: github.Ptr("abc123"), | ||
Size: github.Ptr(42), | ||
HTMLURL: github.Ptr("https://github.com/owner/repo/blob/main/README.md"), | ||
DownloadURL: github.Ptr("https://raw.githubusercontent.com/owner/repo/main/README.md"), | ||
}, | ||
{ | ||
Type: github.Ptr("dir"), | ||
Name: github.Ptr("src"), | ||
Path: github.Ptr("src"), | ||
SHA: github.Ptr("def456"), | ||
HTMLURL: github.Ptr("https://github.com/owner/repo/tree/main/src"), | ||
DownloadURL: github.Ptr("https://raw.githubusercontent.com/owner/repo/main/src"), | ||
}, | ||
} | ||
expectedDirContent := []mcp.TextResourceContents{ | ||
{ | ||
URI: "https://github.com/owner/repo/blob/main/README.md", | ||
MIMEType: "text/markdown", | ||
Text: "README.md", | ||
}, | ||
{ | ||
@@ -44,20 +50,41 @@ func Test_repositoryResourceContentsHandler(t *testing.T) { | ||
}, | ||
} | ||
mockTextContent := &github.RepositoryContent{ | ||
Type: github.Ptr("file"), | ||
Name: github.Ptr("README.md"), | ||
Path: github.Ptr("README.md"), | ||
Content: github.Ptr("# Test Repository\n\nThis is a test repository."), | ||
SHA: github.Ptr("abc123"), | ||
Size: github.Ptr(42), | ||
HTMLURL: github.Ptr("https://github.com/owner/repo/blob/main/README.md"), | ||
DownloadURL: github.Ptr("https://raw.githubusercontent.com/owner/repo/main/README.md"), | ||
} | ||
mockFileContent := &github.RepositoryContent{ | ||
Type: github.Ptr("file"), | ||
Name: github.Ptr("data.png"), | ||
Path: github.Ptr("data.png"), | ||
Content: github.Ptr("IyBUZXN0IFJlcG9zaXRvcnkKClRoaXMgaXMgYSB0ZXN0IHJlcG9zaXRvcnku"), // Base64 encoded "# Test Repository\n\nThis is a test repository." | ||
SHA: github.Ptr("abc123"), | ||
Size: github.Ptr(42), | ||
HTMLURL: github.Ptr("https://github.com/owner/repo/blob/main/data.png"), | ||
DownloadURL: github.Ptr("https://raw.githubusercontent.com/owner/repo/main/data.png"), | ||
} | ||
expectedFileContent := []mcp.BlobResourceContents{ | ||
{ | ||
Blob: "IyBUZXN0IFJlcG9zaXRvcnkKClRoaXMgaXMgYSB0ZXN0IHJlcG9zaXRvcnku", | ||
MIMEType: "image/png", | ||
URI: "", | ||
}, | ||
} | ||
expectedTextContent := []mcp.TextResourceContents{ | ||
{ | ||
Text: "# Test Repository\n\nThis is a test repository.", | ||
MIMEType: "text/markdown", | ||
URI: "", | ||
}, | ||
} | ||
@@ -94,21 +121,50 @@ func Test_repositoryResourceContentsHandler(t *testing.T) { | ||
expectError: "repo is required", | ||
}, | ||
{ | ||
name: "successfulblob content fetch", | ||
mockedClient: mock.NewMockedHTTPClient( | ||
mock.WithRequestMatch( | ||
mock.GetReposContentsByOwnerByRepoByPath, | ||
mockFileContent, | ||
), | ||
mock.WithRequestMatchHandler( | ||
GetRawReposContentsByOwnerByRepoByPath, | ||
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
w.Header().Set("Content-Type", "image/png") | ||
// as this is given as a png, it will return the content as a blob | ||
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository.")) | ||
require.NoError(t, err) | ||
}), | ||
), | ||
), | ||
requestArgs: map[string]any{ | ||
"owner": []string{"owner"}, | ||
"repo": []string{"repo"}, | ||
"path": []string{"data.png"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. In the 'successful text content fetch' test, the request argument 'path' is set to 'data.png' while the mockTextContent has a name of 'README.md' (implying a .md extension). This discrepancy could lead to inconsistent MIME type resolution; please ensure that the file name and path are consistent. Copilot uses AI. Check for mistakes. | ||
"branch": []string{"main"}, | ||
}, | ||
expectedResult: expectedFileContent, | ||
}, | ||
{ | ||
name: "successful text content fetch", | ||
mockedClient: mock.NewMockedHTTPClient( | ||
mock.WithRequestMatch( | ||
mock.GetReposContentsByOwnerByRepoByPath, | ||
mockTextContent, | ||
), | ||
mock.WithRequestMatch( | ||
GetRawReposContentsByOwnerByRepoByPath, | ||
[]byte("# Test Repository\n\nThis is a test repository."), | ||
), | ||
), | ||
requestArgs: map[string]any{ | ||
"owner": []string{"owner"}, | ||
"repo": []string{"repo"}, | ||
"path": []string{"README.md"}, | ||
"branch": []string{"main"}, | ||
}, | ||
expectedResult: expectedTextContent, | ||
}, | ||
{ | ||
name: "successful directory content fetch", | ||
mockedClient: mock.NewMockedHTTPClient( | ||