From 3bb730682d259d305b58136a780b18d04ce9721f Mon Sep 17 00:00:00 2001 From: sagar23sj Date: Mon, 12 Jul 2021 19:28:27 +0530 Subject: [PATCH] Resources Covered : - Issue - IssueRequest - PullRequestLinks - LockIssueOptions --- github/issues_test.go | 160 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/github/issues_test.go b/github/issues_test.go index 1bc42f3ae20..80bfb3ff6d2 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -433,3 +433,163 @@ func TestIsPullRequest(t *testing.T) { t.Errorf("expected i.IsPullRequest (%v) to return true, got false", i) } } + +func TestLockIssueOptions_Marshal(t *testing.T) { + testJSONMarshal(t, &LockIssueOptions{}, "{}") + + u := &LockIssueOptions{ + LockReason: "lr", + } + + want := `{ + "lock_reason": "lr" + }` + + testJSONMarshal(t, u, want) +} + +func TestPullRequestLinks_Marshal(t *testing.T) { + testJSONMarshal(t, &PullRequestLinks{}, "{}") + + u := &PullRequestLinks{ + URL: String("url"), + HTMLURL: String("hurl"), + DiffURL: String("durl"), + PatchURL: String("purl"), + } + + want := `{ + "url": "url", + "html_url": "hurl", + "diff_url": "durl", + "patch_url": "purl" + }` + + testJSONMarshal(t, u, want) +} + +func TestIssueRequest_Marshal(t *testing.T) { + testJSONMarshal(t, &IssueRequest{}, "{}") + + u := &IssueRequest{ + Title: String("url"), + Body: String("url"), + Labels: &[]string{"l"}, + Assignee: String("url"), + State: String("url"), + Milestone: Int(1), + Assignees: &[]string{"a"}, + } + + want := `{ + "title": "url", + "body": "url", + "labels": [ + "l" + ], + "assignee": "url", + "state": "url", + "milestone": 1, + "assignees": [ + "a" + ] + }` + + testJSONMarshal(t, u, want) +} + +func TestIssue_Marshal(t *testing.T) { + testJSONMarshal(t, &Issue{}, "{}") + + u := &Issue{ + ID: Int64(1), + Number: Int(1), + State: String("s"), + Locked: Bool(false), + Title: String("title"), + Body: String("body"), + AuthorAssociation: String("aa"), + User: &User{ID: Int64(1)}, + Labels: []*Label{{ID: Int64(1)}}, + Assignee: &User{ID: Int64(1)}, + Comments: Int(1), + ClosedAt: &referenceTime, + CreatedAt: &referenceTime, + UpdatedAt: &referenceTime, + ClosedBy: &User{ID: Int64(1)}, + URL: String("url"), + HTMLURL: String("hurl"), + CommentsURL: String("curl"), + EventsURL: String("eurl"), + LabelsURL: String("lurl"), + RepositoryURL: String("rurl"), + Milestone: &Milestone{ID: Int64(1)}, + PullRequestLinks: &PullRequestLinks{URL: String("url")}, + Repository: &Repository{ID: Int64(1)}, + Reactions: &Reactions{TotalCount: Int(1)}, + Assignees: []*User{{ID: Int64(1)}}, + NodeID: String("nid"), + TextMatches: []*TextMatch{{ObjectURL: String("ourl")}}, + ActiveLockReason: String("alr"), + } + + want := `{ + "id": 1, + "number": 1, + "state": "s", + "locked": false, + "title": "title", + "body": "body", + "author_association": "aa", + "user": { + "id": 1 + }, + "labels": [ + { + "id": 1 + } + ], + "assignee": { + "id": 1 + }, + "comments": 1, + "closed_at": ` + referenceTimeStr + `, + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "closed_by": { + "id": 1 + }, + "url": "url", + "html_url": "hurl", + "comments_url": "curl", + "events_url": "eurl", + "labels_url": "lurl", + "repository_url": "rurl", + "milestone": { + "id": 1 + }, + "pull_request": { + "url": "url" + }, + "repository": { + "id": 1 + }, + "reactions": { + "total_count": 1 + }, + "assignees": [ + { + "id": 1 + } + ], + "node_id": "nid", + "text_matches": [ + { + "object_url": "ourl" + } + ], + "active_lock_reason": "alr" + }` + + testJSONMarshal(t, u, want) +}