Skip to content

Commit 8341f9b

Browse files
authored
Improve apps.go coverage (google#1702)
1 parent 96d6f8c commit 8341f9b

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

github/apps_test.go

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ func TestAppsService_Get_authenticatedApp(t *testing.T) {
3737
if !reflect.DeepEqual(app, want) {
3838
t.Errorf("Apps.Get returned %+v, want %+v", app, want)
3939
}
40+
41+
const methodName = "Get"
42+
testBadOptions(t, methodName, func() (err error) {
43+
_, _, err = client.Apps.Get(ctx, "\n")
44+
return err
45+
})
46+
47+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
48+
got, resp, err := client.Apps.Get(ctx, "")
49+
if got != nil {
50+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
51+
}
52+
return resp, err
53+
})
4054
}
4155

4256
func TestAppsService_Get_specifiedApp(t *testing.T) {
@@ -159,6 +173,15 @@ func TestAppsService_ListInstallations(t *testing.T) {
159173
if !reflect.DeepEqual(installations, want) {
160174
t.Errorf("Apps.ListInstallations returned %+v, want %+v", installations, want)
161175
}
176+
177+
const methodName = "ListInstallations"
178+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
179+
got, resp, err := client.Apps.ListInstallations(ctx, opt)
180+
if got != nil {
181+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
182+
}
183+
return resp, err
184+
})
162185
}
163186

164187
func TestAppsService_GetInstallation(t *testing.T) {
@@ -180,6 +203,20 @@ func TestAppsService_GetInstallation(t *testing.T) {
180203
if !reflect.DeepEqual(installation, want) {
181204
t.Errorf("Apps.GetInstallation returned %+v, want %+v", installation, want)
182205
}
206+
207+
const methodName = "GetInstallation"
208+
testBadOptions(t, methodName, func() (err error) {
209+
_, _, err = client.Apps.GetInstallation(ctx, -1)
210+
return err
211+
})
212+
213+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
214+
got, resp, err := client.Apps.GetInstallation(ctx, 1)
215+
if got != nil {
216+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
217+
}
218+
return resp, err
219+
})
183220
}
184221

185222
func TestAppsService_ListUserInstallations(t *testing.T) {
@@ -206,6 +243,15 @@ func TestAppsService_ListUserInstallations(t *testing.T) {
206243
if !reflect.DeepEqual(installations, want) {
207244
t.Errorf("Apps.ListUserInstallations returned %+v, want %+v", installations, want)
208245
}
246+
247+
const methodName = "ListUserInstallations"
248+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
249+
got, resp, err := client.Apps.ListUserInstallations(ctx, opt)
250+
if got != nil {
251+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
252+
}
253+
return resp, err
254+
})
209255
}
210256

211257
func TestAppsService_SuspendInstallation(t *testing.T) {
@@ -222,6 +268,16 @@ func TestAppsService_SuspendInstallation(t *testing.T) {
222268
if _, err := client.Apps.SuspendInstallation(ctx, 1); err != nil {
223269
t.Errorf("Apps.SuspendInstallation returned error: %v", err)
224270
}
271+
272+
const methodName = "SuspendInstallation"
273+
testBadOptions(t, methodName, func() (err error) {
274+
_, err = client.Apps.SuspendInstallation(ctx, -1)
275+
return err
276+
})
277+
278+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
279+
return client.Apps.SuspendInstallation(ctx, 1)
280+
})
225281
}
226282

227283
func TestAppsService_UnsuspendInstallation(t *testing.T) {
@@ -238,6 +294,16 @@ func TestAppsService_UnsuspendInstallation(t *testing.T) {
238294
if _, err := client.Apps.UnsuspendInstallation(ctx, 1); err != nil {
239295
t.Errorf("Apps.UnsuspendInstallation returned error: %v", err)
240296
}
297+
298+
const methodName = "UnsuspendInstallation"
299+
testBadOptions(t, methodName, func() (err error) {
300+
_, err = client.Apps.UnsuspendInstallation(ctx, -1)
301+
return err
302+
})
303+
304+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
305+
return client.Apps.UnsuspendInstallation(ctx, 1)
306+
})
241307
}
242308

243309
func TestAppsService_DeleteInstallation(t *testing.T) {
@@ -254,6 +320,16 @@ func TestAppsService_DeleteInstallation(t *testing.T) {
254320
if err != nil {
255321
t.Errorf("Apps.DeleteInstallation returned error: %v", err)
256322
}
323+
324+
const methodName = "DeleteInstallation"
325+
testBadOptions(t, methodName, func() (err error) {
326+
_, err = client.Apps.DeleteInstallation(ctx, -1)
327+
return err
328+
})
329+
330+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
331+
return client.Apps.DeleteInstallation(ctx, 1)
332+
})
257333
}
258334

