Skip to content

Commit 9e29843

Browse files
committed
Add test cases for JSON resource marshaling
Helps: google#55.
1 parent 81128b1 commit 9e29843

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

‎github/repos_releases_test.go‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,125 @@ func TestRepositoriesService_UploadReleaseAsset(t *testing.T) {
653653
})
654654
}
655655
}
656+
657+
func TestRepositoryReleaseRequest_Marshal(t *testing.T) {
658+
testJSONMarshal(t, &repositoryReleaseRequest{}, "{}")
659+
660+
u := &repositoryReleaseRequest{
661+
TagName: String("tn"),
662+
TargetCommitish: String("tc"),
663+
Name: String("name"),
664+
Body: String("body"),
665+
Draft: Bool(false),
666+
Prerelease: Bool(false),
667+
DiscussionCategoryName: String("dcn"),
668+
}
669+
670+
want := `{
671+
"tag_name": "tn",
672+
"target_commitish": "tc",
673+
"name": "name",
674+
"body": "body",
675+
"draft": false,
676+
"prerelease": false,
677+
"discussion_category_name": "dcn"
678+
}`
679+
680+
testJSONMarshal(t, u, want)
681+
}
682+
683+
func TestReleaseAsset_Marshal(t *testing.T) {
684+
testJSONMarshal(t, &ReleaseAsset{}, "{}")
685+
686+
u := &ReleaseAsset{
687+
ID: Int64(1),
688+
URL: String("url"),
689+
Name: String("name"),
690+
Label: String("label"),
691+
State: String("state"),
692+
ContentType: String("ct"),
693+
Size: Int(1),
694+
DownloadCount: Int(1),
695+
CreatedAt: &Timestamp{referenceTime},
696+
UpdatedAt: &Timestamp{referenceTime},
697+
BrowserDownloadURL: String("bdu"),
698+
Uploader: &User{ID: Int64(1)},
699+
NodeID: String("nid"),
700+
}
701+
702+
want := `{
703+
"id": 1,
704+
"url": "url",
705+
"name": "name",
706+
"label": "label",
707+
"state": "state",
708+
"content_type": "ct",
709+
"size": 1,
710+
"download_count": 1,
711+
"created_at": ` + referenceTimeStr + `,
712+
"updated_at": ` + referenceTimeStr + `,
713+
"browser_download_url": "bdu",
714+
"uploader": {
715+
"id": 1
716+
},
717+
"node_id": "nid"
718+
}`
719+
720+
testJSONMarshal(t, u, want)
721+
}
722+
723+
func TestRepositoryRelease_Marshal(t *testing.T) {
724+
testJSONMarshal(t, &RepositoryRelease{}, "{}")
725+
726+
u := &RepositoryRelease{
727+
TagName: String("tn"),
728+
TargetCommitish: String("tc"),
729+
Name: String("name"),
730+
Body: String("body"),
731+
Draft: Bool(false),
732+
Prerelease: Bool(false),
733+
DiscussionCategoryName: String("dcn"),
734+
ID: Int64(1),
735+
CreatedAt: &Timestamp{referenceTime},
736+
PublishedAt: &Timestamp{referenceTime},
737+
URL: String("url"),
738+
HTMLURL: String("hurl"),
739+
AssetsURL: String("aurl"),
740+
Assets: []*ReleaseAsset{{ID: Int64(1)}},
741+
UploadURL: String("uurl"),
742+
ZipballURL: String("zurl"),
743+
TarballURL: String("turl"),
744+
Author: &User{ID: Int64(1)},
745+
NodeID: String("nid"),
746+
}
747+
748+
want := `{
749+
"tag_name": "tn",
750+
"target_commitish": "tc",
751+
"name": "name",
752+
"body": "body",
753+
"draft": false,
754+
"prerelease": false,
755+
"discussion_category_name": "dcn",
756+
"id": 1,
757+
"created_at": ` + referenceTimeStr + `,
758+
"published_at": ` + referenceTimeStr + `,
759+
"url": "url",
760+
"html_url": "hurl",
761+
"assets_url": "aurl",
762+
"assets": [
763+
{
764+
"id": 1
765+
}
766+
],
767+
"upload_url": "uurl",
768+
"zipball_url": "zurl",
769+
"tarball_url": "turl",
770+
"author": {
771+
"id": 1
772+
},
773+
"node_id": "nid"
774+
}`
775+
776+
testJSONMarshal(t, u, want)
777+
}

0 commit comments

Comments
 (0)