@@ -15,6 +15,7 @@ import (
1515 "time"
1616
1717 "github.com/google/go-cmp/cmp"
18+ "golang.org/x/crypto/openpgp"
1819)
1920
2021func TestRepositoriesService_ListCommits (t * testing.T ) {
@@ -662,3 +663,307 @@ func TestRepositoriesService_ListBranchesHeadCommit(t *testing.T) {
662663 return resp , err
663664 })
664665}
666+
667+ func TestBranchCommit_Marshal (t * testing.T ) {
668+ testJSONMarshal (t , & BranchCommit {}, "{}" )
669+
670+ r := & BranchCommit {
671+ Name : String ("n" ),
672+ Commit : & Commit {
673+ SHA : String ("s" ),
674+ Author : & CommitAuthor {
675+ Date : & referenceTime ,
676+ Name : String ("n" ),
677+ Email : String ("e" ),
678+ Login : String ("u" ),
679+ },
680+ Committer : & CommitAuthor {
681+ Date : & referenceTime ,
682+ Name : String ("n" ),
683+ Email : String ("e" ),
684+ Login : String ("u" ),
685+ },
686+ Message : String ("m" ),
687+ Tree : & Tree {
688+ SHA : String ("s" ),
689+ Entries : []* TreeEntry {{
690+ SHA : String ("s" ),
691+ Path : String ("p" ),
692+ Mode : String ("m" ),
693+ Type : String ("t" ),
694+ Size : Int (1 ),
695+ Content : String ("c" ),
696+ URL : String ("u" ),
697+ }},
698+ Truncated : Bool (false ),
699+ },
700+ Parents : nil ,
701+ Stats : & CommitStats {
702+ Additions : Int (1 ),
703+ Deletions : Int (1 ),
704+ Total : Int (1 ),
705+ },
706+ HTMLURL : String ("h" ),
707+ URL : String ("u" ),
708+ Verification : & SignatureVerification {
709+ Verified : Bool (false ),
710+ Reason : String ("r" ),
711+ Signature : String ("s" ),
712+ Payload : String ("p" ),
713+ },
714+ NodeID : String ("n" ),
715+ CommentCount : Int (1 ),
716+ SigningKey : & openpgp.Entity {},
717+ },
718+ Protected : Bool (false ),
719+ }
720+
721+ want := `{
722+ "name": "n",
723+ "commit": {
724+ "sha": "s",
725+ "author": {
726+ "date": ` + referenceTimeStr + `,
727+ "name": "n",
728+ "email": "e",
729+ "username": "u"
730+ },
731+ "committer": {
732+ "date": ` + referenceTimeStr + `,
733+ "name": "n",
734+ "email": "e",
735+ "username": "u"
736+ },
737+ "message": "m",
738+ "tree": {
739+ "sha": "s",
740+ "tree": [
741+ {
742+ "sha": "s",
743+ "path": "p",
744+ "mode": "m",
745+ "type": "t",
746+ "size": 1,
747+ "content": "c",
748+ "url": "u"
749+ }
750+ ],
751+ "truncated": false
752+ },
753+ "stats": {
754+ "additions": 1,
755+ "deletions": 1,
756+ "total": 1
757+ },
758+ "html_url": "h",
759+ "url": "u",
760+ "verification": {
761+ "verified": false,
762+ "reason": "r",
763+ "signature": "s",
764+ "payload": "p"
765+ },
766+ "node_id": "n",
767+ "comment_count": 1
768+ },
769+ "protected": false
770+ }`
771+
772+ testJSONMarshal (t , r , want )
773+ }
774+
775+ func TestCommitsComparison_Marshal (t * testing.T ) {
776+ testJSONMarshal (t , & CommitsComparison {}, "{}" )
777+
778+ r := & CommitsComparison {
779+ BaseCommit : & RepositoryCommit {NodeID : String ("nid" )},
780+ MergeBaseCommit : & RepositoryCommit {NodeID : String ("nid" )},
781+ Status : String ("status" ),
782+ AheadBy : Int (1 ),
783+ BehindBy : Int (1 ),
784+ TotalCommits : Int (1 ),
785+ Commits : []* RepositoryCommit {
786+ {
787+ NodeID : String ("nid" ),
788+ },
789+ },
790+ Files : []* CommitFile {
791+ {
792+ SHA : String ("sha" ),
793+ },
794+ },
795+ HTMLURL : String ("hurl" ),
796+ PermalinkURL : String ("purl" ),
797+ DiffURL : String ("durl" ),
798+ PatchURL : String ("purl" ),
799+ URL : String ("url" ),
800+ }
801+
802+ want := `{
803+ "base_commit": {
804+ "node_id": "nid"
805+ },
806+ "merge_base_commit": {
807+ "node_id": "nid"
808+ },
809+ "status": "status",
810+ "ahead_by": 1,
811+ "behind_by": 1,
812+ "total_commits": 1,
813+ "commits": [
814+ {
815+ "node_id": "nid"
816+ }
817+ ],
818+ "files": [
819+ {
820+ "sha": "sha"
821+ }
822+ ],
823+ "html_url": "hurl",
824+ "permalink_url": "purl",
825+ "diff_url": "durl",
826+ "patch_url": "purl",
827+ "url": "url"
828+ }`
829+
830+ testJSONMarshal (t , r , want )
831+ }
832+
833+ func TestCommitFile_Marshal (t * testing.T ) {
834+ testJSONMarshal (t , & CommitFile {}, "{}" )
835+
836+ r := & CommitFile {
837+ SHA : String ("sha" ),
838+ Filename : String ("fn" ),
839+ Additions : Int (1 ),
840+ Deletions : Int (1 ),
841+ Changes : Int (1 ),
842+ Status : String ("status" ),
843+ Patch : String ("patch" ),
844+ BlobURL : String ("burl" ),
845+ RawURL : String ("rurl" ),
846+ ContentsURL : String ("curl" ),
847+ PreviousFilename : String ("pf" ),
848+ }
849+
850+ want := `{
851+ "sha": "sha",
852+ "filename": "fn",
853+ "additions": 1,
854+ "deletions": 1,
855+ "changes": 1,
856+ "status": "status",
857+ "patch": "patch",
858+ "blob_url": "burl",
859+ "raw_url": "rurl",
860+ "contents_url": "curl",
861+ "previous_filename": "pf"
862+ }`
863+
864+ testJSONMarshal (t , r , want )
865+ }
866+
867+ func TestCommitStats_Marshal (t * testing.T ) {
868+ testJSONMarshal (t , & CommitStats {}, "{}" )
869+
870+ r := & CommitStats {
871+ Additions : Int (1 ),
872+ Deletions : Int (1 ),
873+ Total : Int (1 ),
874+ }
875+
876+ want := `{
877+ "additions": 1,
878+ "deletions": 1,
879+ "total": 1
880+ }`
881+
882+ testJSONMarshal (t , r , want )
883+ }
884+
885+ func TestRepositoryCommit_Marshal (t * testing.T ) {
886+ testJSONMarshal (t , & RepositoryCommit {}, "{}" )
887+
888+ r := & RepositoryCommit {
889+ NodeID : String ("nid" ),
890+ SHA : String ("sha" ),
891+ Commit : & Commit {
892+ Message : String ("m" ),
893+ },
894+ Author : & User {
895+ Login : String ("l" ),
896+ },
897+ Committer : & User {
898+ Login : String ("l" ),
899+ },
900+ Parents : []* Commit {
901+ {
902+ SHA : String ("s" ),
903+ },
904+ },
905+ HTMLURL : String ("hurl" ),
906+ URL : String ("url" ),
907+ CommentsURL : String ("curl" ),
908+ Stats : & CommitStats {
909+ Additions : Int (104 ),
910+ Deletions : Int (4 ),
911+ Total : Int (108 ),
912+ },
913+ Files : []* CommitFile {
914+ {
915+ Filename : String ("f" ),
916+ Additions : Int (10 ),
917+ Deletions : Int (2 ),
918+ Changes : Int (12 ),
919+ Status : String ("s" ),
920+ Patch : String ("p" ),
921+ BlobURL : String ("b" ),
922+ RawURL : String ("r" ),
923+ ContentsURL : String ("c" ),
924+ },
925+ },
926+ }
927+
928+ want := `{
929+ "node_id": "nid",
930+ "sha": "sha",
931+ "commit": {
932+ "message": "m"
933+ },
934+ "author": {
935+ "login": "l"
936+ },
937+ "committer": {
938+ "login": "l"
939+ },
940+ "parents": [
941+ {
942+ "sha": "s"
943+ }
944+ ],
945+ "html_url": "hurl",
946+ "url": "url",
947+ "comments_url": "curl",
948+ "stats": {
949+ "additions": 104,
950+ "deletions": 4,
951+ "total": 108
952+ },
953+ "files": [
954+ {
955+ "filename": "f",
956+ "additions": 10,
957+ "deletions": 2,
958+ "changes": 12,
959+ "status": "s",
960+ "patch": "p",
961+ "blob_url": "b",
962+ "raw_url": "r",
963+ "contents_url": "c"
964+ }
965+ ]
966+ }`
967+
968+ testJSONMarshal (t , r , want )
969+ }
0 commit comments