@@ -10,7 +10,6 @@ import (
1010 "github.com/google/go-github/v69/github"
1111 "github.com/mark3labs/mcp-go/mcp"
1212 "github.com/migueleliasweb/go-github-mock/src/mock"
13- "github.com/stretchr/testify/assert"
1413 "github.com/stretchr/testify/require"
1514)
1615
@@ -66,7 +65,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
6665 name string
6766 mockedClient * http.Client
6867 requestArgs map [string ]any
69- expectError bool
68+ expectError string
7069 expectedResult any
7170 expectedErrMsg string
7271 }{
@@ -79,7 +78,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
7978 ),
8079 ),
8180 requestArgs : map [string ]any {},
82- expectError : true ,
81+ expectError : "owner is required" ,
8382 },
8483 {
8584 name : "missing repo" ,
@@ -92,7 +91,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
9291 requestArgs : map [string ]any {
9392 "owner" : []string {"owner" },
9493 },
95- expectError : true ,
94+ expectError : "repo is required" ,
9695 },
9796 {
9897 name : "successful file content fetch" ,
@@ -108,7 +107,6 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
108107 "path" : []string {"README.md" },
109108 "branch" : []string {"main" },
110109 },
111- expectError : false ,
112110 expectedResult : expectedFileContent ,
113111 },
114112 {
@@ -124,11 +122,25 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
124122 "repo" : []string {"repo" },
125123 "path" : []string {"src" },
126124 },
127- expectError : false ,
128125 expectedResult : expectedDirContent ,
129126 },
130127 {
131- name : "empty content fetch" ,
128+ name : "no data" ,
129+ mockedClient : mock .NewMockedHTTPClient (
130+ mock .WithRequestMatch (
131+ mock .GetReposContentsByOwnerByRepoByPath ,
132+ ),
133+ ),
134+ requestArgs : map [string ]any {
135+ "owner" : []string {"owner" },
136+ "repo" : []string {"repo" },
137+ "path" : []string {"src" },
138+ },
139+ expectedResult : nil ,
140+ expectError : "no repository resource content found" ,
141+ },
142+ {
143+ name : "empty data" ,
132144 mockedClient : mock .NewMockedHTTPClient (
133145 mock .WithRequestMatch (
134146 mock .GetReposContentsByOwnerByRepoByPath ,
@@ -140,7 +152,6 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
140152 "repo" : []string {"repo" },
141153 "path" : []string {"src" },
142154 },
143- expectError : false ,
144155 expectedResult : nil ,
145156 },
146157 {
@@ -160,8 +171,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
160171 "path" : []string {"nonexistent.md" },
161172 "branch" : []string {"main" },
162173 },
163- expectError : true ,
164- expectedErrMsg : "404 Not Found" ,
174+ expectError : "404 Not Found" ,
165175 },
166176 }
167177
@@ -181,9 +191,8 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
181191
182192 resp , err := handler (context .TODO (), request )
183193
184- if tc .expectError {
185- require .Error (t , err )
186- assert .Contains (t , err .Error (), tc .expectedErrMsg )
194+ if tc .expectError != "" {
195+ require .ErrorContains (t , err , tc .expectedErrMsg )
187196 return
188197 }
189198
0 commit comments