Skip to content

Commit b96a791

Browse files
CopilotJoannaaKL
andcommitted
Define endpoint path constants in this repo instead of reusing go-github-mock
- Add endpoint pattern constants to helper_test.go - Update code_scanning_test.go to use new constants - Update git_test.go to use new constants - Removes dependency on go-github-mock endpoint patterns - Prepares for eventual removal of go-github-mock dependency Co-authored-by: JoannaaKL <[email protected]>
1 parent 9e403f5 commit b96a791

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

pkg/github/code_scanning_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/github/github-mcp-server/pkg/translations"
1111
"github.com/google/go-github/v79/github"
1212
"github.com/google/jsonschema-go/jsonschema"
13-
"github.com/migueleliasweb/go-github-mock/src/mock"
1413
"github.com/stretchr/testify/assert"
1514
"github.com/stretchr/testify/require"
1615
)
@@ -51,7 +50,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
5150
{
5251
name: "successful alert fetch",
5352
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
54-
mock.GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber.Method + " " + mock.GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber.Pattern: mockResponse(t, http.StatusOK, mockAlert),
53+
GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber: mockResponse(t, http.StatusOK, mockAlert),
5554
}),
5655
requestArgs: map[string]interface{}{
5756
"owner": "owner",
@@ -64,7 +63,7 @@ func Test_GetCodeScanningAlert(t *testing.T) {
6463
{
6564
name: "alert fetch fails",
6665
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
67-
mock.GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber.Method + " " + mock.GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber.Pattern: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
66+
GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
6867
w.WriteHeader(http.StatusNotFound)
6968
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
7069
}),
@@ -166,7 +165,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
166165
{
167166
name: "successful alerts listing",
168167
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
169-
mock.GetReposCodeScanningAlertsByOwnerByRepo.Method + " " + mock.GetReposCodeScanningAlertsByOwnerByRepo.Pattern: expectQueryParams(t, map[string]string{
168+
GetReposCodeScanningAlertsByOwnerByRepo: expectQueryParams(t, map[string]string{
170169
"ref": "main",
171170
"state": "open",
172171
"severity": "high",
@@ -189,7 +188,7 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
189188
{
190189
name: "alerts listing fails",
191190
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
192-
mock.GetReposCodeScanningAlertsByOwnerByRepo.Method + " " + mock.GetReposCodeScanningAlertsByOwnerByRepo.Pattern: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
191+
GetReposCodeScanningAlertsByOwnerByRepo: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
193192
w.WriteHeader(http.StatusUnauthorized)
194193
_, _ = w.Write([]byte(`{"message": "Unauthorized access"}`))
195194
}),

pkg/github/git_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/github/github-mcp-server/pkg/translations"
1212
"github.com/google/go-github/v79/github"
1313
"github.com/google/jsonschema-go/jsonschema"
14-
"github.com/migueleliasweb/go-github-mock/src/mock"
1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
1716
)
@@ -72,8 +71,8 @@ func Test_GetRepositoryTree(t *testing.T) {
7271
{
7372
name: "successfully get repository tree",
7473
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
75-
mock.GetReposByOwnerByRepo.Method + " " + mock.GetReposByOwnerByRepo.Pattern: mockResponse(t, http.StatusOK, mockRepo),
76-
mock.GetReposGitTreesByOwnerByRepoByTreeSha.Method + " " + mock.GetReposGitTreesByOwnerByRepoByTreeSha.Pattern: mockResponse(t, http.StatusOK, mockTree),
74+
GetReposByOwnerByRepo: mockResponse(t, http.StatusOK, mockRepo),
75+
GetReposGitTreesByOwnerByRepoByTree: mockResponse(t, http.StatusOK, mockTree),
7776
}),
7877
requestArgs: map[string]interface{}{
7978
"owner": "owner",
@@ -83,8 +82,8 @@ func Test_GetRepositoryTree(t *testing.T) {
8382
{
8483
name: "successfully get repository tree with path filter",
8584
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
86-
mock.GetReposByOwnerByRepo.Method + " " + mock.GetReposByOwnerByRepo.Pattern: mockResponse(t, http.StatusOK, mockRepo),
87-
mock.GetReposGitTreesByOwnerByRepoByTreeSha.Method + " " + mock.GetReposGitTreesByOwnerByRepoByTreeSha.Pattern: mockResponse(t, http.StatusOK, mockTree),
85+
GetReposByOwnerByRepo: mockResponse(t, http.StatusOK, mockRepo),
86+
GetReposGitTreesByOwnerByRepoByTree: mockResponse(t, http.StatusOK, mockTree),
8887
}),
8988
requestArgs: map[string]interface{}{
9089
"owner": "owner",
@@ -95,7 +94,7 @@ func Test_GetRepositoryTree(t *testing.T) {
9594
{
9695
name: "repository not found",
9796
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
98-
mock.GetReposByOwnerByRepo.Method + " " + mock.GetReposByOwnerByRepo.Pattern: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
97+
GetReposByOwnerByRepo: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
9998
w.WriteHeader(http.StatusNotFound)
10099
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
101100
}),
@@ -110,8 +109,8 @@ func Test_GetRepositoryTree(t *testing.T) {
110109
{
111110
name: "tree not found",
112111
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
113-
mock.GetReposByOwnerByRepo.Method + " " + mock.GetReposByOwnerByRepo.Pattern: mockResponse(t, http.StatusOK, mockRepo),
114-
mock.GetReposGitTreesByOwnerByRepoByTreeSha.Method + " " + mock.GetReposGitTreesByOwnerByRepoByTreeSha.Pattern: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
112+
GetReposByOwnerByRepo: mockResponse(t, http.StatusOK, mockRepo),
113+
GetReposGitTreesByOwnerByRepoByTree: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
115114
w.WriteHeader(http.StatusNotFound)
116115
_, _ = w.Write([]byte(`{"message": "Not Found"}`))
117116
}),

pkg/github/helper_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18+
// GitHub API endpoint patterns for testing
19+
// These constants define the URL patterns used in HTTP mocking for tests
20+
const (
21+
// Repository endpoints
22+
GetReposByOwnerByRepo = "GET /repos/{owner}/{repo}"
23+
24+
// Git endpoints
25+
GetReposGitTreesByOwnerByRepoByTree = "GET /repos/{owner}/{repo}/git/trees/{tree}"
26+
27+
// Code scanning endpoints
28+
GetReposCodeScanningAlertsByOwnerByRepo = "GET /repos/{owner}/{repo}/code-scanning/alerts"
29+
GetReposCodeScanningAlertsByOwnerByRepoByAlertNumber = "GET /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}"
30+
)
31+
1832
type expectations struct {
1933
path string
2034
queryParams map[string]string

0 commit comments

Comments
 (0)