@@ -304,36 +304,49 @@ func TestRepositoryHookList(t *testing.T) {
304304 t .Run ("Page" , testPage (res ))
305305}
306306
307- func TestRepositoryHookDelete (t * testing.T ) {
307+ func TestRepositoryHookCreate (t * testing.T ) {
308308 defer gock .Off ()
309309
310310 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 ).
313313 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+ }
315323
316324 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 )
318326 if err != nil {
319327 t .Error (err )
320328 return
321329 }
322330
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 )
325338 }
326339
327340 t .Run ("Request" , testRequest (res ))
328341 t .Run ("Rate" , testRate (res ))
329342}
330343
331- func TestRepositoryHookCreate (t * testing.T ) {
344+ func TestRepositoryHookUpdate (t * testing.T ) {
332345 defer gock .Off ()
333346
334347 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 ).
337350 Type ("application/json" ).
338351 SetHeaders (mockHeaders ).
339352 File ("testdata/hook.json" )
@@ -346,7 +359,7 @@ func TestRepositoryHookCreate(t *testing.T) {
346359 }
347360
348361 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 )
350363 if err != nil {
351364 t .Error (err )
352365 return
@@ -365,6 +378,30 @@ func TestRepositoryHookCreate(t *testing.T) {
365378 t .Run ("Rate" , testRate (res ))
366379}
367380
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+
368405func TestConvertState (t * testing.T ) {
369406 tests := []struct {
370407 src string
@@ -484,7 +521,7 @@ func TestHookEvents(t *testing.T) {
484521 },
485522 }
486523 for i , test := range tests {
487- got , want := convertHookEvents (test .in ), test .out
524+ got , want := convertFromHookEvents (test .in ), test .out
488525 if diff := cmp .Diff (got , want ); diff != "" {
489526 t .Errorf ("Unexpected Results at index %d" , i )
490527 t .Log (diff )
0 commit comments