Content-Length: 417285 | pFad | http://github.com/github/github-mcp-server/pull/96/commits/5c5f42f5034e84eab34c094a29d726c4e898d559

AC assert params and body in repositories_test by juruen · Pull Request #96 · github/github-mcp-server · GitHub
Skip to content

assert params and body in repositories_test #96

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 1 commit into from
Apr 4, 2025
Merged
Changes from all commits
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
assert params and body
  • Loading branch information
juruen committed Apr 4, 2025
commit 5c5f42f5034e84eab34c094a29d726c4e898d559
122 changes: 100 additions & 22 deletions pkg/github/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ func Test_GetFileContents(t *testing.T) {
{
name: "successful file content fetch",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetReposContentsByOwnerByRepoByPath,
mockFileContent,
expectQueryParams(t, map[string]string{
"ref": "main",
}).andThen(
mockResponse(t, http.StatusOK, mockFileContent),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -87,9 +91,11 @@ func Test_GetFileContents(t *testing.T) {
{
name: "successful directory content fetch",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetReposContentsByOwnerByRepoByPath,
mockDirContent,
expectQueryParams(t, map[string]string{}).andThen(
mockResponse(t, http.StatusOK, mockDirContent),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -352,9 +358,14 @@ func Test_CreateBranch(t *testing.T) {
mock.GetReposGitRefByOwnerByRepoByRef,
mockSourceRef,
),
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PostReposGitRefsByOwnerByRepo,
mockCreatedRef,
expectRequestBody(t, map[string]interface{}{
"ref": "refs/heads/new-feature",
"sha": "abc123def456",
}).andThen(
mockResponse(t, http.StatusCreated, mockCreatedRef),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -538,9 +549,15 @@ func Test_ListCommits(t *testing.T) {
{
name: "successful commits fetch with branch",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetReposCommitsByOwnerByRepo,
mockCommits,
expectQueryParams(t, map[string]string{
"sha": "main",
"page": "1",
"per_page": "30",
}).andThen(
mockResponse(t, http.StatusOK, mockCommits),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -554,9 +571,14 @@ func Test_ListCommits(t *testing.T) {
{
name: "successful commits fetch with pagination",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetReposCommitsByOwnerByRepo,
mockCommits,
expectQueryParams(t, map[string]string{
"page": "2",
"per_page": "10",
}).andThen(
mockResponse(t, http.StatusOK, mockCommits),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -676,9 +698,15 @@ func Test_CreateOrUpdateFile(t *testing.T) {
{
name: "successful file creation",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PutReposContentsByOwnerByRepoByPath,
mockFileResponse,
expectRequestBody(t, map[string]interface{}{
"message": "Add example file",
"content": "IyBFeGFtcGxlCgpUaGlzIGlzIGFuIGV4YW1wbGUgZmlsZS4=", // Base64 encoded content
"branch": "main",
}).andThen(
mockResponse(t, http.StatusOK, mockFileResponse),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -695,9 +723,16 @@ func Test_CreateOrUpdateFile(t *testing.T) {
{
name: "successful file update with SHA",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PutReposContentsByOwnerByRepoByPath,
mockFileResponse,
expectRequestBody(t, map[string]interface{}{
"message": "Update example file",
"content": "IyBVcGRhdGVkIEV4YW1wbGUKClRoaXMgZmlsZSBoYXMgYmVlbiB1cGRhdGVkLg==", // Base64 encoded content
"branch": "main",
"sha": "abc123def456",
}).andThen(
mockResponse(t, http.StatusOK, mockFileResponse),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -819,7 +854,14 @@ func Test_CreateRepository(t *testing.T) {
Pattern: "/user/repos",
Method: "POST",
},
mockResponse(t, http.StatusCreated, mockRepo),
expectRequestBody(t, map[string]interface{}{
"name": "test-repo",
"description": "Test repository",
"private": true,
"auto_init": true,
}).andThen(
mockResponse(t, http.StatusCreated, mockRepo),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -839,7 +881,14 @@ func Test_CreateRepository(t *testing.T) {
Pattern: "/user/repos",
Method: "POST",
},
mockResponse(t, http.StatusCreated, mockRepo),
expectRequestBody(t, map[string]interface{}{
"name": "test-repo",
"auto_init": false,
"description": "",
"private": false,
}).andThen(
mockResponse(t, http.StatusCreated, mockRepo),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -980,19 +1029,48 @@ func Test_PushFiles(t *testing.T) {
mockCommit,
),
// Create tree
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PostReposGitTreesByOwnerByRepo,
mockTree,
expectRequestBody(t, map[string]interface{}{
"base_tree": "def456",
"tree": []interface{}{
map[string]interface{}{
"path": "README.md",
"mode": "100644",
"type": "blob",
"content": "# Updated README\n\nThis is an updated README file.",
},
map[string]interface{}{
"path": "docs/example.md",
"mode": "100644",
"type": "blob",
"content": "# Example\n\nThis is an example file.",
},
},
}).andThen(
mockResponse(t, http.StatusCreated, mockTree),
),
),
// Create commit
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PostReposGitCommitsByOwnerByRepo,
mockNewCommit,
expectRequestBody(t, map[string]interface{}{
"message": "Update multiple files",
"tree": "ghi789",
"parents": []interface{}{"abc123"},
}).andThen(
mockResponse(t, http.StatusCreated, mockNewCommit),
),
),
// Update reference
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.PatchReposGitRefsByOwnerByRepoByRef,
mockUpdatedRef,
expectRequestBody(t, map[string]interface{}{
"sha": "jkl012",
"force": false,
}).andThen(
mockResponse(t, http.StatusOK, mockUpdatedRef),
),
),
),
requestArgs: map[string]interface{}{
Expand Down








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/96/commits/5c5f42f5034e84eab34c094a29d726c4e898d559

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy