@@ -984,3 +984,137 @@ func Test_ParseISOTimestamp(t *testing.T) {
984
984
})
985
985
}
986
986
}
987
+
988
+ func Test_GetIssueComments (t * testing.T ) {
989
+ // Verify tool definition once
990
+ mockClient := github .NewClient (nil )
991
+ tool , _ := getIssueComments (mockClient , translations .NullTranslationHelper )
992
+
993
+ assert .Equal (t , "get_issue_comments" , tool .Name )
994
+ assert .NotEmpty (t , tool .Description )
995
+ assert .Contains (t , tool .InputSchema .Properties , "owner" )
996
+ assert .Contains (t , tool .InputSchema .Properties , "repo" )
997
+ assert .Contains (t , tool .InputSchema .Properties , "issue_number" )
998
+ assert .Contains (t , tool .InputSchema .Properties , "page" )
999
+ assert .Contains (t , tool .InputSchema .Properties , "per_page" )
1000
+ assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" , "issue_number" })
1001
+
1002
+ // Setup mock comments for success case
1003
+ mockComments := []* github.IssueComment {
1004
+ {
1005
+ ID : github .Ptr (int64 (123 )),
1006
+ Body : github .Ptr ("This is the first comment" ),
1007
+ User : & github.User {
1008
+ Login : github .Ptr ("user1" ),
1009
+ },
1010
+ CreatedAt : & github.Timestamp {Time : time .Now ().Add (- time .Hour * 24 )},
1011
+ },
1012
+ {
1013
+ ID : github .Ptr (int64 (456 )),
1014
+ Body : github .Ptr ("This is the second comment" ),
1015
+ User : & github.User {
1016
+ Login : github .Ptr ("user2" ),
1017
+ },
1018
+ CreatedAt : & github.Timestamp {Time : time .Now ().Add (- time .Hour )},
1019
+ },
1020
+ }
1021
+
1022
+ tests := []struct {
1023
+ name string
1024
+ mockedClient * http.Client
1025
+ requestArgs map [string ]interface {}
1026
+ expectError bool
1027
+ expectedComments []* github.IssueComment
1028
+ expectedErrMsg string
1029
+ }{
1030
+ {
1031
+ name : "successful comments retrieval" ,
1032
+ mockedClient : mock .NewMockedHTTPClient (
1033
+ mock .WithRequestMatch (
1034
+ mock .GetReposIssuesCommentsByOwnerByRepoByIssueNumber ,
1035
+ mockComments ,
1036
+ ),
1037
+ ),
1038
+ requestArgs : map [string ]interface {}{
1039
+ "owner" : "owner" ,
1040
+ "repo" : "repo" ,
1041
+ "issue_number" : float64 (42 ),
1042
+ },
1043
+ expectError : false ,
1044
+ expectedComments : mockComments ,
1045
+ },
1046
+ {
1047
+ name : "successful comments retrieval with pagination" ,
1048
+ mockedClient : mock .NewMockedHTTPClient (
1049
+ mock .WithRequestMatchHandler (
1050
+ mock .GetReposIssuesCommentsByOwnerByRepoByIssueNumber ,
1051
+ expectQueryParams (t , map [string ]string {
1052
+ "page" : "2" ,
1053
+ "per_page" : "10" ,
1054
+ }).andThen (
1055
+ mockResponse (t , http .StatusOK , mockComments ),
1056
+ ),
1057
+ ),
1058
+ ),
1059
+ requestArgs : map [string ]interface {}{
1060
+ "owner" : "owner" ,
1061
+ "repo" : "repo" ,
1062
+ "issue_number" : float64 (42 ),
1063
+ "page" : float64 (2 ),
1064
+ "per_page" : float64 (10 ),
1065
+ },
1066
+ expectError : false ,
1067
+ expectedComments : mockComments ,
1068
+ },
1069
+ {
1070
+ name : "issue not found" ,
1071
+ mockedClient : mock .NewMockedHTTPClient (
1072
+ mock .WithRequestMatchHandler (
1073
+ mock .GetReposIssuesCommentsByOwnerByRepoByIssueNumber ,
1074
+ mockResponse (t , http .StatusNotFound , `{"message": "Issue not found"}` ),
1075
+ ),
1076
+ ),
1077
+ requestArgs : map [string ]interface {}{
1078
+ "owner" : "owner" ,
1079
+ "repo" : "repo" ,
1080
+ "issue_number" : float64 (999 ),
1081
+ },
1082
+ expectError : true ,
1083
+ expectedErrMsg : "failed to get issue comments" ,
1084
+ },
1085
+ }
1086
+
1087
+ for _ , tc := range tests {
1088
+ t .Run (tc .name , func (t * testing.T ) {
1089
+ // Setup client with mock
1090
+ client := github .NewClient (tc .mockedClient )
1091
+ _ , handler := getIssueComments (client , translations .NullTranslationHelper )
1092
+
1093
+ // Create call request
1094
+ request := createMCPRequest (tc .requestArgs )
1095
+
1096
+ // Call handler
1097
+ result , err := handler (context .Background (), request )
1098
+
1099
+ // Verify results
1100
+ if tc .expectError {
1101
+ require .Error (t , err )
1102
+ assert .Contains (t , err .Error (), tc .expectedErrMsg )
1103
+ return
1104
+ }
1105
+
1106
+ require .NoError (t , err )
1107
+ textContent := getTextResult (t , result )
1108
+
1109
+ // Unmarshal and verify the result
1110
+ var returnedComments []* github.IssueComment
1111
+ err = json .Unmarshal ([]byte (textContent .Text ), & returnedComments )
1112
+ require .NoError (t , err )
1113
+ assert .Equal (t , len (tc .expectedComments ), len (returnedComments ))
1114
+ if len (returnedComments ) > 0 {
1115
+ assert .Equal (t , * tc .expectedComments [0 ].Body , * returnedComments [0 ].Body )
1116
+ assert .Equal (t , * tc .expectedComments [0 ].User .Login , * returnedComments [0 ].User .Login )
1117
+ }
1118
+ })
1119
+ }
1120
+ }
0 commit comments