Skip to content

Commit 0491dfa

Browse files
authored
Add test cases for JSON resource marshaling (#1929)
1 parent 908fe35 commit 0491dfa

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed

github/authorizations_test.go

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,185 @@ func TestAuthorizationsService_DeleteImpersonation(t *testing.T) {
203203
return client.Authorizations.DeleteImpersonation(ctx, "u")
204204
})
205205
}
206+
207+
func TestAuthorizationUpdateRequest_Marshal(t *testing.T) {
208+
testJSONMarshal(t, &AuthorizationUpdateRequest{}, "{}")
209+
210+
u := &AuthorizationUpdateRequest{
211+
Scopes: []string{"s"},
212+
AddScopes: []string{"a"},
213+
RemoveScopes: []string{"r"},
214+
Note: String("n"),
215+
NoteURL: String("nu"),
216+
Fingerprint: String("f"),
217+
}
218+
219+
want := `{
220+
"scopes": ["s"],
221+
"add_scopes": ["a"],
222+
"remove_scopes": ["r"],
223+
"note": "n",
224+
"note_url": "nu",
225+
"fingerprint": "f"
226+
}`
227+
228+
testJSONMarshal(t, u, want)
229+
}
230+
231+
func TestAuthorizationRequest_Marshal(t *testing.T) {
232+
testJSONMarshal(t, &AuthorizationRequest{}, "{}")
233+
234+
u := &AuthorizationRequest{
235+
Scopes: []Scope{"s"},
236+
ClientID: String("cid"),
237+
ClientSecret: String("cs"),
238+
Note: String("n"),
239+
NoteURL: String("nu"),
240+
Fingerprint: String("f"),
241+
}
242+
243+
want := `{
244+
"scopes": ["s"],
245+
"client_id": "cid",
246+
"client_secret": "cs",
247+
"note": "n",
248+
"note_url": "nu",
249+
"fingerprint": "f"
250+
}`
251+
252+
testJSONMarshal(t, u, want)
253+
}
254+
255+
func TestAuthorizationApp_Marshal(t *testing.T) {
256+
testJSONMarshal(t, &AuthorizationApp{}, "{}")
257+
258+
u := &AuthorizationApp{
259+
URL: String("u"),
260+
Name: String("n"),
261+
ClientID: String("cid"),
262+
}
263+
264+
want := `{
265+
"url": "u",
266+
"name": "n",
267+
"client_id": "cid"
268+
}`
269+
270+
testJSONMarshal(t, u, want)
271+
}
272+
273+
func TestGrant_Marshal(t *testing.T) {
274+
testJSONMarshal(t, &Grant{}, "{}")
275+
276+
u := &Grant{
277+
ID: Int64(1),
278+
URL: String("u"),
279+
App: &AuthorizationApp{
280+
URL: String("u"),
281+
Name: String("n"),
282+
ClientID: String("cid"),
283+
},
284+
CreatedAt: &Timestamp{referenceTime},
285+
UpdatedAt: &Timestamp{referenceTime},
286+
Scopes: []string{"s"},
287+
}
288+
289+
want := `{
290+
"id": 1,
291+
"url": "u",
292+
"app": {
293+
"url": "u",
294+
"name": "n",
295+
"client_id": "cid"
296+
},
297+
"created_at": ` + referenceTimeStr + `,
298+
"updated_at": ` + referenceTimeStr + `,
299+
"scopes": ["s"]
300+
}`
301+
302+
testJSONMarshal(t, u, want)
303+
}
304+
305+
func TestAuthorization_Marshal(t *testing.T) {
306+
testJSONMarshal(t, &Authorization{}, "{}")
307+
308+
u := &Authorization{
309+
ID: Int64(1),
310+
URL: String("u"),
311+
Scopes: []Scope{"s"},
312+
Token: String("t"),
313+
TokenLastEight: String("tle"),
314+
HashedToken: String("ht"),
315+
App: &AuthorizationApp{
316+
URL: String("u"),
317+
Name: String("n"),
318+
ClientID: String("cid"),
319+
},
320+
Note: String("n"),
321+
NoteURL: String("nu"),
322+
UpdatedAt: &Timestamp{referenceTime},
323+
CreatedAt: &Timestamp{referenceTime},
324+
Fingerprint: String("f"),
325+
User: &User{
326+
Login: String("l"),
327+
ID: Int64(1),
328+
URL: String("u"),
329+
AvatarURL: String("a"),
330+
GravatarID: String("g"),
331+
Name: String("n"),
332+
Company: String("c"),
333+
Blog: String("b"),
334+
Location: String("l"),
335+
Email: String("e"),
336+
Hireable: Bool(true),
337+
Bio: String("b"),
338+
TwitterUsername: String("t"),
339+
PublicRepos: Int(1),
340+
Followers: Int(1),
341+
Following: Int(1),
342+
CreatedAt: &Timestamp{referenceTime},
343+
SuspendedAt: &Timestamp{referenceTime},
344+
},
345+
}
346+
347+
want := `{
348+
"id": 1,
349+
"url": "u",
350+
"scopes": ["s"],
351+
"token": "t",
352+
"token_last_eight": "tle",
353+
"hashed_token": "ht",
354+
"app": {
355+
"url": "u",
356+
"name": "n",
357+
"client_id": "cid"
358+
},
359+
"note": "n",
360+
"note_url": "nu",
361+
"updated_at": ` + referenceTimeStr + `,
362+
"created_at": ` + referenceTimeStr + `,
363+
"fingerprint": "f",
364+
"user": {
365+
"login": "l",
366+
"id": 1,
367+
"avatar_url": "a",
368+
"gravatar_id": "g",
369+
"name": "n",
370+
"company": "c",
371+
"blog": "b",
372+
"location": "l",
373+
"email": "e",
374+
"hireable": true,
375+
"bio": "b",
376+
"twitter_username": "t",
377+
"public_repos": 1,
378+
"followers": 1,
379+
"following": 1,
380+
"created_at": ` + referenceTimeStr + `,
381+
"suspended_at": ` + referenceTimeStr + `,
382+
"url": "u"
383+
}
384+
}`
385+
386+
testJSONMarshal(t, u, want)
387+
}

0 commit comments

Comments
 (0)