@@ -296,3 +296,263 @@ func TestRepositoriesService_TestHook_invalidOwner(t *testing.T) {
296296 _ , err := client .Repositories .TestHook (ctx , "%" , "%" , 1 )
297297 testURLParseError (t , err )
298298}
299+
300+ func TestBranchWebHookPayload_Marshal (t * testing.T ) {
301+ testJSONMarshal (t , & WebHookPayload {}, "{}" )
302+
303+ v := & WebHookPayload {
304+ Action : String ("action" ),
305+ After : String ("after" ),
306+ Before : String ("before" ),
307+ Commits : []* WebHookCommit {
308+ {
309+ Added : []string {"1" , "2" , "3" },
310+ Author : & WebHookAuthor {
311+ Email : String ("abc@gmail.com" ),
312+ Name : String ("abc" ),
313+ Username : String ("abc_12" ),
314+ },
315+ Committer : & WebHookAuthor {
316+ Email : String ("abc@gmail.com" ),
317+ Name : String ("abc" ),
318+ Username : String ("abc_12" ),
319+ },
320+ ID : String ("1" ),
321+ Message : String ("WebHookCommit" ),
322+ Modified : []string {"abc" , "efg" , "erd" },
323+ Removed : []string {"cmd" , "rti" , "duv" },
324+ },
325+ },
326+ Compare : String ("compare" ),
327+ Created : Bool (true ),
328+ Forced : Bool (false ),
329+ HeadCommit : & WebHookCommit {
330+ Added : []string {"1" , "2" , "3" },
331+ Author : & WebHookAuthor {
332+ Email : String ("abc@gmail.com" ),
333+ Name : String ("abc" ),
334+ Username : String ("abc_12" ),
335+ },
336+ Committer : & WebHookAuthor {
337+ Email : String ("abc@gmail.com" ),
338+ Name : String ("abc" ),
339+ Username : String ("abc_12" ),
340+ },
341+ ID : String ("1" ),
342+ Message : String ("WebHookCommit" ),
343+ Modified : []string {"abc" , "efg" , "erd" },
344+ Removed : []string {"cmd" , "rti" , "duv" },
345+ },
346+ Installation : & Installation {
347+ ID : Int64 (12 ),
348+ },
349+ Organization : & Organization {
350+ ID : Int64 (22 ),
351+ },
352+ Pusher : & User {
353+ Login : String ("rd@yahoo.com" ),
354+ ID : Int64 (112 ),
355+ },
356+ Repo : & Repository {
357+ ID : Int64 (321 ),
358+ NodeID : String ("node_321" ),
359+ },
360+ Sender : & User {
361+ Login : String ("st@gmail.com" ),
362+ ID : Int64 (202 ),
363+ },
364+ }
365+
366+ want := `{
367+ "action": "action",
368+ "after": "after",
369+ "before": "before",
370+ "commits": [
371+ {
372+ "added": ["1", "2", "3"],
373+ "author":{
374+ "email": "abc@gmail.com",
375+ "name": "abc",
376+ "username": "abc_12"
377+ },
378+ "committer": {
379+ "email": "abc@gmail.com",
380+ "name": "abc",
381+ "username": "abc_12"
382+ },
383+ "id": "1",
384+ "message": "WebHookCommit",
385+ "modified": ["abc", "efg", "erd"],
386+ "removed": ["cmd", "rti", "duv"]
387+ }
388+ ],
389+ "compare": "compare",
390+ "created": true,
391+ "forced": false,
392+ "head_commit": {
393+ "added": ["1", "2", "3"],
394+ "author":{
395+ "email": "abc@gmail.com",
396+ "name": "abc",
397+ "username": "abc_12"
398+ },
399+ "committer": {
400+ "email": "abc@gmail.com",
401+ "name": "abc",
402+ "username": "abc_12"
403+ },
404+ "id": "1",
405+ "message": "WebHookCommit",
406+ "modified": ["abc", "efg", "erd"],
407+ "removed": ["cmd", "rti", "duv"]
408+ },
409+ "installation": {
410+ "id": 12
411+ },
412+ "organization": {
413+ "id" : 22
414+ },
415+ "pusher":{
416+ "login": "rd@yahoo.com",
417+ "id": 112
418+ },
419+ "repository":{
420+ "id": 321,
421+ "node_id": "node_321"
422+ },
423+ "sender":{
424+ "login": "st@gmail.com",
425+ "id": 202
426+ }
427+ }`
428+
429+ testJSONMarshal (t , v , want )
430+ }
431+
432+ func TestBranchWebHookAuthor_Marshal (t * testing.T ) {
433+ testJSONMarshal (t , & WebHookAuthor {}, "{}" )
434+
435+ v := & WebHookAuthor {
436+ Email : String ("abc@gmail.com" ),
437+ Name : String ("abc" ),
438+ Username : String ("abc_12" ),
439+ }
440+
441+ want := `{
442+ "email": "abc@gmail.com",
443+ "name": "abc",
444+ "username": "abc_12"
445+ }`
446+
447+ testJSONMarshal (t , v , want )
448+ }
449+
450+ func TestBranchWebHookCommit_Marshal (t * testing.T ) {
451+ testJSONMarshal (t , & WebHookCommit {}, "{}" )
452+
453+ v := & WebHookCommit {
454+ Added : []string {"1" , "2" , "3" },
455+ Author : & WebHookAuthor {
456+ Email : String ("abc@gmail.com" ),
457+ Name : String ("abc" ),
458+ Username : String ("abc_12" ),
459+ },
460+ Committer : & WebHookAuthor {
461+ Email : String ("abc@gmail.com" ),
462+ Name : String ("abc" ),
463+ Username : String ("abc_12" ),
464+ },
465+ ID : String ("1" ),
466+ Message : String ("WebHookCommit" ),
467+ Modified : []string {"abc" , "efg" , "erd" },
468+ Removed : []string {"cmd" , "rti" , "duv" },
469+ }
470+
471+ want := `{
472+ "added": ["1", "2", "3"],
473+ "author":{
474+ "email": "abc@gmail.com",
475+ "name": "abc",
476+ "username": "abc_12"
477+ },
478+ "committer": {
479+ "email": "abc@gmail.com",
480+ "name": "abc",
481+ "username": "abc_12"
482+ },
483+ "id": "1",
484+ "message": "WebHookCommit",
485+ "modified": ["abc", "efg", "erd"],
486+ "removed": ["cmd", "rti", "duv"]
487+ }`
488+
489+ testJSONMarshal (t , v , want )
490+ }
491+
492+ func TestBranchCreateHookRequest_Marshal (t * testing.T ) {
493+ testJSONMarshal (t , & createHookRequest {}, "{}" )
494+
495+ v := & createHookRequest {
496+ Name : "abc" ,
497+ Events : []string {"1" , "2" , "3" },
498+ Active : Bool (true ),
499+ Config : map [string ]interface {}{
500+ "thing" : "@123" ,
501+ },
502+ }
503+
504+ want := `{
505+ "name": "abc",
506+ "active": true,
507+ "events": ["1","2","3"],
508+ "config":{
509+ "thing": "@123"
510+ }
511+ }`
512+
513+ testJSONMarshal (t , v , want )
514+ }
515+
516+ func TestBranchHook_Marshal (t * testing.T ) {
517+ testJSONMarshal (t , & Hook {}, "{}" )
518+
519+ v := & Hook {
520+ CreatedAt : & referenceTime ,
521+ UpdatedAt : & referenceTime ,
522+ URL : String ("url" ),
523+ ID : Int64 (1 ),
524+ Type : String ("type" ),
525+ Name : String ("name" ),
526+ TestURL : String ("testurl" ),
527+ PingURL : String ("pingurl" ),
528+ LastResponse : map [string ]interface {}{
529+ "item" : "item" ,
530+ },
531+ Config : map [string ]interface {}{
532+ "thing" : "@123" ,
533+ },
534+ Events : []string {"1" , "2" , "3" },
535+ Active : Bool (true ),
536+ }
537+
538+ want := `{
539+ "created_at": ` + referenceTimeStr + `,
540+ "updated_at": ` + referenceTimeStr + `,
541+ "url": "url",
542+ "id": 1,
543+ "type": "type",
544+ "name": "name",
545+ "test_url": "testurl",
546+ "ping_url": "pingurl",
547+ "last_response":{
548+ "item": "item"
549+ },
550+ "config":{
551+ "thing": "@123"
552+ },
553+ "events": ["1","2","3"],
554+ "active": true
555+ }`
556+
557+ testJSONMarshal (t , v , want )
558+ }
0 commit comments