259335
func TestAppsService_CreateInstallationToken(t *testing.T) {
@@ -275,6 +351,20 @@ func TestAppsService_CreateInstallationToken(t *testing.T) {
275351
if !reflect.DeepEqual(token, want) {
276352
t.Errorf("Apps.CreateInstallationToken returned %+v, want %+v", token, want)
277353
}
354+
355+
const methodName = "CreateInstallationToken"
356+
testBadOptions(t, methodName, func() (err error) {
357+
_, _, err = client.Apps.CreateInstallationToken(ctx, -1, nil)
358+
return err
359+
})
360+
361+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
362+
got, resp, err := client.Apps.CreateInstallationToken(ctx, 1, nil)
363+
if got != nil {
364+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
365+
}
366+
return resp, err
367+
})
278368
}
279369

280370
func TestAppsService_CreateInstallationTokenWithOptions(t *testing.T) {
@@ -346,6 +436,20 @@ func TestAppsService_CreateAttachement(t *testing.T) {
346436
if !reflect.DeepEqual(got, want) {
347437
t.Errorf("CreateAttachment = %+v, want %+v", got, want)
348438
}
439+
440+
const methodName = "CreateAttachment"
441+
testBadOptions(t, methodName, func() (err error) {
442+
_, _, err = client.Apps.CreateAttachment(ctx, -11, "\n", "\n")
443+
return err
444+
})
445+
446+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
447+
got, resp, err := client.Apps.CreateAttachment(ctx, 11, "title1", "body1")
448+
if got != nil {
449+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
450+
}
451+
return resp, err
452+
})
349453
}
350454

351455
func TestAppsService_FindOrganizationInstallation(t *testing.T) {
@@ -367,6 +471,20 @@ func TestAppsService_FindOrganizationInstallation(t *testing.T) {
367471
if !reflect.DeepEqual(installation, want) {
368472
t.Errorf("Apps.FindOrganizationInstallation returned %+v, want %+v", installation, want)
369473
}
474+
475+
const methodName = "FindOrganizationInstallation"
476+
testBadOptions(t, methodName, func() (err error) {
477+
_, _, err = client.Apps.FindOrganizationInstallation(ctx, "\n")
478+
return err
479+
})
480+
481+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
482+
got, resp, err := client.Apps.FindOrganizationInstallation(ctx, "o")
483+
if got != nil {
484+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
485+
}
486+
return resp, err
487+
})
370488
}
371489

372490
func TestAppsService_FindRepositoryInstallation(t *testing.T) {
@@ -388,6 +506,20 @@ func TestAppsService_FindRepositoryInstallation(t *testing.T) {
388506
if !reflect.DeepEqual(installation, want) {
389507
t.Errorf("Apps.FindRepositoryInstallation returned %+v, want %+v", installation, want)
390508
}
509+
510+
const methodName = "FindRepositoryInstallation"
511+
testBadOptions(t, methodName, func() (err error) {
512+
_, _, err = client.Apps.FindRepositoryInstallation(ctx, "\n", "\n")
513+
return err
514+
})
515+
516+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
517+
got, resp, err := client.Apps.FindRepositoryInstallation(ctx, "o", "r")
518+
if got != nil {
519+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
520+
}
521+
return resp, err
522+
})
391523
}
392524

393525
func TestAppsService_FindRepositoryInstallationByID(t *testing.T) {
@@ -409,6 +541,20 @@ func TestAppsService_FindRepositoryInstallationByID(t *testing.T) {
409541
if !reflect.DeepEqual(installation, want) {
410542
t.Errorf("Apps.FindRepositoryInstallationByID returned %+v, want %+v", installation, want)
411543
}
544+
545+
const methodName = "FindRepositoryInstallationByID"
546+
testBadOptions(t, methodName, func() (err error) {
547+
_, _, err = client.Apps.FindRepositoryInstallationByID(ctx, -1)
548+
return err
549+
})
550+
551+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
552+
got, resp, err := client.Apps.FindRepositoryInstallationByID(ctx, 1)
553+
if got != nil {
554+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
555+
}
556+
return resp, err
557+
})
412558
}
413559

414560
func TestAppsService_FindUserInstallation(t *testing.T) {
@@ -430,6 +576,20 @@ func TestAppsService_FindUserInstallation(t *testing.T) {
430576
if !reflect.DeepEqual(installation, want) {
431577
t.Errorf("Apps.FindUserInstallation returned %+v, want %+v", installation, want)
432578
}
579+
580+
const methodName = "FindUserInstallation"
581+
testBadOptions(t, methodName, func() (err error) {
582+
_, _, err = client.Apps.FindUserInstallation(ctx, "\n")
583+
return err
584+
})
585+
586+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
587+
got, resp, err := client.Apps.FindUserInstallation(ctx, "u")
588+
if got != nil {
589+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
590+
}
591+
return resp, err
592+
})
433593
}
434594

435595
// GetReadWriter converts a body interface into an io.ReadWriter object.

0 commit comments

Comments
 (0)