Skip to content

Commit d3f8bdf

Browse files
vaibhavsingh97gmlewis
authored andcommitted
Add test cases for JSON marshaling (#1144)
1 parent 3bd1b5e commit d3f8bdf

File tree

3 files changed

+365
-0
lines changed

3 files changed

+365
-0
lines changed

github/gists_comments_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,64 @@ import (
1212
"net/http"
1313
"reflect"
1414
"testing"
15+
"time"
1516
)
1617

18+
func TestGistComments_marshall(t *testing.T) {
19+
testJSONMarshal(t, &GistComment{}, "{}")
20+
21+
createdAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)
22+
23+
u := &GistComment{
24+
ID: Int64(1),
25+
URL: String("u"),
26+
Body: String("test gist comment"),
27+
User: &User{
28+
Login: String("ll"),
29+
ID: Int64(123),
30+
AvatarURL: String("a"),
31+
GravatarID: String("g"),
32+
Name: String("n"),
33+
Company: String("c"),
34+
Blog: String("b"),
35+
Location: String("l"),
36+
Email: String("e"),
37+
Hireable: Bool(true),
38+
PublicRepos: Int(1),
39+
Followers: Int(1),
40+
Following: Int(1),
41+
CreatedAt: &Timestamp{referenceTime},
42+
URL: String("u"),
43+
},
44+
CreatedAt: &createdAt,
45+
}
46+
47+
want := `{
48+
"id": 1,
49+
"url": "u",
50+
"body": "test gist comment",
51+
"user": {
52+
"login": "ll",
53+
"id": 123,
54+
"avatar_url": "a",
55+
"gravatar_id": "g",
56+
"name": "n",
57+
"company": "c",
58+
"blog": "b",
59+
"location": "l",
60+
"email": "e",
61+
"hireable": true,
62+
"public_repos": 1,
63+
"followers": 1,
64+
"following": 1,
65+
"created_at": ` + referenceTimeStr + `,
66+
"url": "u"
67+
},
68+
"created_at": "2002-02-10T15:30:00Z"
69+
}`
70+
71+
testJSONMarshal(t, u, want)
72+
}
1773
func TestGistsService_ListComments(t *testing.T) {
1874
client, mux, _, teardown := setup()
1975
defer teardown()

github/gists_test.go

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,215 @@ import (
1515
"time"
1616
)
1717

18+
func TestGist_marshall(t *testing.T) {
19+
testJSONMarshal(t, &Gist{}, "{}")
20+
21+
createdAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC)
22+
updatedAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC)
23+
24+
u := &Gist{
25+
ID: String("i"),
26+
Description: String("description"),
27+
Public: Bool(true),
28+
Owner: &User{
29+
Login: String("ll"),
30+
ID: Int64(123),
31+
AvatarURL: String("a"),
32+
GravatarID: String("g"),
33+
Name: String("n"),
34+
Company: String("c"),
35+
Blog: String("b"),
36+
Location: String("l"),
37+
Email: String("e"),
38+
Hireable: Bool(true),
39+
PublicRepos: Int(1),
40+
Followers: Int(1),
41+
Following: Int(1),
42+
CreatedAt: &Timestamp{referenceTime},
43+
URL: String("u"),
44+
},
45+
Files: map[GistFilename]GistFile{
46+
"gistfile.py": {
47+
Size: Int(167),
48+
Filename: String("gistfile.py"),
49+
Language: String("Python"),
50+
Type: String("application/x-python"),
51+
RawURL: String("raw-url"),
52+
Content: String("c"),
53+
},
54+
},
55+
Comments: Int(1),
56+
HTMLURL: String("html-url"),
57+
GitPullURL: String("gitpull-url"),
58+
GitPushURL: String("gitpush-url"),
59+
CreatedAt: &createdAt,
60+
UpdatedAt: &updatedAt,
61+
NodeID: String("node"),
62+
}
63+
64+
want := `{
65+
"id": "i",
66+
"description": "description",
67+
"public": true,
68+
"owner": {
69+
"login": "ll",
70+
"id": 123,
71+
"avatar_url": "a",
72+
"gravatar_id": "g",
73+
"name": "n",
74+
"company": "c",
75+
"blog": "b",
76+
"location": "l",
77+
"email": "e",
78+
"hireable": true,
79+
"public_repos": 1,
80+
"followers": 1,
81+
"following": 1,
82+
"created_at": ` + referenceTimeStr + `,
83+
"url": "u"
84+
},
85+
"files": {
86+
"gistfile.py": {
87+
"size": 167,
88+
"filename": "gistfile.py",
89+
"language": "Python",
90+
"type": "application/x-python",
91+
"raw_url": "raw-url",
92+
"content": "c"
93+
}
94+
},
95+
"comments": 1,
96+
"html_url": "html-url",
97+
"git_pull_url": "gitpull-url",
98+
"git_push_url": "gitpush-url",
99+
"created_at": "2010-02-10T10:10:00Z",
100+
"updated_at": "2010-02-10T10:10:00Z",
101+
"node_id": "node"
102+
}`
103+
104+
testJSONMarshal(t, u, want)
105+
}
106+
107+
func TestGistCommit_marshall(t *testing.T) {
108+
testJSONMarshal(t, &GistCommit{}, "{}")
109+
110+
u := &GistCommit{
111+
URL: String("u"),
112+
Version: String("v"),
113+
User: &User{
114+
Login: String("ll"),
115+
ID: Int64(123),
116+
AvatarURL: String("a"),
117+
GravatarID: String("g"),
118+
Name: String("n"),
119+
Company: String("c"),
120+
Blog: String("b"),
121+
Location: String("l"),
122+
Email: String("e"),
123+
Hireable: Bool(true),
124+
PublicRepos: Int(1),
125+
Followers: Int(1),
126+
Following: Int(1),
127+
CreatedAt: &Timestamp{referenceTime},
128+
URL: String("u"),
129+
},
130+
ChangeStatus: &CommitStats{
131+
Additions: Int(1),
132+
Deletions: Int(1),
133+
Total: Int(2),
134+
},
135+
CommittedAt: &Timestamp{referenceTime},
136+
NodeID: String("node"),
137+
}
138+
139+
want := `{
140+
"url": "u",
141+
"version": "v",
142+
"user": {
143+
"login": "ll",
144+
"id": 123,
145+
"avatar_url": "a",
146+
"gravatar_id": "g",
147+
"name": "n",
148+
"company": "c",
149+
"blog": "b",
150+
"location": "l",
151+
"email": "e",
152+
"hireable": true,
153+
"public_repos": 1,
154+
"followers": 1,
155+
"following": 1,
156+
"created_at": ` + referenceTimeStr + `,
157+
"url": "u"
158+
},
159+
"change_status": {
160+
"additions": 1,
161+
"deletions": 1,
162+
"total": 2
163+
},
164+
"committed_at": ` + referenceTimeStr + `,
165+
"node_id": "node"
166+
}`
167+
168+
testJSONMarshal(t, u, want)
169+
}
170+
171+
func TestGistFork_marshall(t *testing.T) {
172+
testJSONMarshal(t, &GistFork{}, "{}")
173+
174+
u := &GistFork{
175+
URL: String("u"),
176+
User: &User{
177+
Login: String("ll"),
178+
ID: Int64(123),
179+
AvatarURL: String("a"),
180+
GravatarID: String("g"),
181+
Name: String("n"),
182+
Company: String("c"),
183+
Blog: String("b"),
184+
Location: String("l"),
185+
Email: String("e"),
186+
Hireable: Bool(true),
187+
PublicRepos: Int(1),
188+
Followers: Int(1),
189+
Following: Int(1),
190+
CreatedAt: &Timestamp{referenceTime},
191+
URL: String("u"),
192+
},
193+
ID: String("id"),
194+
CreatedAt: &Timestamp{referenceTime},
195+
UpdatedAt: &Timestamp{referenceTime},
196+
NodeID: String("node"),
197+
}
198+
199+
want := `{
200+
"url": "u",
201+
"user": {
202+
"login": "ll",
203+
"id": 123,
204+
"avatar_url": "a",
205+
"gravatar_id": "g",
206+
"name": "n",
207+
"company": "c",
208+
"blog": "b",
209+
"location": "l",
210+
"email": "e",
211+
"hireable": true,
212+
"public_repos": 1,
213+
"followers": 1,
214+
"following": 1,
215+
"created_at": ` + referenceTimeStr + `,
216+
"url": "u"
217+
},
218+
"id": "id",
219+
"created_at": ` + referenceTimeStr + `,
220+
"updated_at": ` + referenceTimeStr + `,
221+
"node_id": "node"
222+
}`
223+
224+
testJSONMarshal(t, u, want)
225+
}
226+
18227
func TestGistsService_List_specifiedUser(t *testing.T) {
19228
client, mux, _, teardown := setup()
20229
defer teardown()

github/pulls_comments_test.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,106 @@ import (
1515
"time"
1616
)
1717

18+
func TestPullComments_marshall(t *testing.T) {
19+
testJSONMarshal(t, &PullRequestComment{}, "{}")
20+
21+
createdAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)
22+
updatedAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)
23+
reactions := &Reactions{
24+
TotalCount: Int(1),
25+
PlusOne: Int(1),
26+
MinusOne: Int(0),
27+
Laugh: Int(0),
28+
Confused: Int(0),
29+
Heart: Int(0),
30+
Hooray: Int(0),
31+
URL: String("u"),
32+
}
33+
34+
u := &PullRequestComment{
35+
ID: Int64(10),
36+
InReplyTo: Int64(8),
37+
Body: String("Test comment"),
38+
Path: String("file1.txt"),
39+
DiffHunk: String("@@ -16,33 +16,40 @@ fmt.Println()"),
40+
PullRequestReviewID: Int64(42),
41+
Position: Int(1),
42+
OriginalPosition: Int(4),
43+
CommitID: String("ab"),
44+
OriginalCommitID: String("9c"),
45+
User: &User{
46+
Login: String("ll"),
47+
ID: Int64(123),
48+
AvatarURL: String("a"),
49+
GravatarID: String("g"),
50+
Name: String("n"),
51+
Company: String("c"),
52+
Blog: String("b"),
53+
Location: String("l"),
54+
Email: String("e"),
55+
Hireable: Bool(true),
56+
PublicRepos: Int(1),
57+
Followers: Int(1),
58+
Following: Int(1),
59+
CreatedAt: &Timestamp{referenceTime},
60+
URL: String("u"),
61+
},
62+
Reactions: reactions,
63+
CreatedAt: &createdAt,
64+
UpdatedAt: &updatedAt,
65+
URL: String("pullrequestcommentUrl"),
66+
HTMLURL: String("pullrequestcommentHTMLUrl"),
67+
PullRequestURL: String("pullrequestcommentPullRequestURL"),
68+
}
69+
70+
want := `{
71+
"id": 10,
72+
"in_reply_to_id": 8,
73+
"body": "Test comment",
74+
"path": "file1.txt",
75+
"diff_hunk": "@@ -16,33 +16,40 @@ fmt.Println()",
76+
"pull_request_review_id": 42,
77+
"position": 1,
78+
"original_position": 4,
79+
"commit_id": "ab",
80+
"original_commit_id": "9c",
81+
"user": {
82+
"login": "ll",
83+
"id": 123,
84+
"avatar_url": "a",
85+
"gravatar_id": "g",
86+
"name": "n",
87+
"company": "c",
88+
"blog": "b",
89+
"location": "l",
90+
"email": "e",
91+
"hireable": true,
92+
"public_repos": 1,
93+
"followers": 1,
94+
"following": 1,
95+
"created_at": ` + referenceTimeStr + `,
96+
"url": "u"
97+
},
98+
"reactions": {
99+
"total_count": 1,
100+
"+1": 1,
101+
"-1": 0,
102+
"laugh": 0,
103+
"confused": 0,
104+
"heart": 0,
105+
"hooray": 0,
106+
"url": "u"
107+
},
108+
"created_at": "2002-02-10T15:30:00Z",
109+
"updated_at": "2002-02-10T15:30:00Z",
110+
"url": "pullrequestcommentUrl",
111+
"html_url": "pullrequestcommentHTMLUrl",
112+
"pull_request_url": "pullrequestcommentPullRequestURL"
113+
}`
114+
115+
testJSONMarshal(t, u, want)
116+
}
117+
18118
func TestPullRequestsService_ListComments_allPulls(t *testing.T) {
19119
client, mux, _, teardown := setup()
20120
defer teardown()

0 commit comments

Comments
 (0)