@@ -146,6 +146,7 @@ func TestGitHubApp_AccessToken(t *testing.T) {
146
146
appID string
147
147
installID string
148
148
options []ConfigOption
149
+ request * TokenRequest
149
150
want string
150
151
expErr string
151
152
handlerFunc http.HandlerFunc
@@ -155,6 +156,7 @@ func TestGitHubApp_AccessToken(t *testing.T) {
155
156
appID : "test-app-id" ,
156
157
installID : "test-install-id" ,
157
158
options : []ConfigOption {},
159
+ request : & TokenRequest {Repositories : []string {"test" }, Permissions : map [string ]string {"test" : "test" }},
158
160
want : `{"token":"this-is-the-token-from-github"}` ,
159
161
expErr : "" ,
160
162
handlerFunc : nil ,
@@ -164,6 +166,7 @@ func TestGitHubApp_AccessToken(t *testing.T) {
164
166
appID : "test-app-id" ,
165
167
installID : "test-install-id" ,
166
168
options : []ConfigOption {},
169
+ request : & TokenRequest {Repositories : []string {"test" }, Permissions : map [string ]string {"test" : "test" }},
167
170
expErr : "failed to retrieve token from GitHub - Status: 500 Internal Server Error - Body: " ,
168
171
handlerFunc : func (w http.ResponseWriter , r * http.Request ) {
169
172
w .WriteHeader (500 )
@@ -174,6 +177,7 @@ func TestGitHubApp_AccessToken(t *testing.T) {
174
177
appID : "test-app-id" ,
175
178
installID : "test-install-id" ,
176
179
options : []ConfigOption {},
180
+ request : & TokenRequest {Repositories : []string {"test" }, Permissions : map [string ]string {"test" : "test" }},
177
181
expErr : "invalid access token from GitHub - Body: not json" ,
178
182
handlerFunc : func (w http.ResponseWriter , r * http.Request ) {
179
183
w .WriteHeader (201 )
@@ -185,11 +189,33 @@ func TestGitHubApp_AccessToken(t *testing.T) {
185
189
appID : "test-app-id" ,
186
190
installID : "test-install-id" ,
187
191
options : []ConfigOption {},
192
+ request : & TokenRequest {Repositories : []string {"test" }, Permissions : map [string ]string {"test" : "test" }},
188
193
expErr : "invalid access token from GitHub - Body:" ,
189
194
handlerFunc : func (w http.ResponseWriter , r * http.Request ) {
190
195
w .WriteHeader (201 )
191
196
},
192
197
},
198
+ {
199
+ name : "allow_empty_repositories" ,
200
+ appID : "test-app-id" ,
201
+ installID : "test-install-id" ,
202
+ options : []ConfigOption {},
203
+ request : & TokenRequest {Repositories : []string {}, Permissions : map [string ]string {"test" : "test" }},
204
+ want : `{"token":"this-is-the-token-from-github"}` ,
205
+ expErr : "" ,
206
+ handlerFunc : nil ,
207
+ },
208
+ {
209
+ name : "missing_repositories" ,
210
+ appID : "test-app-id" ,
211
+ installID : "test-install-id" ,
212
+ options : []ConfigOption {},
213
+ request : & TokenRequest {Permissions : map [string ]string {"test" : "test" }},
214
+ expErr : "requested repositories cannot be nil, did you mean to use AccessTokenAllRepos to request all repos?" ,
215
+ handlerFunc : func (w http.ResponseWriter , r * http.Request ) {
216
+ w .WriteHeader (201 )
217
+ },
218
+ },
193
219
}
194
220
195
221
for _ , tc := range cases {
@@ -221,7 +247,7 @@ func TestGitHubApp_AccessToken(t *testing.T) {
221
247
tc .options = append (tc .options , WithAccessTokenURLPattern (fakeGitHub .URL + "/%s/access_tokens" ))
222
248
223
249
app := New (NewConfig (tc .appID , tc .installID , rsaPrivateKey , tc .options ... ))
224
- got , err := app .AccessToken (context .Background (), & TokenRequest {} )
250
+ got , err := app .AccessToken (context .Background (), tc . request )
225
251
if diff := testutil .DiffErrString (err , tc .expErr ); diff != "" {
226
252
t .Errorf (diff )
227
253
}
0 commit comments