Content-Length: 400302 | pFad | http://github.com/github/github-mcp-server/pull/69/commits/ad5822019b4a5c470633f70072d9652f317f12e5

0F repository resource tests by mntlty · Pull Request #69 · github/github-mcp-server · GitHub
Skip to content

repository resource tests #69

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more tests and cleanup
  • Loading branch information
mntlty committed Apr 2, 2025
commit ad5822019b4a5c470633f70072d9652f317f12e5
8 changes: 6 additions & 2 deletions pkg/github/repository_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ func repositoryResourceContentsHandler(client *github.Client) func(ctx context.C
repo := r[0]

// path should be a joined list of the path parts
path := strings.Join(request.Params.Arguments["path"].([]string), "/")
path := ""
p, ok := request.Params.Arguments["path"].([]string)
if ok {
path = strings.Join(p, "/")
}

opts := &github.RepositoryContentGetOptions{}

Expand Down Expand Up @@ -150,6 +154,6 @@ func repositoryResourceContentsHandler(client *github.Client) func(ctx context.C
}
}

return nil, nil
return nil, errors.New("no repository resource content found")
}
}
35 changes: 22 additions & 13 deletions pkg/github/repository_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -66,7 +65,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
name string
mockedClient *http.Client
requestArgs map[string]any
expectError bool
expectError string
expectedResult any
expectedErrMsg string
}{
Expand All @@ -79,7 +78,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
),
),
requestArgs: map[string]any{},
expectError: true,
expectError: "owner is required",
},
{
name: "missing repo",
Expand All @@ -92,7 +91,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
requestArgs: map[string]any{
"owner": []string{"owner"},
},
expectError: true,
expectError: "repo is required",
},
{
name: "successful file content fetch",
Expand All @@ -108,7 +107,6 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
"path": []string{"README.md"},
"branch": []string{"main"},
},
expectError: false,
expectedResult: expectedFileContent,
},
{
Expand All @@ -124,11 +122,25 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
"repo": []string{"repo"},
"path": []string{"src"},
},
expectError: false,
expectedResult: expectedDirContent,
},
{
name: "empty content fetch",
name: "no data",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.GetReposContentsByOwnerByRepoByPath,
),
),
requestArgs: map[string]any{
"owner": []string{"owner"},
"repo": []string{"repo"},
"path": []string{"src"},
},
expectedResult: nil,
expectError: "no repository resource content found",
},
{
name: "empty data",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.GetReposContentsByOwnerByRepoByPath,
Expand All @@ -140,7 +152,6 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
"repo": []string{"repo"},
"path": []string{"src"},
},
expectError: false,
expectedResult: nil,
},
{
Expand All @@ -160,8 +171,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
"path": []string{"nonexistent.md"},
"branch": []string{"main"},
},
expectError: true,
expectedErrMsg: "404 Not Found",
expectError: "404 Not Found",
},
}

Expand All @@ -181,9 +191,8 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {

resp, err := handler(context.TODO(), request)

if tc.expectError {
require.Error(t, err)
assert.Contains(t, err.Error(), tc.expectedErrMsg)
if tc.expectError != "" {
require.ErrorContains(t, err, tc.expectedErrMsg)
return
}

Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github/github-mcp-server/pull/69/commits/ad5822019b4a5c470633f70072d9652f317f12e5

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy