Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This project uses a combination of unit tests and end-to-end (e2e) tests to ensu
- Unit tests are located alongside implementation, with filenames ending in `_test.go`.
- Currently the preference is to use internal tests i.e. test files do not have `_test` package suffix.
- Tests use [testify](https://github.com/stretchr/testify) for assertions and require statements. Use `require` when continuing the test is not meaningful, for example it is almost never correct to continue after an error expectation.
- Mocking is performed using [go-github-mock](https://github.com/migueleliasweb/go-github-mock) or `githubv4mock` for simulating GitHub rest and GQL API responses.
- REST mocking in unit tests is performed with the internal `pkg/testmock` helpers (built on `net/http` and testify assertions) or `githubv4mock` for simulating GitHub REST and GQL API responses.
- Each tool's schema is snapshotted and checked for changes using the `toolsnaps` utility (see below).
- Tests are designed to be explicit and verbose to aid maintainability and clarity.
- Handler unit tests should take the form of:
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const (
PatchReposIssuesByOwnerByRepoByIssueNumber = "PATCH /repos/{owner}/{repo}/issues/{issue_number}"
GetReposIssuesSubIssuesByOwnerByRepoByIssueNumber = "GET /repos/{owner}/{repo}/issues/{issue_number}/sub_issues"
PostReposIssuesSubIssuesByOwnerByRepoByIssueNumber = "POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues"
DeleteReposIssuesSubIssueByOwnerByRepoByIssueNumber = "DELETE /repos/{owner}/{repo}/issues/{issue_number}/sub_issues"
DeleteReposIssuesSubIssueByOwnerByRepoByIssueNumber = "DELETE /repos/{owner}/{repo}/issues/{issue_number}/sub_issue"
PatchReposIssuesSubIssuesPriorityByOwnerByRepoByIssueNumber = "PATCH /repos/{owner}/{repo}/issues/{issue_number}/sub_issues/priority"

// Pull request endpoints
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/github/github-mcp-server/internal/githubv4mock"
"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/lockdown"
mock "github.com/github/github-mcp-server/pkg/testmock"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v79/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"testing"

"github.com/github/github-mcp-server/internal/toolsnaps"
mock "github.com/github/github-mcp-server/pkg/testmock"
"github.com/github/github-mcp-server/pkg/translations"
gh "github.com/google/go-github/v79/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/pullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/google/jsonschema-go/jsonschema"
"github.com/shurcooL/githubv4"

"github.com/migueleliasweb/go-github-mock/src/mock"
mock "github.com/github/github-mcp-server/pkg/testmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
7 changes: 4 additions & 3 deletions pkg/github/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/raw"
mock "github.com/github/github-mcp-server/pkg/testmock"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/github/github-mcp-server/pkg/utils"
"github.com/google/go-github/v79/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -307,11 +307,12 @@ func Test_GetFileContents(t *testing.T) {
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Request for "refs/heads/main" -> 404 (doesn't exist)
// Request for "refs/heads/develop" (default branch) -> 200
path := r.URL.EscapedPath()
switch {
case strings.Contains(r.URL.Path, "heads/main"):
case strings.Contains(path, "heads/main") || strings.Contains(path, "heads%2Fmain"):
w.WriteHeader(http.StatusNotFound)
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
case strings.Contains(r.URL.Path, "heads/develop"):
case strings.Contains(path, "heads/develop") || strings.Contains(path, "heads%2Fdevelop"):
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"ref": "refs/heads/develop", "object": {"sha": "abc123def456"}}`))
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"testing"

"github.com/github/github-mcp-server/internal/toolsnaps"
mock "github.com/github/github-mcp-server/pkg/testmock"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v79/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
10 changes: 5 additions & 5 deletions pkg/raw/raw_mock.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package raw

import "github.com/migueleliasweb/go-github-mock/src/mock"
import "github.com/github/github-mcp-server/pkg/testmock"

var GetRawReposContentsByOwnerByRepoByPath mock.EndpointPattern = mock.EndpointPattern{
var GetRawReposContentsByOwnerByRepoByPath = testmock.EndpointPattern{
Pattern: "/{owner}/{repo}/HEAD/{path:.*}",
Method: "GET",
}
var GetRawReposContentsByOwnerByRepoByBranchByPath mock.EndpointPattern = mock.EndpointPattern{
var GetRawReposContentsByOwnerByRepoByBranchByPath = testmock.EndpointPattern{
Pattern: "/{owner}/{repo}/refs/heads/{branch}/{path:.*}",
Method: "GET",
}
var GetRawReposContentsByOwnerByRepoByTagByPath mock.EndpointPattern = mock.EndpointPattern{
var GetRawReposContentsByOwnerByRepoByTagByPath = testmock.EndpointPattern{
Pattern: "/{owner}/{repo}/refs/tags/{tag}/{path:.*}",
Method: "GET",
}
var GetRawReposContentsByOwnerByRepoBySHAByPath mock.EndpointPattern = mock.EndpointPattern{
var GetRawReposContentsByOwnerByRepoBySHAByPath = testmock.EndpointPattern{
Pattern: "/{owner}/{repo}/{sha}/{path:.*}",
Method: "GET",
}
Loading