Skip to content

Commit 3452d5f

Browse files
committed
Add JSON marshaling tests (google#1799)
Helps google#55.
1 parent 7371919 commit 3452d5f

2 files changed

Lines changed: 104 additions & 82 deletions

File tree

‎github/pulls_reviewers_test.go‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,110 @@ import (
1313
"testing"
1414
)
1515

16+
func TestReviewersRequest_marshal(t *testing.T) {
17+
testJSONMarshal(t, &ReviewersRequest{}, "{}")
18+
19+
u := &ReviewersRequest{
20+
NodeID: String("n"),
21+
Reviewers: []string{"r"},
22+
TeamReviewers: []string{"t"},
23+
}
24+
25+
want := `{
26+
"node_id": "n",
27+
"reviewers": [
28+
"r"
29+
],
30+
"team_reviewers" : [
31+
"t"
32+
]
33+
}`
34+
35+
testJSONMarshal(t, u, want)
36+
}
37+
38+
func TestReviewers_marshal(t *testing.T) {
39+
testJSONMarshal(t, &Reviewers{}, "{}")
40+
41+
u := &Reviewers{
42+
Users: []*User{{
43+
Login: String("l"),
44+
ID: Int64(1),
45+
AvatarURL: String("a"),
46+
GravatarID: String("g"),
47+
Name: String("n"),
48+
Company: String("c"),
49+
Blog: String("b"),
50+
Location: String("l"),
51+
Email: String("e"),
52+
Hireable: Bool(true),
53+
PublicRepos: Int(1),
54+
Followers: Int(1),
55+
Following: Int(1),
56+
CreatedAt: &Timestamp{referenceTime},
57+
URL: String("u"),
58+
}},
59+
Teams: []*Team{{
60+
ID: Int64(1),
61+
NodeID: String("node"),
62+
Name: String("n"),
63+
Description: String("d"),
64+
URL: String("u"),
65+
Slug: String("s"),
66+
Permission: String("p"),
67+
Privacy: String("priv"),
68+
MembersCount: Int(1),
69+
ReposCount: Int(1),
70+
Organization: nil,
71+
MembersURL: String("m"),
72+
RepositoriesURL: String("r"),
73+
Parent: nil,
74+
LDAPDN: String("l"),
75+
}},
76+
}
77+
78+
want := `{
79+
"users" : [
80+
{
81+
"login": "l",
82+
"id": 1,
83+
"avatar_url": "a",
84+
"gravatar_id": "g",
85+
"name": "n",
86+
"company": "c",
87+
"blog": "b",
88+
"location": "l",
89+
"email": "e",
90+
"hireable": true,
91+
"public_repos": 1,
92+
"followers": 1,
93+
"following": 1,
94+
"created_at": ` + referenceTimeStr + `,
95+
"url": "u"
96+
}
97+
],
98+
"teams" : [
99+
{
100+
"id": 1,
101+
"node_id": "node",
102+
"name": "n",
103+
"description": "d",
104+
"url": "u",
105+
"slug": "s",
106+
"permission": "p",
107+
"privacy": "priv",
108+
"members_count": 1,
109+
"repos_count": 1,
110+
"members_url": "m",
111+
"repositories_url": "r",
112+
"ldap_dn": "l"
113+
}
114+
]
115+
}`
116+
117+
testJSONMarshal(t, u, want)
118+
}
119+
16120
func TestRequestReviewers(t *testing.T) {
17121
client, mux, _, teardown := setup()
18122
defer teardown()

‎github/pulls_reviews_test.go‎

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -14,88 +14,6 @@ import (
1414
"testing"
1515
)
1616

17-
func TestReviewers_marshall(t *testing.T) {
18-
testJSONMarshal(t, &Reviewers{}, "{}")
19-
20-
u := &Reviewers{
21-
Users: []*User{{
22-
Login: String("l"),
23-
ID: Int64(1),
24-
AvatarURL: String("a"),
25-
GravatarID: String("g"),
26-
Name: String("n"),
27-
Company: String("c"),
28-
Blog: String("b"),
29-
Location: String("l"),
30-
Email: String("e"),
31-
Hireable: Bool(true),
32-
PublicRepos: Int(1),
33-
Followers: Int(1),
34-
Following: Int(1),
35-
CreatedAt: &Timestamp{referenceTime},
36-
URL: String("u"),
37-
}},
38-
Teams: []*Team{{
39-
ID: Int64(1),
40-
NodeID: String("node"),
41-
Name: String("n"),
42-
Description: String("d"),
43-
URL: String("u"),
44-
Slug: String("s"),
45-
Permission: String("p"),
46-
Privacy: String("priv"),
47-
MembersCount: Int(1),
48-
ReposCount: Int(1),
49-
Organization: nil,
50-
MembersURL: String("m"),
51-
RepositoriesURL: String("r"),
52-
Parent: nil,
53-
LDAPDN: String("l"),
54-
}},
55-
}
56-
57-
want := `{
58-
"users" : [
59-
{
60-
"login": "l",
61-
"id": 1,
62-
"avatar_url": "a",
63-
"gravatar_id": "g",
64-
"name": "n",
65-
"company": "c",
66-
"blog": "b",
67-
"location": "l",
68-
"email": "e",
69-
"hireable": true,
70-
"public_repos": 1,
71-
"followers": 1,
72-
"following": 1,
73-
"created_at": ` + referenceTimeStr + `,
74-
"url": "u"
75-
}
76-
],
77-
"teams" : [
78-
{
79-
"id": 1,
80-
"node_id": "node",
81-
"name": "n",
82-
"description": "d",
83-
"url": "u",
84-
"slug": "s",
85-
"permission": "p",
86-
"privacy": "priv",
87-
"members_count": 1,
88-
"repos_count": 1,
89-
"members_url": "m",
90-
"repositories_url": "r",
91-
"ldap_dn": "l"
92-
}
93-
]
94-
}`
95-
96-
testJSONMarshal(t, u, want)
97-
}
98-
9917
func TestPullRequestsService_ListReviews(t *testing.T) {
10018
client, mux, _, teardown := setup()
10119
defer teardown()

0 commit comments

Comments
 (0)