@@ -304,36 +304,49 @@ func TestRepositoryHookList(t *testing.T) {
304
304
t .Run ("Page" , testPage (res ))
305
305
}
306
306
307
- func TestRepositoryHookDelete (t * testing.T ) {
307
+ func TestRepositoryHookCreate (t * testing.T ) {
308
308
defer gock .Off ()
309
309
310
310
gock .New ("https://api.github.com" ).
311
- Delete ("/repos/octocat/hello-world/hooks/1 " ).
312
- Reply (204 ).
311
+ Post ("/repos/octocat/hello-world/hooks" ).
312
+ Reply (201 ).
313
313
Type ("application/json" ).
314
- SetHeaders (mockHeaders )
314
+ SetHeaders (mockHeaders ).
315
+ File ("testdata/hook.json" )
316
+
317
+ in := & scm.HookInput {
318
+ Name : "drone" ,
319
+ Target : "https://example.com" ,
320
+ Secret : "topsecret" ,
321
+ SkipVerify : true ,
322
+ }
315
323
316
324
client := NewDefault ()
317
- res , err := client .Repositories .DeleteHook (context .Background (), "octocat/hello-world" , "1" )
325
+ got , res , err := client .Repositories .CreateHook (context .Background (), "octocat/hello-world" , in )
318
326
if err != nil {
319
327
t .Error (err )
320
328
return
321
329
}
322
330
323
- if got , want := res .Status , 204 ; got != want {
324
- t .Errorf ("Want response status %d, got %d" , want , got )
331
+ want := new (scm.Hook )
332
+ raw , _ := ioutil .ReadFile ("testdata/hook.json.golden" )
333
+ json .Unmarshal (raw , want )
334
+
335
+ if diff := cmp .Diff (got , want ); diff != "" {
336
+ t .Errorf ("Unexpected Results" )
337
+ t .Log (diff )
325
338
}
326
339
327
340
t .Run ("Request" , testRequest (res ))
328
341
t .Run ("Rate" , testRate (res ))
329
342
}
330
343
331
- func TestRepositoryHookCreate (t * testing.T ) {
344
+ func TestRepositoryHookUpdate (t * testing.T ) {
332
345
defer gock .Off ()
333
346
334
347
gock .New ("https://api.github.com" ).
335
- Post ("/repos/octocat/hello-world/hooks" ).
336
- Reply (201 ).
348
+ Patch ("/repos/octocat/hello-world/hooks/1 " ).
349
+ Reply (200 ).
337
350
Type ("application/json" ).
338
351
SetHeaders (mockHeaders ).
339
352
File ("testdata/hook.json" )
@@ -346,7 +359,7 @@ func TestRepositoryHookCreate(t *testing.T) {
346
359
}
347
360
348
361
client := NewDefault ()
349
- got , res , err := client .Repositories .CreateHook (context .Background (), "octocat/hello-world" , in )
362
+ got , res , err := client .Repositories .UpdateHook (context .Background (), "octocat/hello-world" , "1 " , in )
350
363
if err != nil {
351
364
t .Error (err )
352
365
return
@@ -365,6 +378,30 @@ func TestRepositoryHookCreate(t *testing.T) {
365
378
t .Run ("Rate" , testRate (res ))
366
379
}
367
380
381
+ func TestRepositoryHookDelete (t * testing.T ) {
382
+ defer gock .Off ()
383
+
384
+ gock .New ("https://api.github.com" ).
385
+ Delete ("/repos/octocat/hello-world/hooks/1" ).
386
+ Reply (204 ).
387
+ Type ("application/json" ).
388
+ SetHeaders (mockHeaders )
389
+
390
+ client := NewDefault ()
391
+ res , err := client .Repositories .DeleteHook (context .Background (), "octocat/hello-world" , "1" )
392
+ if err != nil {
393
+ t .Error (err )
394
+ return
395
+ }
396
+
397
+ if got , want := res .Status , 204 ; got != want {
398
+ t .Errorf ("Want response status %d, got %d" , want , got )
399
+ }
400
+
401
+ t .Run ("Request" , testRequest (res ))
402
+ t .Run ("Rate" , testRate (res ))
403
+ }
404
+
368
405
func TestConvertState (t * testing.T ) {
369
406
tests := []struct {
370
407
src string
@@ -484,7 +521,7 @@ func TestHookEvents(t *testing.T) {
484
521
},
485
522
}
486
523
for i , test := range tests {
487
- got , want := convertHookEvents (test .in ), test .out
524
+ got , want := convertFromHookEvents (test .in ), test .out
488
525
if diff := cmp .Diff (got , want ); diff != "" {
489
526
t .Errorf ("Unexpected Results at index %d" , i )
490
527
t .Log (diff )
0 commit comments