@@ -517,11 +517,6 @@ func Test_GetCommit(t *testing.T) {
517517 },
518518 },
519519 }
520- // This one currently isn't defined in the mock package we're using.
521- var mockEndpointPattern = mock.EndpointPattern {
522- Pattern : "/repos/{owner}/{repo}/commits/{sha}" ,
523- Method : "GET" ,
524- }
525520
526521 tests := []struct {
527522 name string
@@ -535,7 +530,7 @@ func Test_GetCommit(t *testing.T) {
535530 name : "successful commit fetch" ,
536531 mockedClient : mock .NewMockedHTTPClient (
537532 mock .WithRequestMatchHandler (
538- mockEndpointPattern ,
533+ mock . GetReposCommitsByOwnerByRepoByRef ,
539534 mockResponse (t , http .StatusOK , mockCommit ),
540535 ),
541536 ),
@@ -551,7 +546,7 @@ func Test_GetCommit(t *testing.T) {
551546 name : "commit fetch fails" ,
552547 mockedClient : mock .NewMockedHTTPClient (
553548 mock .WithRequestMatchHandler (
554- mockEndpointPattern ,
549+ mock . GetReposCommitsByOwnerByRepoByRef ,
555550 http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
556551 w .WriteHeader (http .StatusNotFound )
557552 _ , _ = w .Write ([]byte (`{"message": "Not Found"}` ))
@@ -1423,3 +1418,113 @@ func Test_PushFiles(t *testing.T) {
14231418 })
14241419 }
14251420}
1421+
1422+ func Test_ListBranches (t * testing.T ) {
1423+ // Verify tool definition once
1424+ mockClient := github .NewClient (nil )
1425+ tool , _ := ListBranches (stubGetClientFn (mockClient ), translations .NullTranslationHelper )
1426+
1427+ assert .Equal (t , "list_branches" , tool .Name )
1428+ assert .NotEmpty (t , tool .Description )
1429+ assert .Contains (t , tool .InputSchema .Properties , "owner" )
1430+ assert .Contains (t , tool .InputSchema .Properties , "repo" )
1431+ assert .Contains (t , tool .InputSchema .Properties , "page" )
1432+ assert .Contains (t , tool .InputSchema .Properties , "perPage" )
1433+ assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" })
1434+
1435+ // Setup mock branches for success case
1436+ mockBranches := []* github.Branch {
1437+ {
1438+ Name : github .Ptr ("main" ),
1439+ Commit : & github.RepositoryCommit {SHA : github .Ptr ("abc123" )},
1440+ },
1441+ {
1442+ Name : github .Ptr ("develop" ),
1443+ Commit : & github.RepositoryCommit {SHA : github .Ptr ("def456" )},
1444+ },
1445+ }
1446+
1447+ // Test cases
1448+ tests := []struct {
1449+ name string
1450+ args map [string ]interface {}
1451+ mockResponses []mock.MockBackendOption
1452+ wantErr bool
1453+ errContains string
1454+ }{
1455+ {
1456+ name : "success" ,
1457+ args : map [string ]interface {}{
1458+ "owner" : "owner" ,
1459+ "repo" : "repo" ,
1460+ "page" : float64 (2 ),
1461+ },
1462+ mockResponses : []mock.MockBackendOption {
1463+ mock .WithRequestMatch (
1464+ mock .GetReposBranchesByOwnerByRepo ,
1465+ mockBranches ,
1466+ ),
1467+ },
1468+ wantErr : false ,
1469+ },
1470+ {
1471+ name : "missing owner" ,
1472+ args : map [string ]interface {}{
1473+ "repo" : "repo" ,
1474+ },
1475+ mockResponses : []mock.MockBackendOption {},
1476+ wantErr : false ,
1477+ errContains : "missing required parameter: owner" ,
1478+ },
1479+ {
1480+ name : "missing repo" ,
1481+ args : map [string ]interface {}{
1482+ "owner" : "owner" ,
1483+ },
1484+ mockResponses : []mock.MockBackendOption {},
1485+ wantErr : false ,
1486+ errContains : "missing required parameter: repo" ,
1487+ },
1488+ }
1489+
1490+ for _ , tt := range tests {
1491+ t .Run (tt .name , func (t * testing.T ) {
1492+ // Create mock client
1493+ mockClient := github .NewClient (mock .NewMockedHTTPClient (tt .mockResponses ... ))
1494+ _ , handler := ListBranches (stubGetClientFn (mockClient ), translations .NullTranslationHelper )
1495+
1496+ // Create request
1497+ request := createMCPRequest (tt .args )
1498+
1499+ // Call handler
1500+ result , err := handler (context .Background (), request )
1501+ if tt .wantErr {
1502+ require .Error (t , err )
1503+ if tt .errContains != "" {
1504+ assert .Contains (t , err .Error (), tt .errContains )
1505+ }
1506+ return
1507+ }
1508+
1509+ require .NoError (t , err )
1510+ require .NotNil (t , result )
1511+
1512+ if tt .errContains != "" {
1513+ textContent := getTextResult (t , result )
1514+ assert .Contains (t , textContent .Text , tt .errContains )
1515+ return
1516+ }
1517+
1518+ textContent := getTextResult (t , result )
1519+ require .NotEmpty (t , textContent .Text )
1520+
1521+ // Verify response
1522+ var branches []* github.Branch
1523+ err = json .Unmarshal ([]byte (textContent .Text ), & branches )
1524+ require .NoError (t , err )
1525+ assert .Len (t , branches , 2 )
1526+ assert .Equal (t , "main" , * branches [0 ].Name )
1527+ assert .Equal (t , "develop" , * branches [1 ].Name )
1528+ })
1529+ }
1530+ }
0 commit comments