From de09c7958c6b57655fc880c2e2bd8ced2672889b Mon Sep 17 00:00:00 2001 From: sagar23sj Date: Fri, 16 Jul 2021 15:55:33 +0530 Subject: [PATCH] Resources Covered : - PullRequestAutoMerge - PullRequest - PRLink - PRLinks - PullRequestBranch - NewPullRequest - PullRequestBranchUpdateOptions - PullRequestBranchUpdateResponse - pullRequestUpdate - PullRequestMergeResult - pullRequestMergeRequest --- github/pulls_test.go | 740 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 740 insertions(+) diff --git a/github/pulls_test.go b/github/pulls_test.go index 65febb079d5..b498193817d 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -841,3 +841,743 @@ func TestPullRequestsService_Merge_Blank_Message(t *testing.T) { t.Error("TestPullRequestsService_Merge_Blank_Message #2 did not make request") } } + +func TestPullRequestMergeRequest_Marshal(t *testing.T) { + testJSONMarshal(t, &pullRequestMergeRequest{}, "{}") + + u := &pullRequestMergeRequest{ + CommitMessage: String("cm"), + CommitTitle: "ct", + MergeMethod: "mm", + SHA: "sha", + } + + want := `{ + "commit_message": "cm", + "commit_title": "ct", + "merge_method": "mm", + "sha": "sha" + }` + + testJSONMarshal(t, u, want) +} + +func TestPullRequestMergeResult_Marshal(t *testing.T) { + testJSONMarshal(t, &PullRequestMergeResult{}, "{}") + + u := &PullRequestMergeResult{ + SHA: String("sha"), + Merged: Bool(false), + Message: String("msg"), + } + + want := `{ + "sha": "sha", + "merged": false, + "message": "msg" + }` + + testJSONMarshal(t, u, want) +} + +func TestPullRequestUpdate_Marshal(t *testing.T) { + testJSONMarshal(t, &pullRequestUpdate{}, "{}") + + u := &pullRequestUpdate{ + Title: String("title"), + Body: String("body"), + State: String("state"), + Base: String("base"), + MaintainerCanModify: Bool(false), + } + + want := `{ + "title": "title", + "body": "body", + "state": "state", + "base": "base", + "maintainer_can_modify": false + }` + + testJSONMarshal(t, u, want) +} + +func TestPullRequestBranchUpdateResponse_Marshal(t *testing.T) { + testJSONMarshal(t, &PullRequestBranchUpdateResponse{}, "{}") + + u := &PullRequestBranchUpdateResponse{ + Message: String("message"), + URL: String("url"), + } + + want := `{ + "message": "message", + "url": "url" + }` + + testJSONMarshal(t, u, want) +} + +func TestPullRequestBranchUpdateOptions_Marshal(t *testing.T) { + testJSONMarshal(t, &PullRequestBranchUpdateOptions{}, "{}") + + u := &PullRequestBranchUpdateOptions{ + ExpectedHeadSHA: String("eh"), + } + + want := `{ + "expected_head_sha": "eh" + }` + + testJSONMarshal(t, u, want) +} + +func TestNewPullRequest_Marshal(t *testing.T) { + testJSONMarshal(t, &NewPullRequest{}, "{}") + + u := &NewPullRequest{ + Title: String("eh"), + Head: String("eh"), + Base: String("eh"), + Body: String("eh"), + Issue: Int(1), + MaintainerCanModify: Bool(false), + Draft: Bool(false), + } + + want := `{ + "title": "eh", + "head": "eh", + "base": "eh", + "body": "eh", + "issue": 1, + "maintainer_can_modify": false, + "draft": false + }` + + testJSONMarshal(t, u, want) +} + +func TestPullRequestBranch_Marshal(t *testing.T) { + testJSONMarshal(t, &PullRequestBranch{}, "{}") + + u := &PullRequestBranch{ + Label: String("label"), + Ref: String("ref"), + SHA: String("sha"), + Repo: &Repository{ID: Int64(1)}, + User: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + } + + want := `{ + "label": "label", + "ref": "ref", + "sha": "sha", + "repo": { + "id": 1 + }, + "user": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestPRLink_Marshal(t *testing.T) { + testJSONMarshal(t, &PRLink{}, "{}") + + u := &PRLink{ + HRef: String("href"), + } + + want := `{ + "href": "href" + }` + + testJSONMarshal(t, u, want) +} + +func TestPRLinks_Marshal(t *testing.T) { + testJSONMarshal(t, &PRLinks{}, "{}") + + u := &PRLinks{ + Self: &PRLink{ + HRef: String("href"), + }, + HTML: &PRLink{ + HRef: String("href"), + }, + Issue: &PRLink{ + HRef: String("href"), + }, + Comments: &PRLink{ + HRef: String("href"), + }, + ReviewComments: &PRLink{ + HRef: String("href"), + }, + ReviewComment: &PRLink{ + HRef: String("href"), + }, + Commits: &PRLink{ + HRef: String("href"), + }, + Statuses: &PRLink{ + HRef: String("href"), + }, + } + + want := `{ + "self": { + "href": "href" + }, + "html": { + "href": "href" + }, + "issue": { + "href": "href" + }, + "comments": { + "href": "href" + }, + "review_comments": { + "href": "href" + }, + "review_comment": { + "href": "href" + }, + "commits": { + "href": "href" + }, + "statuses": { + "href": "href" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestPullRequestAutoMerge_Marshal(t *testing.T) { + testJSONMarshal(t, &PullRequestAutoMerge{}, "{}") + + u := &PullRequestAutoMerge{ + EnabledBy: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + MergeMethod: String("mm"), + CommitTitle: String("ct"), + CommitMessage: String("cm"), + } + + want := `{ + "enabled_by": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "merge_method": "mm", + "commit_title": "ct", + "commit_message": "cm" + }` + + testJSONMarshal(t, u, want) +} + +func TestPullRequest_Marshal(t *testing.T) { + testJSONMarshal(t, &PullRequest{}, "{}") + + u := &PullRequest{ + ID: Int64(1), + Number: Int(1), + State: String("state"), + Locked: Bool(false), + Title: String("title"), + Body: String("body"), + CreatedAt: &referenceTime, + UpdatedAt: &referenceTime, + ClosedAt: &referenceTime, + MergedAt: &referenceTime, + Labels: []*Label{{ID: Int64(1)}}, + User: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + Draft: Bool(false), + Merged: Bool(false), + Mergeable: Bool(false), + MergeableState: String("ms"), + MergedBy: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + MergeCommitSHA: String("mcs"), + Rebaseable: Bool(false), + Comments: Int(1), + Commits: Int(1), + Additions: Int(1), + Deletions: Int(1), + ChangedFiles: Int(1), + URL: String("url"), + HTMLURL: String("hurl"), + IssueURL: String("iurl"), + StatusesURL: String("surl"), + DiffURL: String("durl"), + PatchURL: String("purl"), + CommitsURL: String("curl"), + CommentsURL: String("comurl"), + ReviewCommentsURL: String("rcurls"), + ReviewCommentURL: String("rcurl"), + ReviewComments: Int(1), + Assignee: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + Assignees: []*User{ + { + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + }, + Milestone: &Milestone{ID: Int64(1)}, + MaintainerCanModify: Bool(true), + AuthorAssociation: String("aa"), + NodeID: String("nid"), + RequestedReviewers: []*User{ + { + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + }, + AutoMerge: &PullRequestAutoMerge{ + EnabledBy: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + MergeMethod: String("mm"), + CommitTitle: String("ct"), + CommitMessage: String("cm"), + }, + RequestedTeams: []*Team{{ID: Int64(1)}}, + Links: &PRLinks{ + Self: &PRLink{ + HRef: String("href"), + }, + HTML: &PRLink{ + HRef: String("href"), + }, + Issue: &PRLink{ + HRef: String("href"), + }, + Comments: &PRLink{ + HRef: String("href"), + }, + ReviewComments: &PRLink{ + HRef: String("href"), + }, + ReviewComment: &PRLink{ + HRef: String("href"), + }, + Commits: &PRLink{ + HRef: String("href"), + }, + Statuses: &PRLink{ + HRef: String("href"), + }, + }, + Head: &PullRequestBranch{ + Ref: String("r2"), + Repo: &Repository{ID: Int64(2)}, + }, + Base: &PullRequestBranch{ + Ref: String("r2"), + Repo: &Repository{ID: Int64(2)}, + }, + ActiveLockReason: String("alr"), + } + + want := `{ + "id": 1, + "number": 1, + "state": "state", + "locked": false, + "title": "title", + "body": "body", + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "closed_at": ` + referenceTimeStr + `, + "merged_at": ` + referenceTimeStr + `, + "labels": [ + { + "id": 1 + } + ], + "user": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "draft": false, + "merged": false, + "mergeable": false, + "mergeable_state": "ms", + "merged_by": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "merge_commit_sha": "mcs", + "rebaseable": false, + "comments": 1, + "commits": 1, + "additions": 1, + "deletions": 1, + "changed_files": 1, + "url": "url", + "html_url": "hurl", + "issue_url": "iurl", + "statuses_url": "surl", + "diff_url": "durl", + "patch_url": "purl", + "commits_url": "curl", + "comments_url": "comurl", + "review_comments_url": "rcurls", + "review_comment_url": "rcurl", + "review_comments": 1, + "assignee": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "assignees": [ + { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + } + ], + "milestone": { + "id": 1 + }, + "maintainer_can_modify": true, + "author_association": "aa", + "node_id": "nid", + "requested_reviewers": [ + { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + } + ], + "auto_merge": { + "enabled_by": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "merge_method": "mm", + "commit_title": "ct", + "commit_message": "cm" + }, + "requested_teams": [ + { + "id": 1 + } + ], + "_links": { + "self": { + "href": "href" + }, + "html": { + "href": "href" + }, + "issue": { + "href": "href" + }, + "comments": { + "href": "href" + }, + "review_comments": { + "href": "href" + }, + "review_comment": { + "href": "href" + }, + "commits": { + "href": "href" + }, + "statuses": { + "href": "href" + } + }, + "head": { + "ref": "r2", + "repo": { + "id": 2 + } + }, + "base": { + "ref": "r2", + "repo": { + "id": 2 + } + }, + "active_lock_reason": "alr" + }` + + testJSONMarshal(t, u, want) +}