Skip to content

Commit e526a4b

Browse files
committed
Resources Covered :
- RepositoryContent - RepositoryContentResponse - RepositoryContentFileOptions
1 parent 9cd1df3 commit e526a4b

File tree

1 file changed

+213
-0
lines changed

1 file changed

+213
-0
lines changed

github/repos_contents_test.go

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"testing"
1616

1717
"github.com/google/go-cmp/cmp"
18+
"golang.org/x/crypto/openpgp"
1819
)
1920

2021
func TestRepositoryContent_GetContent(t *testing.T) {
@@ -762,3 +763,215 @@ func TestRepositoriesService_GetContents_NoTrailingSlashInDirectoryApiPath(t *te
762763
t.Fatalf("Repositories.GetContents returned error: %v", err)
763764
}
764765
}
766+
767+
func TestRepositoryContent_Marshal(t *testing.T) {
768+
testJSONMarshal(t, &RepositoryContent{}, "{}")
769+
770+
r := &RepositoryContent{
771+
Type: String("type"),
772+
Target: String("target"),
773+
Encoding: String("encoding"),
774+
Size: Int(1),
775+
Name: String("name"),
776+
Path: String("path"),
777+
Content: String("content"),
778+
SHA: String("sha"),
779+
URL: String("url"),
780+
GitURL: String("gurl"),
781+
HTMLURL: String("hurl"),
782+
DownloadURL: String("durl"),
783+
}
784+
785+
want := `{
786+
"type": "type",
787+
"target": "target",
788+
"encoding": "encoding",
789+
"size": 1,
790+
"name": "name",
791+
"path": "path",
792+
"content": "content",
793+
"sha": "sha",
794+
"url": "url",
795+
"git_url": "gurl",
796+
"html_url": "hurl",
797+
"download_url": "durl"
798+
}`
799+
800+
testJSONMarshal(t, r, want)
801+
}
802+
803+
func TestRepositoryContentResponse_Marshal(t *testing.T) {
804+
testJSONMarshal(t, &RepositoryContentResponse{}, "{}")
805+
806+
r := &RepositoryContentResponse{
807+
Content: &RepositoryContent{
808+
Type: String("type"),
809+
Target: String("target"),
810+
Encoding: String("encoding"),
811+
Size: Int(1),
812+
Name: String("name"),
813+
Path: String("path"),
814+
Content: String("content"),
815+
SHA: String("sha"),
816+
URL: String("url"),
817+
GitURL: String("gurl"),
818+
HTMLURL: String("hurl"),
819+
DownloadURL: String("durl"),
820+
},
821+
Commit: Commit{
822+
SHA: String("s"),
823+
Author: &CommitAuthor{
824+
Date: &referenceTime,
825+
Name: String("n"),
826+
Email: String("e"),
827+
Login: String("u"),
828+
},
829+
Committer: &CommitAuthor{
830+
Date: &referenceTime,
831+
Name: String("n"),
832+
Email: String("e"),
833+
Login: String("u"),
834+
},
835+
Message: String("m"),
836+
Tree: &Tree{
837+
SHA: String("s"),
838+
Entries: []*TreeEntry{{
839+
SHA: String("s"),
840+
Path: String("p"),
841+
Mode: String("m"),
842+
Type: String("t"),
843+
Size: Int(1),
844+
Content: String("c"),
845+
URL: String("u"),
846+
}},
847+
Truncated: Bool(false),
848+
},
849+
Parents: nil,
850+
Stats: &CommitStats{
851+
Additions: Int(1),
852+
Deletions: Int(1),
853+
Total: Int(1),
854+
},
855+
HTMLURL: String("h"),
856+
URL: String("u"),
857+
Verification: &SignatureVerification{
858+
Verified: Bool(false),
859+
Reason: String("r"),
860+
Signature: String("s"),
861+
Payload: String("p"),
862+
},
863+
NodeID: String("n"),
864+
CommentCount: Int(1),
865+
SigningKey: &openpgp.Entity{},
866+
},
867+
}
868+
869+
want := `{
870+
"content": {
871+
"type": "type",
872+
"target": "target",
873+
"encoding": "encoding",
874+
"size": 1,
875+
"name": "name",
876+
"path": "path",
877+
"content": "content",
878+
"sha": "sha",
879+
"url": "url",
880+
"git_url": "gurl",
881+
"html_url": "hurl",
882+
"download_url": "durl"
883+
},
884+
"commit": {
885+
"sha": "s",
886+
"author": {
887+
"date": ` + referenceTimeStr + `,
888+
"name": "n",
889+
"email": "e",
890+
"username": "u"
891+
},
892+
"committer": {
893+
"date": ` + referenceTimeStr + `,
894+
"name": "n",
895+
"email": "e",
896+
"username": "u"
897+
},
898+
"message": "m",
899+
"tree": {
900+
"sha": "s",
901+
"tree": [
902+
{
903+
"sha": "s",
904+
"path": "p",
905+
"mode": "m",
906+
"type": "t",
907+
"size": 1,
908+
"content": "c",
909+
"url": "u"
910+
}
911+
],
912+
"truncated": false
913+
},
914+
"stats": {
915+
"additions": 1,
916+
"deletions": 1,
917+
"total": 1
918+
},
919+
"html_url": "h",
920+
"url": "u",
921+
"verification": {
922+
"verified": false,
923+
"reason": "r",
924+
"signature": "s",
925+
"payload": "p"
926+
},
927+
"node_id": "n",
928+
"comment_count": 1
929+
}
930+
}`
931+
932+
testJSONMarshal(t, r, want)
933+
}
934+
935+
func TestRepositoryContentFileOptions_Marshal(t *testing.T) {
936+
testJSONMarshal(t, &RepositoryContentFileOptions{}, "{}")
937+
938+
r := &RepositoryContentFileOptions{
939+
Message: String("type"),
940+
Content: []byte{1},
941+
SHA: String("type"),
942+
Branch: String("type"),
943+
Author: &CommitAuthor{
944+
Date: &referenceTime,
945+
Name: String("name"),
946+
Email: String("email"),
947+
Login: String("login"),
948+
},
949+
Committer: &CommitAuthor{
950+
Date: &referenceTime,
951+
Name: String("name"),
952+
Email: String("email"),
953+
Login: String("login"),
954+
},
955+
}
956+
957+
want := `{
958+
"message": "type",
959+
"content": "AQ==",
960+
"sha": "type",
961+
"branch": "type",
962+
"author": {
963+
"date": ` + referenceTimeStr + `,
964+
"name": "name",
965+
"email": "email",
966+
"username": "login"
967+
},
968+
"committer": {
969+
"date": ` + referenceTimeStr + `,
970+
"name": "name",
971+
"email": "email",
972+
"username": "login"
973+
}
974+
}`
975+
976+
testJSONMarshal(t, r, want)
977+
}

0 commit comments

Comments
 (0)