@@ -10,7 +10,6 @@ import (
10
10
"github.com/google/go-github/v69/github"
11
11
"github.com/mark3labs/mcp-go/mcp"
12
12
"github.com/migueleliasweb/go-github-mock/src/mock"
13
- "github.com/stretchr/testify/assert"
14
13
"github.com/stretchr/testify/require"
15
14
)
16
15
@@ -66,7 +65,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
66
65
name string
67
66
mockedClient * http.Client
68
67
requestArgs map [string ]any
69
- expectError bool
68
+ expectError string
70
69
expectedResult any
71
70
expectedErrMsg string
72
71
}{
@@ -79,7 +78,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
79
78
),
80
79
),
81
80
requestArgs : map [string ]any {},
82
- expectError : true ,
81
+ expectError : "owner is required" ,
83
82
},
84
83
{
85
84
name : "missing repo" ,
@@ -92,7 +91,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
92
91
requestArgs : map [string ]any {
93
92
"owner" : []string {"owner" },
94
93
},
95
- expectError : true ,
94
+ expectError : "repo is required" ,
96
95
},
97
96
{
98
97
name : "successful file content fetch" ,
@@ -108,7 +107,6 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
108
107
"path" : []string {"README.md" },
109
108
"branch" : []string {"main" },
110
109
},
111
- expectError : false ,
112
110
expectedResult : expectedFileContent ,
113
111
},
114
112
{
@@ -124,11 +122,25 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
124
122
"repo" : []string {"repo" },
125
123
"path" : []string {"src" },
126
124
},
127
- expectError : false ,
128
125
expectedResult : expectedDirContent ,
129
126
},
130
127
{
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" ,
132
144
mockedClient : mock .NewMockedHTTPClient (
133
145
mock .WithRequestMatch (
134
146
mock .GetReposContentsByOwnerByRepoByPath ,
@@ -140,7 +152,6 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
140
152
"repo" : []string {"repo" },
141
153
"path" : []string {"src" },
142
154
},
143
- expectError : false ,
144
155
expectedResult : nil ,
145
156
},
146
157
{
@@ -160,8 +171,7 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
160
171
"path" : []string {"nonexistent.md" },
161
172
"branch" : []string {"main" },
162
173
},
163
- expectError : true ,
164
- expectedErrMsg : "404 Not Found" ,
174
+ expectError : "404 Not Found" ,
165
175
},
166
176
}
167
177
@@ -181,9 +191,8 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
181
191
182
192
resp , err := handler (context .TODO (), request )
183
193
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 )
187
196
return
188
197
}
189
198
0 commit comments