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