@@ -225,7 +225,8 @@ func TestAddDeployKey(t *testing.T) {
225225 "id" : 12,
226226 "title" : "My deploy key",
227227 "can_push": true,
228- "created_at" : "2015-08-29T12:44:31.550Z"
228+ "created_at" : "2015-08-29T12:44:31.550Z",
229+ "expires_at": null
229230 }` )
230231 })
231232
@@ -256,6 +257,55 @@ func TestAddDeployKey(t *testing.T) {
256257 }
257258}
258259
260+ func TestAddDeployKey_withExpiresAt (t * testing.T ) {
261+ mux , client := setup (t )
262+
263+ mux .HandleFunc ("/api/v4/projects/5/deploy_keys" , func (w http.ResponseWriter , r * http.Request ) {
264+ testMethod (t , r , http .MethodPost )
265+ fmt .Fprintf (w , `{
266+ "key" : "ssh-rsa AAAA...",
267+ "id" : 12,
268+ "title" : "My deploy key",
269+ "can_push": true,
270+ "created_at" : "2015-08-29T12:44:31.550Z",
271+ "expires_at": "2999-03-01T00:00:00.000Z"
272+ }` )
273+ })
274+
275+ expiresAt , err := time .Parse (timeLayout , "2999-03-01T00:00:00.000Z" )
276+ if err != nil {
277+ t .Errorf ("DeployKeys.AddDeployKey returned an error while parsing time: %v" , err )
278+ }
279+
280+ opt := & AddDeployKeyOptions {
281+ Key : Ptr ("ssh-rsa AAAA..." ),
282+ Title : Ptr ("My deploy key" ),
283+ CanPush : Ptr (true ),
284+ ExpiresAt : & expiresAt ,
285+ }
286+ deployKey , _ , err := client .DeployKeys .AddDeployKey (5 , opt )
287+ if err != nil {
288+ t .Errorf ("DeployKey.AddDeployKey returned error: %v" , err )
289+ }
290+
291+ createdAt , err := time .Parse (timeLayout , "2015-08-29T12:44:31.550Z" )
292+ if err != nil {
293+ t .Errorf ("DeployKeys.AddDeployKey returned an error while parsing time: %v" , err )
294+ }
295+
296+ want := & ProjectDeployKey {
297+ Title : "My deploy key" ,
298+ ID : 12 ,
299+ Key : "ssh-rsa AAAA..." ,
300+ CreatedAt : & createdAt ,
301+ CanPush : true ,
302+ ExpiresAt : & expiresAt ,
303+ }
304+ if ! reflect .DeepEqual (want , deployKey ) {
305+ t .Errorf ("DeployKeys.AddDeployKey returned %+v, want %+v" , deployKey , want )
306+ }
307+ }
308+
259309func TestDeleteDeployKey (t * testing.T ) {
260310 mux , client := setup (t )
261311
0 commit comments