| 1 |
// Copyright 2022 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"testing" |
| 10 |
"time" |
| 11 |
) |
| 12 |
|
| 13 |
func TestPullRequestThread_Marshal(t *testing.T) { |
| 14 |
testJSONMarshal(t, &PullRequestThread{}, "{}") |
| 15 |
|
| 16 |
createdAt := Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)} |
| 17 |
updatedAt := Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)} |
| 18 |
reactions := &Reactions{ |
| 19 |
TotalCount: Int(1), |
| 20 |
PlusOne: Int(1), |
| 21 |
MinusOne: Int(0), |
| 22 |
Laugh: Int(0), |
| 23 |
Confused: Int(0), |
| 24 |
Heart: Int(0), |
| 25 |
Hooray: Int(0), |
| 26 |
Rocket: Int(0), |
| 27 |
Eyes: Int(0), |
| 28 |
URL: String("u"), |
| 29 |
} |
| 30 |
user := &User{ |
| 31 |
Login: String("ll"), |
| 32 |
ID: Int64(123), |
| 33 |
AvatarURL: String("a"), |
| 34 |
GravatarID: String("g"), |
| 35 |
Name: String("n"), |
| 36 |
Company: String("c"), |
| 37 |
Blog: String("b"), |
| 38 |
Location: String("l"), |
| 39 |
Email: String("e"), |
| 40 |
Hireable: Bool(true), |
| 41 |
PublicRepos: Int(1), |
| 42 |
Followers: Int(1), |
| 43 |
Following: Int(1), |
| 44 |
CreatedAt: &Timestamp{referenceTime}, |
| 45 |
URL: String("u"), |
| 46 |
} |
| 47 |
comment := &PullRequestComment{ |
| 48 |
ID: Int64(10), |
| 49 |
InReplyTo: Int64(8), |
| 50 |
Body: String("Test comment"), |
| 51 |
Path: String("file1.txt"), |
| 52 |
DiffHunk: String("@@ -16,33 +16,40 @@ fmt.Println()"), |
| 53 |
PullRequestReviewID: Int64(42), |
| 54 |
Position: Int(1), |
| 55 |
OriginalPosition: Int(4), |
| 56 |
StartLine: Int(2), |
| 57 |
Line: Int(3), |
| 58 |
OriginalLine: Int(2), |
| 59 |
OriginalStartLine: Int(2), |
| 60 |
Side: String("RIGHT"), |
| 61 |
StartSide: String("LEFT"), |
| 62 |
CommitID: String("ab"), |
| 63 |
OriginalCommitID: String("9c"), |
| 64 |
User: user, |
| 65 |
Reactions: reactions, |
| 66 |
CreatedAt: &createdAt, |
| 67 |
UpdatedAt: &updatedAt, |
| 68 |
URL: String("pullrequestcommentUrl"), |
| 69 |
HTMLURL: String("pullrequestcommentHTMLUrl"), |
| 70 |
PullRequestURL: String("pullrequestcommentPullRequestURL"), |
| 71 |
} |
| 72 |
|
| 73 |
u := &PullRequestThread{ |
| 74 |
ID: Int64(1), |
| 75 |
NodeID: String("nid"), |
| 76 |
Comments: []*PullRequestComment{comment, comment}, |
| 77 |
} |
| 78 |
|
| 79 |
want := `{ |
| 80 |
"id": 1, |
| 81 |
"node_id": "nid", |
| 82 |
"comments": [ |
| 83 |
{ |
| 84 |
"id": 10, |
| 85 |
"in_reply_to_id": 8, |
| 86 |
"body": "Test comment", |
| 87 |
"path": "file1.txt", |
| 88 |
"diff_hunk": "@@ -16,33 +16,40 @@ fmt.Println()", |
| 89 |
"pull_request_review_id": 42, |
| 90 |
"position": 1, |
| 91 |
"original_position": 4, |
| 92 |
"start_line": 2, |
| 93 |
"line": 3, |
| 94 |
"original_line": 2, |
| 95 |
"original_start_line": 2, |
| 96 |
"side": "RIGHT", |
| 97 |
"start_side": "LEFT", |
| 98 |
"commit_id": "ab", |
| 99 |
"original_commit_id": "9c", |
| 100 |
"user": { |
| 101 |
"login": "ll", |
| 102 |
"id": 123, |
| 103 |
"avatar_url": "a", |
| 104 |
"gravatar_id": "g", |
| 105 |
"name": "n", |
| 106 |
"company": "c", |
| 107 |
"blog": "b", |
| 108 |
"location": "l", |
| 109 |
"email": "e", |
| 110 |
"hireable": true, |
| 111 |
"public_repos": 1, |
| 112 |
"followers": 1, |
| 113 |
"following": 1, |
| 114 |
"created_at": ` + referenceTimeStr + `, |
| 115 |
"url": "u" |
| 116 |
}, |
| 117 |
"reactions": { |
| 118 |
"total_count": 1, |
| 119 |
"+1": 1, |
| 120 |
"-1": 0, |
| 121 |
"laugh": 0, |
| 122 |
"confused": 0, |
| 123 |
"heart": 0, |
| 124 |
"hooray": 0, |
| 125 |
"rocket": 0, |
| 126 |
"eyes": 0, |
| 127 |
"url": "u" |
| 128 |
}, |
| 129 |
"created_at": "2002-02-10T15:30:00Z", |
| 130 |
"updated_at": "2002-02-10T15:30:00Z", |
| 131 |
"url": "pullrequestcommentUrl", |
| 132 |
"html_url": "pullrequestcommentHTMLUrl", |
| 133 |
"pull_request_url": "pullrequestcommentPullRequestURL" |
| 134 |
}, |
| 135 |
{ |
| 136 |
"id": 10, |
| 137 |
"in_reply_to_id": 8, |
| 138 |
"body": "Test comment", |
| 139 |
"path": "file1.txt", |
| 140 |
"diff_hunk": "@@ -16,33 +16,40 @@ fmt.Println()", |
| 141 |
"pull_request_review_id": 42, |
| 142 |
"position": 1, |
| 143 |
"original_position": 4, |
| 144 |
"start_line": 2, |
| 145 |
"line": 3, |
| 146 |
"original_line": 2, |
| 147 |
"original_start_line": 2, |
| 148 |
"side": "RIGHT", |
| 149 |
"start_side": "LEFT", |
| 150 |
"commit_id": "ab", |
| 151 |
"original_commit_id": "9c", |
| 152 |
"user": { |
| 153 |
"login": "ll", |
| 154 |
"id": 123, |
| 155 |
"avatar_url": "a", |
| 156 |
"gravatar_id": "g", |
| 157 |
"name": "n", |
| 158 |
"company": "c", |
| 159 |
"blog": "b", |
| 160 |
"location": "l", |
| 161 |
"email": "e", |
| 162 |
"hireable": true, |
| 163 |
"public_repos": 1, |
| 164 |
"followers": 1, |
| 165 |
"following": 1, |
| 166 |
"created_at": ` + referenceTimeStr + `, |
| 167 |
"url": "u" |
| 168 |
}, |
| 169 |
"reactions": { |
| 170 |
"total_count": 1, |
| 171 |
"+1": 1, |
| 172 |
"-1": 0, |
| 173 |
"laugh": 0, |
| 174 |
"confused": 0, |
| 175 |
"heart": 0, |
| 176 |
"hooray": 0, |
| 177 |
"rocket": 0, |
| 178 |
"eyes": 0, |
| 179 |
"url": "u" |
| 180 |
}, |
| 181 |
"created_at": "2002-02-10T15:30:00Z", |
| 182 |
"updated_at": "2002-02-10T15:30:00Z", |
| 183 |
"url": "pullrequestcommentUrl", |
| 184 |
"html_url": "pullrequestcommentHTMLUrl", |
| 185 |
"pull_request_url": "pullrequestcommentPullRequestURL" |
| 186 |
} |
| 187 |
] |
| 188 |
}` |
| 189 |
|
| 190 |
testJSONMarshal(t, u, want) |
| 191 |
} |