From df88dd9538970888b81a73d41d6f0ae90129b067 Mon Sep 17 00:00:00 2001 From: Chris King Date: Sat, 2 Dec 2017 20:34:41 +0100 Subject: [PATCH] Remove global test variables in favor of local. (#766) This refactor removes the global test variables used by all tests, replacing them with local variables that are independent in each test. This is better style, easier to read and be confident about correctness, and allows tests to be parallelized in the future. Resolves #762. --- github/activity_events_test.go | 38 +++++++--- github/activity_notifications_test.go | 18 ++--- github/activity_star_test.go | 26 +++++-- github/activity_test.go | 2 +- github/activity_watching_test.go | 16 ++-- github/admin_stats_test.go | 2 +- github/admin_test.go | 4 +- github/apps_installation_test.go | 8 +- github/apps_marketplace_test.go | 16 ++-- github/apps_test.go | 12 +-- github/authorizations_test.go | 32 ++++---- github/gists_comments_test.go | 25 ++++-- github/gists_test.go | 61 ++++++++++----- github/git_blobs_test.go | 10 ++- github/git_commits_test.go | 10 ++- github/git_refs_test.go | 20 ++--- github/git_tags_test.go | 4 +- github/git_trees_test.go | 12 ++- github/github_test.go | 52 +++++-------- github/gitignore_test.go | 7 +- github/issues_assignees_test.go | 18 +++-- github/issues_comments_test.go | 27 +++++-- github/issues_events_test.go | 6 +- github/issues_labels_test.go | 55 +++++++++++--- github/issues_milestones_test.go | 25 ++++-- github/issues_test.go | 33 +++++--- github/issues_timeline_test.go | 2 +- github/licenses_test.go | 7 +- github/migrations_source_import_test.go | 16 ++-- github/migrations_test.go | 12 +-- github/misc_test.go | 16 ++-- github/orgs_hooks_test.go | 22 ++++-- github/orgs_members_test.go | 44 +++++++---- github/orgs_outside_collaborators_test.go | 5 +- github/orgs_projects_test.go | 4 +- github/orgs_teams_test.go | 74 ++++++++++++------ github/orgs_test.go | 21 ++++-- github/orgs_users_blocking_test.go | 8 +- github/projects_test.go | 30 ++++---- github/pulls_comments_test.go | 27 +++++-- github/pulls_reviewers_test.go | 8 +- github/pulls_reviews_test.go | 37 +++++++-- github/pulls_test.go | 40 ++++++---- github/reactions_test.go | 18 ++--- github/repos_collaborators_test.go | 26 +++++-- github/repos_comments_test.go | 30 ++++++-- github/repos_commits_test.go | 14 ++-- github/repos_community_health_test.go | 2 +- github/repos_contents_test.go | 28 +++---- github/repos_deployments_test.go | 12 +-- github/repos_forks_test.go | 10 ++- github/repos_hooks_test.go | 32 ++++++-- github/repos_invitations_test.go | 6 +- github/repos_keys_test.go | 25 ++++-- github/repos_merging_test.go | 2 +- github/repos_pages_test.go | 12 +-- github/repos_projects_test.go | 4 +- github/repos_releases_test.go | 30 ++++---- github/repos_stats_test.go | 10 +-- github/repos_statuses_test.go | 12 ++- github/repos_test.go | 92 ++++++++++++++--------- github/repos_traffic_test.go | 8 +- github/search_test.go | 14 ++-- github/users_administration_test.go | 8 +- github/users_blocking_test.go | 8 +- github/users_emails_test.go | 6 +- github/users_followers_test.go | 35 ++++++--- github/users_gpg_keys_test.go | 13 ++-- github/users_keys_test.go | 13 ++-- github/users_test.go | 21 +++--- 70 files changed, 898 insertions(+), 505 deletions(-) diff --git a/github/activity_events_test.go b/github/activity_events_test.go index 2b59d11be8e..dc92a98394c 100644 --- a/github/activity_events_test.go +++ b/github/activity_events_test.go @@ -15,7 +15,7 @@ import ( ) func TestActivityService_ListEvents(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestActivityService_ListEvents(t *testing.T) { } func TestActivityService_ListRepositoryEvents(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/events", func(w http.ResponseWriter, r *http.Request) { @@ -63,12 +63,15 @@ func TestActivityService_ListRepositoryEvents(t *testing.T) { } func TestActivityService_ListRepositoryEvents_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListRepositoryEvents(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestActivityService_ListIssueEventsForRepository(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/events", func(w http.ResponseWriter, r *http.Request) { @@ -92,12 +95,15 @@ func TestActivityService_ListIssueEventsForRepository(t *testing.T) { } func TestActivityService_ListIssueEventsForRepository_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListIssueEventsForRepository(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestActivityService_ListEventsForRepoNetwork(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/networks/o/r/events", func(w http.ResponseWriter, r *http.Request) { @@ -121,12 +127,15 @@ func TestActivityService_ListEventsForRepoNetwork(t *testing.T) { } func TestActivityService_ListEventsForRepoNetwork_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListEventsForRepoNetwork(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestActivityService_ListEventsForOrganization(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/events", func(w http.ResponseWriter, r *http.Request) { @@ -150,12 +159,15 @@ func TestActivityService_ListEventsForOrganization(t *testing.T) { } func TestActivityService_ListEventsForOrganization_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListEventsForOrganization(context.Background(), "%", nil) testURLParseError(t, err) } func TestActivityService_ListEventsPerformedByUser_all(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/events", func(w http.ResponseWriter, r *http.Request) { @@ -179,7 +191,7 @@ func TestActivityService_ListEventsPerformedByUser_all(t *testing.T) { } func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/events/public", func(w http.ResponseWriter, r *http.Request) { @@ -199,12 +211,15 @@ func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) { } func TestActivityService_ListEventsPerformedByUser_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListEventsPerformedByUser(context.Background(), "%", false, nil) testURLParseError(t, err) } func TestActivityService_ListEventsReceivedByUser_all(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/received_events", func(w http.ResponseWriter, r *http.Request) { @@ -228,7 +243,7 @@ func TestActivityService_ListEventsReceivedByUser_all(t *testing.T) { } func TestActivityService_ListEventsReceivedByUser_publicOnly(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/received_events/public", func(w http.ResponseWriter, r *http.Request) { @@ -248,12 +263,15 @@ func TestActivityService_ListEventsReceivedByUser_publicOnly(t *testing.T) { } func TestActivityService_ListEventsReceivedByUser_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListEventsReceivedByUser(context.Background(), "%", false, nil) testURLParseError(t, err) } func TestActivityService_ListUserEventsForOrganization(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/events/orgs/o", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/activity_notifications_test.go b/github/activity_notifications_test.go index cab8f94da8d..292e3e2433c 100644 --- a/github/activity_notifications_test.go +++ b/github/activity_notifications_test.go @@ -16,7 +16,7 @@ import ( ) func TestActivityService_ListNotification(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) { @@ -49,7 +49,7 @@ func TestActivityService_ListNotification(t *testing.T) { } func TestActivityService_ListRepositoryNotification(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) { @@ -69,7 +69,7 @@ func TestActivityService_ListRepositoryNotification(t *testing.T) { } func TestActivityService_MarkNotificationsRead(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) { @@ -87,7 +87,7 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) { } func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) { @@ -105,7 +105,7 @@ func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) { } func TestActivityService_GetThread(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications/threads/1", func(w http.ResponseWriter, r *http.Request) { @@ -125,7 +125,7 @@ func TestActivityService_GetThread(t *testing.T) { } func TestActivityService_MarkThreadRead(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications/threads/1", func(w http.ResponseWriter, r *http.Request) { @@ -140,7 +140,7 @@ func TestActivityService_MarkThreadRead(t *testing.T) { } func TestActivityService_GetThreadSubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications/threads/1/subscription", func(w http.ResponseWriter, r *http.Request) { @@ -160,7 +160,7 @@ func TestActivityService_GetThreadSubscription(t *testing.T) { } func TestActivityService_SetThreadSubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Subscription{Subscribed: Bool(true)} @@ -189,7 +189,7 @@ func TestActivityService_SetThreadSubscription(t *testing.T) { } func TestActivityService_DeleteThreadSubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/notifications/threads/1/subscription", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/activity_star_test.go b/github/activity_star_test.go index 542bfc66b4b..16ae695b3f5 100644 --- a/github/activity_star_test.go +++ b/github/activity_star_test.go @@ -15,7 +15,7 @@ import ( ) func TestActivityService_ListStargazers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stargazers", func(w http.ResponseWriter, r *http.Request) { @@ -40,7 +40,7 @@ func TestActivityService_ListStargazers(t *testing.T) { } func TestActivityService_ListStarred_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred", func(w http.ResponseWriter, r *http.Request) { @@ -61,7 +61,7 @@ func TestActivityService_ListStarred_authenticatedUser(t *testing.T) { } func TestActivityService_ListStarred_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/starred", func(w http.ResponseWriter, r *http.Request) { @@ -88,12 +88,15 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) { } func TestActivityService_ListStarred_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.ListStarred(context.Background(), "%", nil) testURLParseError(t, err) } func TestActivityService_IsStarred_hasStar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -111,7 +114,7 @@ func TestActivityService_IsStarred_hasStar(t *testing.T) { } func TestActivityService_IsStarred_noStar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -129,12 +132,15 @@ func TestActivityService_IsStarred_noStar(t *testing.T) { } func TestActivityService_IsStarred_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Activity.IsStarred(context.Background(), "%", "%") testURLParseError(t, err) } func TestActivityService_Star(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -148,12 +154,15 @@ func TestActivityService_Star(t *testing.T) { } func TestActivityService_Star_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Activity.Star(context.Background(), "%", "%") testURLParseError(t, err) } func TestActivityService_Unstar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -167,6 +176,9 @@ func TestActivityService_Unstar(t *testing.T) { } func TestActivityService_Unstar_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Activity.Unstar(context.Background(), "%", "%") testURLParseError(t, err) } diff --git a/github/activity_test.go b/github/activity_test.go index 98567a254b6..92b42d3a727 100644 --- a/github/activity_test.go +++ b/github/activity_test.go @@ -13,7 +13,7 @@ import ( ) func TestActivityService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/feeds", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/activity_watching_test.go b/github/activity_watching_test.go index d765f67e9e0..d3d0d9697de 100644 --- a/github/activity_watching_test.go +++ b/github/activity_watching_test.go @@ -15,7 +15,7 @@ import ( ) func TestActivityService_ListWatchers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscribers", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestActivityService_ListWatchers(t *testing.T) { } func TestActivityService_ListWatched_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/subscriptions", func(w http.ResponseWriter, r *http.Request) { @@ -62,7 +62,7 @@ func TestActivityService_ListWatched_authenticatedUser(t *testing.T) { } func TestActivityService_ListWatched_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/subscriptions", func(w http.ResponseWriter, r *http.Request) { @@ -85,7 +85,7 @@ func TestActivityService_ListWatched_specifiedUser(t *testing.T) { } func TestActivityService_GetRepositorySubscription_true(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { @@ -105,7 +105,7 @@ func TestActivityService_GetRepositorySubscription_true(t *testing.T) { } func TestActivityService_GetRepositorySubscription_false(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { @@ -125,7 +125,7 @@ func TestActivityService_GetRepositorySubscription_false(t *testing.T) { } func TestActivityService_GetRepositorySubscription_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { @@ -140,7 +140,7 @@ func TestActivityService_GetRepositorySubscription_error(t *testing.T) { } func TestActivityService_SetRepositorySubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Subscription{Subscribed: Bool(true)} @@ -169,7 +169,7 @@ func TestActivityService_SetRepositorySubscription(t *testing.T) { } func TestActivityService_DeleteRepositorySubscription(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/admin_stats_test.go b/github/admin_stats_test.go index d2d979a10e9..9433adc37b0 100644 --- a/github/admin_stats_test.go +++ b/github/admin_stats_test.go @@ -9,7 +9,7 @@ import ( ) func TestAdminService_GetAdminStats(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/enterprise/stats/all", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/admin_test.go b/github/admin_test.go index 32a870eb407..0e693a736a0 100644 --- a/github/admin_test.go +++ b/github/admin_test.go @@ -15,7 +15,7 @@ import ( ) func TestAdminService_UpdateUserLDAPMapping(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &UserLDAPMapping{ @@ -48,7 +48,7 @@ func TestAdminService_UpdateUserLDAPMapping(t *testing.T) { } func TestAdminService_UpdateTeamLDAPMapping(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &TeamLDAPMapping{ diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 130cbbc470e..f3950ebc1d0 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -14,7 +14,7 @@ import ( ) func TestAppsService_ListRepos(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/installation/repositories", func(w http.ResponseWriter, r *http.Request) { @@ -40,7 +40,7 @@ func TestAppsService_ListRepos(t *testing.T) { } func TestAppsService_ListUserRepos(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/installations/1/repositories", func(w http.ResponseWriter, r *http.Request) { @@ -66,7 +66,7 @@ func TestAppsService_ListUserRepos(t *testing.T) { } func TestAppsService_AddRepository(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { @@ -86,7 +86,7 @@ func TestAppsService_AddRepository(t *testing.T) { } func TestAppsService_RemoveRepository(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/apps_marketplace_test.go b/github/apps_marketplace_test.go index 151a72179cb..59c6b318222 100644 --- a/github/apps_marketplace_test.go +++ b/github/apps_marketplace_test.go @@ -14,7 +14,7 @@ import ( ) func TestMarketplaceService_ListPlans(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/marketplace_listing/plans", func(w http.ResponseWriter, r *http.Request) { @@ -41,7 +41,7 @@ func TestMarketplaceService_ListPlans(t *testing.T) { } func TestMarketplaceService_Stubbed_ListPlans(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/marketplace_listing/stubbed/plans", func(w http.ResponseWriter, r *http.Request) { @@ -64,7 +64,7 @@ func TestMarketplaceService_Stubbed_ListPlans(t *testing.T) { } func TestMarketplaceService_ListPlanAccountsForPlan(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/marketplace_listing/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) { @@ -87,7 +87,7 @@ func TestMarketplaceService_ListPlanAccountsForPlan(t *testing.T) { } func TestMarketplaceService_Stubbed_ListPlanAccountsForPlan(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/marketplace_listing/stubbed/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) { @@ -110,7 +110,7 @@ func TestMarketplaceService_Stubbed_ListPlanAccountsForPlan(t *testing.T) { } func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/marketplace_listing/accounts/1", func(w http.ResponseWriter, r *http.Request) { @@ -133,7 +133,7 @@ func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) { } func TestMarketplaceService_Stubbed_ListPlanAccountsForAccount(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/marketplace_listing/stubbed/accounts/1", func(w http.ResponseWriter, r *http.Request) { @@ -156,7 +156,7 @@ func TestMarketplaceService_Stubbed_ListPlanAccountsForAccount(t *testing.T) { } func TestMarketplaceService_ListMarketplacePurchasesForUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/marketplace_purchases", func(w http.ResponseWriter, r *http.Request) { @@ -179,7 +179,7 @@ func TestMarketplaceService_ListMarketplacePurchasesForUser(t *testing.T) { } func TestMarketplaceService_Stubbed_ListMarketplacePurchasesForUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/marketplace_purchases/stubbed", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/apps_test.go b/github/apps_test.go index 9ef1f468291..2a080964792 100644 --- a/github/apps_test.go +++ b/github/apps_test.go @@ -14,7 +14,7 @@ import ( ) func TestAppsService_Get_authenticatedApp(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/app", func(w http.ResponseWriter, r *http.Request) { @@ -35,7 +35,7 @@ func TestAppsService_Get_authenticatedApp(t *testing.T) { } func TestAppsService_Get_specifiedApp(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/apps/a", func(w http.ResponseWriter, r *http.Request) { @@ -56,7 +56,7 @@ func TestAppsService_Get_specifiedApp(t *testing.T) { } func TestAppsService_ListInstallations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/app/installations", func(w http.ResponseWriter, r *http.Request) { @@ -82,7 +82,7 @@ func TestAppsService_ListInstallations(t *testing.T) { } func TestAppsService_GetInstallation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/app/installations/1", func(w http.ResponseWriter, r *http.Request) { @@ -103,7 +103,7 @@ func TestAppsService_GetInstallation(t *testing.T) { } func TestAppsService_ListUserInstallations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/installations", func(w http.ResponseWriter, r *http.Request) { @@ -129,7 +129,7 @@ func TestAppsService_ListUserInstallations(t *testing.T) { } func TestAppsService_CreateInstallationToken(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/installations/1/access_tokens", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/authorizations_test.go b/github/authorizations_test.go index 61bf21252a4..fc39c199953 100644 --- a/github/authorizations_test.go +++ b/github/authorizations_test.go @@ -15,7 +15,7 @@ import ( ) func TestAuthorizationsService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/authorizations", func(w http.ResponseWriter, r *http.Request) { @@ -37,7 +37,7 @@ func TestAuthorizationsService_List(t *testing.T) { } func TestAuthorizationsService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/authorizations/1", func(w http.ResponseWriter, r *http.Request) { @@ -57,7 +57,7 @@ func TestAuthorizationsService_Get(t *testing.T) { } func TestAuthorizationsService_Create(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &AuthorizationRequest{ @@ -88,7 +88,7 @@ func TestAuthorizationsService_Create(t *testing.T) { } func TestAuthorizationsService_GetOrCreateForApp(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &AuthorizationRequest{ @@ -119,7 +119,7 @@ func TestAuthorizationsService_GetOrCreateForApp(t *testing.T) { } func TestAuthorizationsService_GetOrCreateForApp_Fingerprint(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &AuthorizationRequest{ @@ -151,7 +151,7 @@ func TestAuthorizationsService_GetOrCreateForApp_Fingerprint(t *testing.T) { } func TestAuthorizationsService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &AuthorizationUpdateRequest{ @@ -182,7 +182,7 @@ func TestAuthorizationsService_Edit(t *testing.T) { } func TestAuthorizationsService_Delete(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/authorizations/1", func(w http.ResponseWriter, r *http.Request) { @@ -197,7 +197,7 @@ func TestAuthorizationsService_Delete(t *testing.T) { } func TestAuthorizationsService_Check(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/id/tokens/t", func(w http.ResponseWriter, r *http.Request) { @@ -217,7 +217,7 @@ func TestAuthorizationsService_Check(t *testing.T) { } func TestAuthorizationsService_Reset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/id/tokens/t", func(w http.ResponseWriter, r *http.Request) { @@ -237,7 +237,7 @@ func TestAuthorizationsService_Reset(t *testing.T) { } func TestAuthorizationsService_Revoke(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/id/tokens/t", func(w http.ResponseWriter, r *http.Request) { @@ -252,7 +252,7 @@ func TestAuthorizationsService_Revoke(t *testing.T) { } func TestListGrants(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/grants", func(w http.ResponseWriter, r *http.Request) { @@ -272,7 +272,7 @@ func TestListGrants(t *testing.T) { } func TestListGrants_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/grants", func(w http.ResponseWriter, r *http.Request) { @@ -290,7 +290,7 @@ func TestListGrants_withOptions(t *testing.T) { } func TestGetGrant(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/grants/1", func(w http.ResponseWriter, r *http.Request) { @@ -310,7 +310,7 @@ func TestGetGrant(t *testing.T) { } func TestDeleteGrant(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/applications/grants/1", func(w http.ResponseWriter, r *http.Request) { @@ -324,7 +324,7 @@ func TestDeleteGrant(t *testing.T) { } func TestAuthorizationsService_CreateImpersonation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/admin/users/u/authorizations", func(w http.ResponseWriter, r *http.Request) { @@ -345,7 +345,7 @@ func TestAuthorizationsService_CreateImpersonation(t *testing.T) { } func TestAuthorizationsService_DeleteImpersonation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/admin/users/u/authorizations", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/gists_comments_test.go b/github/gists_comments_test.go index 4b6841363ea..5b8026f784e 100644 --- a/github/gists_comments_test.go +++ b/github/gists_comments_test.go @@ -15,7 +15,7 @@ import ( ) func TestGistsService_ListComments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -37,12 +37,15 @@ func TestGistsService_ListComments(t *testing.T) { } func TestGistsService_ListComments_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.ListComments(context.Background(), "%", nil) testURLParseError(t, err) } func TestGistsService_GetComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/comments/2", func(w http.ResponseWriter, r *http.Request) { @@ -62,12 +65,15 @@ func TestGistsService_GetComment(t *testing.T) { } func TestGistsService_GetComment_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.GetComment(context.Background(), "%", 1) testURLParseError(t, err) } func TestGistsService_CreateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &GistComment{ID: Int(1), Body: String("b")} @@ -96,12 +102,15 @@ func TestGistsService_CreateComment(t *testing.T) { } func TestGistsService_CreateComment_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.CreateComment(context.Background(), "%", nil) testURLParseError(t, err) } func TestGistsService_EditComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &GistComment{ID: Int(1), Body: String("b")} @@ -130,12 +139,15 @@ func TestGistsService_EditComment(t *testing.T) { } func TestGistsService_EditComment_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.EditComment(context.Background(), "%", 1, nil) testURLParseError(t, err) } func TestGistsService_DeleteComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/comments/2", func(w http.ResponseWriter, r *http.Request) { @@ -149,6 +161,9 @@ func TestGistsService_DeleteComment(t *testing.T) { } func TestGistsService_DeleteComment_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Gists.DeleteComment(context.Background(), "%", 1) testURLParseError(t, err) } diff --git a/github/gists_test.go b/github/gists_test.go index 6065f277d8a..45ff9954b6a 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -16,7 +16,7 @@ import ( ) func TestGistsService_List_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() since := "2013-01-01T00:00:00Z" @@ -42,7 +42,7 @@ func TestGistsService_List_specifiedUser(t *testing.T) { } func TestGistsService_List_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists", func(w http.ResponseWriter, r *http.Request) { @@ -62,12 +62,15 @@ func TestGistsService_List_authenticatedUser(t *testing.T) { } func TestGistsService_List_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.List(context.Background(), "%", nil) testURLParseError(t, err) } func TestGistsService_ListAll(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() since := "2013-01-01T00:00:00Z" @@ -93,7 +96,7 @@ func TestGistsService_ListAll(t *testing.T) { } func TestGistsService_ListStarred(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() since := "2013-01-01T00:00:00Z" @@ -119,7 +122,7 @@ func TestGistsService_ListStarred(t *testing.T) { } func TestGistsService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1", func(w http.ResponseWriter, r *http.Request) { @@ -139,12 +142,15 @@ func TestGistsService_Get(t *testing.T) { } func TestGistsService_Get_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.Get(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_GetRevision(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/s", func(w http.ResponseWriter, r *http.Request) { @@ -164,12 +170,15 @@ func TestGistsService_GetRevision(t *testing.T) { } func TestGistsService_GetRevision_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.GetRevision(context.Background(), "%", "%") testURLParseError(t, err) } func TestGistsService_Create(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Gist{ @@ -222,7 +231,7 @@ func TestGistsService_Create(t *testing.T) { } func TestGistsService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Gist{ @@ -278,12 +287,15 @@ func TestGistsService_Edit(t *testing.T) { } func TestGistsService_Edit_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.Edit(context.Background(), "%", nil) testURLParseError(t, err) } func TestGistsService_ListCommits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/commits", func(w http.ResponseWriter, r *http.Request) { @@ -330,7 +342,7 @@ func TestGistsService_ListCommits(t *testing.T) { } func TestGistsService_ListCommits_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/commits", func(w http.ResponseWriter, r *http.Request) { @@ -348,7 +360,7 @@ func TestGistsService_ListCommits_withOptions(t *testing.T) { } func TestGistsService_Delete(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1", func(w http.ResponseWriter, r *http.Request) { @@ -362,12 +374,15 @@ func TestGistsService_Delete(t *testing.T) { } func TestGistsService_Delete_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Gists.Delete(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_Star(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/star", func(w http.ResponseWriter, r *http.Request) { @@ -381,12 +396,15 @@ func TestGistsService_Star(t *testing.T) { } func TestGistsService_Star_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Gists.Star(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_Unstar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/star", func(w http.ResponseWriter, r *http.Request) { @@ -400,12 +418,15 @@ func TestGistsService_Unstar(t *testing.T) { } func TestGistsService_Unstar_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Gists.Unstar(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_IsStarred_hasStar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/star", func(w http.ResponseWriter, r *http.Request) { @@ -423,7 +444,7 @@ func TestGistsService_IsStarred_hasStar(t *testing.T) { } func TestGistsService_IsStarred_noStar(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/star", func(w http.ResponseWriter, r *http.Request) { @@ -441,12 +462,15 @@ func TestGistsService_IsStarred_noStar(t *testing.T) { } func TestGistsService_IsStarred_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.IsStarred(context.Background(), "%") testURLParseError(t, err) } func TestGistsService_Fork(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/forks", func(w http.ResponseWriter, r *http.Request) { @@ -466,7 +490,7 @@ func TestGistsService_Fork(t *testing.T) { } func TestGistsService_ListForks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gists/1/forks", func(w http.ResponseWriter, r *http.Request) { @@ -502,6 +526,9 @@ func TestGistsService_ListForks(t *testing.T) { } func TestGistsService_Fork_invalidID(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gists.Fork(context.Background(), "%") testURLParseError(t, err) } diff --git a/github/git_blobs_test.go b/github/git_blobs_test.go index 00861bb9a64..0bf87a33dda 100644 --- a/github/git_blobs_test.go +++ b/github/git_blobs_test.go @@ -15,7 +15,7 @@ import ( ) func TestGitService_GetBlob(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/blobs/s", func(w http.ResponseWriter, r *http.Request) { @@ -44,12 +44,15 @@ func TestGitService_GetBlob(t *testing.T) { } func TestGitService_GetBlob_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.GetBlob(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestGitService_CreateBlob(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Blob{ @@ -93,6 +96,9 @@ func TestGitService_CreateBlob(t *testing.T) { } func TestGitService_CreateBlob_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.CreateBlob(context.Background(), "%", "%", &Blob{}) testURLParseError(t, err) } diff --git a/github/git_commits_test.go b/github/git_commits_test.go index cd392329ea2..ff8827f9035 100644 --- a/github/git_commits_test.go +++ b/github/git_commits_test.go @@ -15,7 +15,7 @@ import ( ) func TestGitService_GetCommit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/commits/s", func(w http.ResponseWriter, r *http.Request) { @@ -36,12 +36,15 @@ func TestGitService_GetCommit(t *testing.T) { } func TestGitService_GetCommit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.GetCommit(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestGitService_CreateCommit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Commit{ @@ -79,6 +82,9 @@ func TestGitService_CreateCommit(t *testing.T) { } func TestGitService_CreateCommit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.CreateCommit(context.Background(), "%", "%", &Commit{}) testURLParseError(t, err) } diff --git a/github/git_refs_test.go b/github/git_refs_test.go index 62025bf4446..3cae3c085fd 100644 --- a/github/git_refs_test.go +++ b/github/git_refs_test.go @@ -15,7 +15,7 @@ import ( ) func TestGitService_GetRef_singleRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -57,7 +57,7 @@ func TestGitService_GetRef_singleRef(t *testing.T) { } func TestGitService_GetRef_multipleRefs(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -95,7 +95,7 @@ func TestGitService_GetRef_multipleRefs(t *testing.T) { } func TestGitService_GetRefs_singleRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -138,7 +138,7 @@ func TestGitService_GetRefs_singleRef(t *testing.T) { } func TestGitService_GetRefs_multipleRefs(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -188,7 +188,7 @@ func TestGitService_GetRefs_multipleRefs(t *testing.T) { // TestGitService_GetRefs_noRefs tests for behaviour resulting from an unexpected GH response. This should never actually happen. func TestGitService_GetRefs_noRefs(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { @@ -205,7 +205,7 @@ func TestGitService_GetRefs_noRefs(t *testing.T) { } func TestGitService_ListRefs(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs", func(w http.ResponseWriter, r *http.Request) { @@ -264,7 +264,7 @@ func TestGitService_ListRefs(t *testing.T) { } func TestGitService_ListRefs_options(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/t", func(w http.ResponseWriter, r *http.Request) { @@ -286,7 +286,7 @@ func TestGitService_ListRefs_options(t *testing.T) { } func TestGitService_CreateRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() args := &createRefRequest{ @@ -350,7 +350,7 @@ func TestGitService_CreateRef(t *testing.T) { } func TestGitService_UpdateRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() args := &updateRefRequest{ @@ -410,7 +410,7 @@ func TestGitService_UpdateRef(t *testing.T) { } func TestGitService_DeleteRef(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/git_tags_test.go b/github/git_tags_test.go index 7031fe8a4d3..8a676a3b453 100644 --- a/github/git_tags_test.go +++ b/github/git_tags_test.go @@ -15,7 +15,7 @@ import ( ) func TestGitService_GetTag(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/tags/s", func(w http.ResponseWriter, r *http.Request) { @@ -37,7 +37,7 @@ func TestGitService_GetTag(t *testing.T) { } func TestGitService_CreateTag(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &createTagRequest{Tag: String("t"), Object: String("s")} diff --git a/github/git_trees_test.go b/github/git_trees_test.go index 29728eee381..176cbac079d 100644 --- a/github/git_trees_test.go +++ b/github/git_trees_test.go @@ -15,7 +15,7 @@ import ( ) func TestGitService_GetTree(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/git/trees/s", func(w http.ResponseWriter, r *http.Request) { @@ -47,12 +47,15 @@ func TestGitService_GetTree(t *testing.T) { } func TestGitService_GetTree_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.GetTree(context.Background(), "%", "%", "%", false) testURLParseError(t, err) } func TestGitService_CreateTree(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []TreeEntry{ @@ -118,7 +121,7 @@ func TestGitService_CreateTree(t *testing.T) { } func TestGitService_CreateTree_Content(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []TreeEntry{ @@ -186,6 +189,9 @@ func TestGitService_CreateTree_Content(t *testing.T) { } func TestGitService_CreateTree_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Git.CreateTree(context.Background(), "%", "%", "", nil) testURLParseError(t, err) } diff --git a/github/github_test.go b/github/github_test.go index 47d463d8fb4..8f578f82bcc 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -22,17 +22,6 @@ import ( "time" ) -var ( - // mux is the HTTP request multiplexer used with the test server. - mux *http.ServeMux - - // client is the GitHub client being tested. - client *Client - - // server is a test HTTP server used to provide mock API responses. - server *httptest.Server -) - const ( // baseURLPath is a non-empty Client.BaseURL path to use during tests, // to ensure relative URLs are used for all endpoints. See issue #752. @@ -42,8 +31,8 @@ const ( // setup sets up a test HTTP server along with a github.Client that is // configured to talk to that test server. Tests should register handlers on // mux which provide mock responses for the API method being tested. -func setup() { - // test server +func setup() (client *Client, mux *http.ServeMux, serverURL string, teardown func()) { + // mux is the HTTP request multiplexer used with the test server. mux = http.NewServeMux() // We want to ensure that tests catch mistakes where the endpoint URL is @@ -61,18 +50,17 @@ func setup() { http.Error(w, "Client.BaseURL path prefix is not preserved in the request URL.", http.StatusInternalServerError) }) - server = httptest.NewServer(apiHandler) + // server is a test HTTP server used to provide mock API responses. + server := httptest.NewServer(apiHandler) - // github client configured to use test server + // client is the GitHub client being tested and is + // configured to use test server. client = NewClient(nil) url, _ := url.Parse(server.URL + baseURLPath + "/") client.BaseURL = url client.UploadURL = url -} -// teardown closes the test HTTP server. -func teardown() { - server.Close() + return client, mux, server.URL, server.Close } // openTestFile creates a new file with the given name and content for testing. @@ -417,7 +405,7 @@ func TestResponse_populatePageValues_invalid(t *testing.T) { } func TestDo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() type foo struct { @@ -442,7 +430,7 @@ func TestDo(t *testing.T) { } func TestDo_httpError(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -464,7 +452,7 @@ func TestDo_httpError(t *testing.T) { // function. A redirect loop is pretty unlikely to occur within the GitHub // API, but does allow us to exercise the right code path. func TestDo_redirectLoop(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -505,7 +493,7 @@ func TestDo_sanitizeURL(t *testing.T) { } func TestDo_rateLimit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -533,7 +521,7 @@ func TestDo_rateLimit(t *testing.T) { // ensure rate limit is still parsed, even for error responses func TestDo_rateLimit_errorResponse(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -565,7 +553,7 @@ func TestDo_rateLimit_errorResponse(t *testing.T) { // Ensure *RateLimitError is returned when API rate limit is exceeded. func TestDo_rateLimit_rateLimitError(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -604,7 +592,7 @@ func TestDo_rateLimit_rateLimitError(t *testing.T) { // Ensure a network call is not made when it's known that API rate limit is still exceeded. func TestDo_rateLimit_noNetworkCall(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() reset := time.Now().UTC().Add(time.Minute).Round(time.Second) // Rate reset is a minute from now, with 1 second precision. @@ -659,7 +647,7 @@ func TestDo_rateLimit_noNetworkCall(t *testing.T) { // Ensure *AbuseRateLimitError is returned when the response indicates that // the client has triggered an abuse detection mechanism. func TestDo_rateLimit_abuseRateLimitError(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -690,7 +678,7 @@ func TestDo_rateLimit_abuseRateLimitError(t *testing.T) { // Ensure *AbuseRateLimitError.RetryAfter is parsed correctly. func TestDo_rateLimit_abuseRateLimitError_retryAfter(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -722,7 +710,7 @@ func TestDo_rateLimit_abuseRateLimitError_retryAfter(t *testing.T) { } func TestDo_noContent(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -861,7 +849,7 @@ func TestError_Error(t *testing.T) { } func TestRateLimits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/rate_limit", func(w http.ResponseWriter, r *http.Request) { @@ -904,7 +892,7 @@ func TestRateLimits(t *testing.T) { } func TestUnauthenticatedRateLimitedTransport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -970,7 +958,7 @@ func TestUnauthenticatedRateLimitedTransport_transport(t *testing.T) { } func TestBasicAuthTransport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() username, password, otp := "u", "p", "123456" diff --git a/github/gitignore_test.go b/github/gitignore_test.go index e5a62643b5d..cdb82237ce7 100644 --- a/github/gitignore_test.go +++ b/github/gitignore_test.go @@ -14,7 +14,7 @@ import ( ) func TestGitignoresService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gitignore/templates", func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +34,7 @@ func TestGitignoresService_List(t *testing.T) { } func TestGitignoresService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/gitignore/templates/name", func(w http.ResponseWriter, r *http.Request) { @@ -54,6 +54,9 @@ func TestGitignoresService_Get(t *testing.T) { } func TestGitignoresService_Get_invalidTemplate(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Gitignores.Get(context.Background(), "%") testURLParseError(t, err) } diff --git a/github/issues_assignees_test.go b/github/issues_assignees_test.go index d88a7888a4e..b73cb60dee0 100644 --- a/github/issues_assignees_test.go +++ b/github/issues_assignees_test.go @@ -15,7 +15,7 @@ import ( ) func TestIssuesService_ListAssignees(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/assignees", func(w http.ResponseWriter, r *http.Request) { @@ -37,12 +37,15 @@ func TestIssuesService_ListAssignees(t *testing.T) { } func TestIssuesService_ListAssignees_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListAssignees(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_IsAssignee_true(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { @@ -59,7 +62,7 @@ func TestIssuesService_IsAssignee_true(t *testing.T) { } func TestIssuesService_IsAssignee_false(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { @@ -77,7 +80,7 @@ func TestIssuesService_IsAssignee_false(t *testing.T) { } func TestIssuesService_IsAssignee_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/assignees/u", func(w http.ResponseWriter, r *http.Request) { @@ -95,12 +98,15 @@ func TestIssuesService_IsAssignee_error(t *testing.T) { } func TestIssuesService_IsAssignee_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.IsAssignee(context.Background(), "%", "r", "u") testURLParseError(t, err) } func TestIssuesService_AddAssignees(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/assignees", func(w http.ResponseWriter, r *http.Request) { @@ -129,7 +135,7 @@ func TestIssuesService_AddAssignees(t *testing.T) { } func TestIssuesService_RemoveAssignees(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/assignees", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/issues_comments_test.go b/github/issues_comments_test.go index 78c486362f4..6ed42240dca 100644 --- a/github/issues_comments_test.go +++ b/github/issues_comments_test.go @@ -16,7 +16,7 @@ import ( ) func TestIssuesService_ListComments_allIssues(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments", func(w http.ResponseWriter, r *http.Request) { @@ -49,7 +49,7 @@ func TestIssuesService_ListComments_allIssues(t *testing.T) { } func TestIssuesService_ListComments_specificIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -70,12 +70,15 @@ func TestIssuesService_ListComments_specificIssue(t *testing.T) { } func TestIssuesService_ListComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListComments(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_GetComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -96,12 +99,15 @@ func TestIssuesService_GetComment(t *testing.T) { } func TestIssuesService_GetComment_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.GetComment(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestIssuesService_CreateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &IssueComment{Body: String("b")} @@ -130,12 +136,15 @@ func TestIssuesService_CreateComment(t *testing.T) { } func TestIssuesService_CreateComment_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.CreateComment(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_EditComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &IssueComment{Body: String("b")} @@ -164,12 +173,15 @@ func TestIssuesService_EditComment(t *testing.T) { } func TestIssuesService_EditComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.EditComment(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_DeleteComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -183,6 +195,9 @@ func TestIssuesService_DeleteComment(t *testing.T) { } func TestIssuesService_DeleteComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.DeleteComment(context.Background(), "%", "r", 1) testURLParseError(t, err) } diff --git a/github/issues_events_test.go b/github/issues_events_test.go index d85b6223eaa..c0133dd45ae 100644 --- a/github/issues_events_test.go +++ b/github/issues_events_test.go @@ -14,7 +14,7 @@ import ( ) func TestIssuesService_ListIssueEvents(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/events", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestIssuesService_ListIssueEvents(t *testing.T) { } func TestIssuesService_ListRepositoryEvents(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/events", func(w http.ResponseWriter, r *http.Request) { @@ -64,7 +64,7 @@ func TestIssuesService_ListRepositoryEvents(t *testing.T) { } func TestIssuesService_GetEvent(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/events/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/issues_labels_test.go b/github/issues_labels_test.go index 5380427a1e6..56c20e552fd 100644 --- a/github/issues_labels_test.go +++ b/github/issues_labels_test.go @@ -15,7 +15,7 @@ import ( ) func TestIssuesService_ListLabels(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/labels", func(w http.ResponseWriter, r *http.Request) { @@ -37,12 +37,15 @@ func TestIssuesService_ListLabels(t *testing.T) { } func TestIssuesService_ListLabels_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListLabels(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestIssuesService_GetLabel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/labels/n", func(w http.ResponseWriter, r *http.Request) { @@ -62,12 +65,15 @@ func TestIssuesService_GetLabel(t *testing.T) { } func TestIssuesService_GetLabel_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.GetLabel(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestIssuesService_CreateLabel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Label{Name: String("n")} @@ -96,12 +102,15 @@ func TestIssuesService_CreateLabel(t *testing.T) { } func TestIssuesService_CreateLabel_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.CreateLabel(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestIssuesService_EditLabel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Label{Name: String("z")} @@ -130,12 +139,15 @@ func TestIssuesService_EditLabel(t *testing.T) { } func TestIssuesService_EditLabel_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.EditLabel(context.Background(), "%", "%", "%", nil) testURLParseError(t, err) } func TestIssuesService_DeleteLabel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/labels/n", func(w http.ResponseWriter, r *http.Request) { @@ -149,12 +161,15 @@ func TestIssuesService_DeleteLabel(t *testing.T) { } func TestIssuesService_DeleteLabel_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.DeleteLabel(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestIssuesService_ListLabelsByIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/labels", func(w http.ResponseWriter, r *http.Request) { @@ -179,12 +194,15 @@ func TestIssuesService_ListLabelsByIssue(t *testing.T) { } func TestIssuesService_ListLabelsByIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListLabelsByIssue(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestIssuesService_AddLabelsToIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []string{"a", "b"} @@ -213,12 +231,15 @@ func TestIssuesService_AddLabelsToIssue(t *testing.T) { } func TestIssuesService_AddLabelsToIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.AddLabelsToIssue(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestIssuesService_RemoveLabelForIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/labels/l", func(w http.ResponseWriter, r *http.Request) { @@ -232,12 +253,15 @@ func TestIssuesService_RemoveLabelForIssue(t *testing.T) { } func TestIssuesService_RemoveLabelForIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.RemoveLabelForIssue(context.Background(), "%", "%", 1, "%") testURLParseError(t, err) } func TestIssuesService_ReplaceLabelsForIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []string{"a", "b"} @@ -266,12 +290,15 @@ func TestIssuesService_ReplaceLabelsForIssue(t *testing.T) { } func TestIssuesService_ReplaceLabelsForIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ReplaceLabelsForIssue(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestIssuesService_RemoveLabelsForIssue(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/labels", func(w http.ResponseWriter, r *http.Request) { @@ -285,12 +312,15 @@ func TestIssuesService_RemoveLabelsForIssue(t *testing.T) { } func TestIssuesService_RemoveLabelsForIssue_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.RemoveLabelsForIssue(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestIssuesService_ListLabelsForMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/milestones/1/labels", func(w http.ResponseWriter, r *http.Request) { @@ -312,6 +342,9 @@ func TestIssuesService_ListLabelsForMilestone(t *testing.T) { } func TestIssuesService_ListLabelsForMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListLabelsForMilestone(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } diff --git a/github/issues_milestones_test.go b/github/issues_milestones_test.go index befa1b48727..019f00a8b9b 100644 --- a/github/issues_milestones_test.go +++ b/github/issues_milestones_test.go @@ -15,7 +15,7 @@ import ( ) func TestIssuesService_ListMilestones(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/milestones", func(w http.ResponseWriter, r *http.Request) { @@ -42,12 +42,15 @@ func TestIssuesService_ListMilestones(t *testing.T) { } func TestIssuesService_ListMilestones_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListMilestones(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_GetMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/milestones/1", func(w http.ResponseWriter, r *http.Request) { @@ -67,12 +70,15 @@ func TestIssuesService_GetMilestone(t *testing.T) { } func TestIssuesService_GetMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.GetMilestone(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestIssuesService_CreateMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Milestone{Title: String("t")} @@ -101,12 +107,15 @@ func TestIssuesService_CreateMilestone(t *testing.T) { } func TestIssuesService_CreateMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.CreateMilestone(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_EditMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Milestone{Title: String("t")} @@ -135,12 +144,15 @@ func TestIssuesService_EditMilestone(t *testing.T) { } func TestIssuesService_EditMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.EditMilestone(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_DeleteMilestone(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/milestones/1", func(w http.ResponseWriter, r *http.Request) { @@ -154,6 +166,9 @@ func TestIssuesService_DeleteMilestone(t *testing.T) { } func TestIssuesService_DeleteMilestone_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Issues.DeleteMilestone(context.Background(), "%", "r", 1) testURLParseError(t, err) } diff --git a/github/issues_test.go b/github/issues_test.go index da60740fb75..26937d2f43f 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -16,7 +16,7 @@ import ( ) func TestIssuesService_List_all(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/issues", func(w http.ResponseWriter, r *http.Request) { @@ -52,7 +52,7 @@ func TestIssuesService_List_all(t *testing.T) { } func TestIssuesService_List_owned(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/issues", func(w http.ResponseWriter, r *http.Request) { @@ -73,7 +73,7 @@ func TestIssuesService_List_owned(t *testing.T) { } func TestIssuesService_ListByOrg(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/issues", func(w http.ResponseWriter, r *http.Request) { @@ -94,12 +94,15 @@ func TestIssuesService_ListByOrg(t *testing.T) { } func TestIssuesService_ListByOrg_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListByOrg(context.Background(), "%", nil) testURLParseError(t, err) } func TestIssuesService_ListByRepo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues", func(w http.ResponseWriter, r *http.Request) { @@ -136,12 +139,15 @@ func TestIssuesService_ListByRepo(t *testing.T) { } func TestIssuesService_ListByRepo_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.ListByRepo(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1", func(w http.ResponseWriter, r *http.Request) { @@ -169,12 +175,15 @@ func TestIssuesService_Get(t *testing.T) { } func TestIssuesService_Get_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.Get(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestIssuesService_Create(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &IssueRequest{ @@ -208,12 +217,15 @@ func TestIssuesService_Create(t *testing.T) { } func TestIssuesService_Create_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.Create(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestIssuesService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &IssueRequest{Title: String("t")} @@ -242,12 +254,15 @@ func TestIssuesService_Edit(t *testing.T) { } func TestIssuesService_Edit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Issues.Edit(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestIssuesService_Lock(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/lock", func(w http.ResponseWriter, r *http.Request) { @@ -262,7 +277,7 @@ func TestIssuesService_Lock(t *testing.T) { } func TestIssuesService_Unlock(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/lock", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/issues_timeline_test.go b/github/issues_timeline_test.go index 2fd22109b06..7dc1e856c2c 100644 --- a/github/issues_timeline_test.go +++ b/github/issues_timeline_test.go @@ -14,7 +14,7 @@ import ( ) func TestIssuesService_ListIssueTimeline(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/timeline", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/licenses_test.go b/github/licenses_test.go index 5c06e659854..6ab917dc545 100644 --- a/github/licenses_test.go +++ b/github/licenses_test.go @@ -14,7 +14,7 @@ import ( ) func TestLicensesService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/licenses", func(w http.ResponseWriter, r *http.Request) { @@ -41,7 +41,7 @@ func TestLicensesService_List(t *testing.T) { } func TestLicensesService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/licenses/mit", func(w http.ResponseWriter, r *http.Request) { @@ -62,6 +62,9 @@ func TestLicensesService_Get(t *testing.T) { } func TestLicensesService_Get_invalidTemplate(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Licenses.Get(context.Background(), "%") testURLParseError(t, err) } diff --git a/github/migrations_source_import_test.go b/github/migrations_source_import_test.go index 67b98fb42b9..f06270f3785 100644 --- a/github/migrations_source_import_test.go +++ b/github/migrations_source_import_test.go @@ -15,7 +15,7 @@ import ( ) func TestMigrationService_StartImport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Import{ @@ -50,7 +50,7 @@ func TestMigrationService_StartImport(t *testing.T) { } func TestMigrationService_ImportProgress(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/import", func(w http.ResponseWriter, r *http.Request) { @@ -70,7 +70,7 @@ func TestMigrationService_ImportProgress(t *testing.T) { } func TestMigrationService_UpdateImport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Import{ @@ -105,7 +105,7 @@ func TestMigrationService_UpdateImport(t *testing.T) { } func TestMigrationService_CommitAuthors(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/import/authors", func(w http.ResponseWriter, r *http.Request) { @@ -128,7 +128,7 @@ func TestMigrationService_CommitAuthors(t *testing.T) { } func TestMigrationService_MapCommitAuthor(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &SourceImportAuthor{Name: String("n"), Email: String("e")} @@ -157,7 +157,7 @@ func TestMigrationService_MapCommitAuthor(t *testing.T) { } func TestMigrationService_SetLFSPreference(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Import{UseLFS: String("opt_in")} @@ -187,7 +187,7 @@ func TestMigrationService_SetLFSPreference(t *testing.T) { } func TestMigrationService_LargeFiles(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/import/large_files", func(w http.ResponseWriter, r *http.Request) { @@ -210,7 +210,7 @@ func TestMigrationService_LargeFiles(t *testing.T) { } func TestMigrationService_CancelImport(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/import", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/migrations_test.go b/github/migrations_test.go index 7e0ac0f7506..8f0cd2760bd 100644 --- a/github/migrations_test.go +++ b/github/migrations_test.go @@ -15,7 +15,7 @@ import ( ) func TestMigrationService_StartMigration(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations", func(w http.ResponseWriter, r *http.Request) { @@ -40,7 +40,7 @@ func TestMigrationService_StartMigration(t *testing.T) { } func TestMigrationService_ListMigrations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations", func(w http.ResponseWriter, r *http.Request) { @@ -61,7 +61,7 @@ func TestMigrationService_ListMigrations(t *testing.T) { } func TestMigrationService_MigrationStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations/1", func(w http.ResponseWriter, r *http.Request) { @@ -82,7 +82,7 @@ func TestMigrationService_MigrationStatus(t *testing.T) { } func TestMigrationService_MigrationArchiveURL(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations/1/archive", func(w http.ResponseWriter, r *http.Request) { @@ -108,7 +108,7 @@ func TestMigrationService_MigrationArchiveURL(t *testing.T) { } func TestMigrationService_DeleteMigration(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations/1/archive", func(w http.ResponseWriter, r *http.Request) { @@ -124,7 +124,7 @@ func TestMigrationService_DeleteMigration(t *testing.T) { } func TestMigrationService_UnlockRepo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/migrations/1/repos/r/lock", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/misc_test.go b/github/misc_test.go index f2b2df44b5e..924e7b4666e 100644 --- a/github/misc_test.go +++ b/github/misc_test.go @@ -15,7 +15,7 @@ import ( ) func TestMarkdown(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &markdownRequest{ @@ -48,7 +48,7 @@ func TestMarkdown(t *testing.T) { } func TestListEmojis(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/emojis", func(w http.ResponseWriter, r *http.Request) { @@ -68,7 +68,7 @@ func TestListEmojis(t *testing.T) { } func TestListCodesOfConduct(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/codes_of_conduct", func(w http.ResponseWriter, r *http.Request) { @@ -98,7 +98,7 @@ func TestListCodesOfConduct(t *testing.T) { } func TestGetCodeOfConduct(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/codes_of_conduct/k", func(w http.ResponseWriter, r *http.Request) { @@ -129,7 +129,7 @@ func TestGetCodeOfConduct(t *testing.T) { } func TestAPIMeta(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/meta", func(w http.ResponseWriter, r *http.Request) { @@ -154,7 +154,7 @@ func TestAPIMeta(t *testing.T) { } func TestOctocat(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := "input" @@ -178,7 +178,7 @@ func TestOctocat(t *testing.T) { } func TestZen(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() output := "sample text" @@ -200,7 +200,7 @@ func TestZen(t *testing.T) { } func TestListServiceHooks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/hooks", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/orgs_hooks_test.go b/github/orgs_hooks_test.go index 69e75f9f4ac..465aabbce24 100644 --- a/github/orgs_hooks_test.go +++ b/github/orgs_hooks_test.go @@ -15,7 +15,7 @@ import ( ) func TestOrganizationsService_ListHooks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/hooks", func(w http.ResponseWriter, r *http.Request) { @@ -38,12 +38,15 @@ func TestOrganizationsService_ListHooks(t *testing.T) { } func TestOrganizationsService_ListHooks_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.ListHooks(context.Background(), "%", nil) testURLParseError(t, err) } func TestOrganizationsService_GetHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/hooks/1", func(w http.ResponseWriter, r *http.Request) { @@ -63,12 +66,15 @@ func TestOrganizationsService_GetHook(t *testing.T) { } func TestOrganizationsService_GetHook_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.GetHook(context.Background(), "%", 1) testURLParseError(t, err) } func TestOrganizationsService_EditHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Hook{Name: String("t")} @@ -97,12 +103,15 @@ func TestOrganizationsService_EditHook(t *testing.T) { } func TestOrganizationsService_EditHook_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.EditHook(context.Background(), "%", 1, nil) testURLParseError(t, err) } func TestOrganizationsService_PingHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/hooks/1/pings", func(w http.ResponseWriter, r *http.Request) { @@ -116,7 +125,7 @@ func TestOrganizationsService_PingHook(t *testing.T) { } func TestOrganizationsService_DeleteHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/hooks/1", func(w http.ResponseWriter, r *http.Request) { @@ -130,6 +139,9 @@ func TestOrganizationsService_DeleteHook(t *testing.T) { } func TestOrganizationsService_DeleteHook_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Organizations.DeleteHook(context.Background(), "%", 1) testURLParseError(t, err) } diff --git a/github/orgs_members_test.go b/github/orgs_members_test.go index 21fbeeaf38f..8ca5e3bd7a1 100644 --- a/github/orgs_members_test.go +++ b/github/orgs_members_test.go @@ -16,7 +16,7 @@ import ( ) func TestOrganizationsService_ListMembers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members", func(w http.ResponseWriter, r *http.Request) { @@ -47,12 +47,15 @@ func TestOrganizationsService_ListMembers(t *testing.T) { } func TestOrganizationsService_ListMembers_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.ListMembers(context.Background(), "%", nil) testURLParseError(t, err) } func TestOrganizationsService_ListMembers_public(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members", func(w http.ResponseWriter, r *http.Request) { @@ -73,7 +76,7 @@ func TestOrganizationsService_ListMembers_public(t *testing.T) { } func TestOrganizationsService_IsMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -92,7 +95,7 @@ func TestOrganizationsService_IsMember(t *testing.T) { // ensure that a 404 response is interpreted as "false" and not an error func TestOrganizationsService_IsMember_notMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -112,7 +115,7 @@ func TestOrganizationsService_IsMember_notMember(t *testing.T) { // ensure that a 400 response is interpreted as an actual error, and not simply // as "false" like the above case of a 404 func TestOrganizationsService_IsMember_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -130,12 +133,15 @@ func TestOrganizationsService_IsMember_error(t *testing.T) { } func TestOrganizationsService_IsMember_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.IsMember(context.Background(), "%", "u") testURLParseError(t, err) } func TestOrganizationsService_IsPublicMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { @@ -154,7 +160,7 @@ func TestOrganizationsService_IsPublicMember(t *testing.T) { // ensure that a 404 response is interpreted as "false" and not an error func TestOrganizationsService_IsPublicMember_notMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { @@ -174,7 +180,7 @@ func TestOrganizationsService_IsPublicMember_notMember(t *testing.T) { // ensure that a 400 response is interpreted as an actual error, and not simply // as "false" like the above case of a 404 func TestOrganizationsService_IsPublicMember_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { @@ -192,12 +198,15 @@ func TestOrganizationsService_IsPublicMember_error(t *testing.T) { } func TestOrganizationsService_IsPublicMember_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.IsPublicMember(context.Background(), "%", "u") testURLParseError(t, err) } func TestOrganizationsService_RemoveMember(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -211,12 +220,15 @@ func TestOrganizationsService_RemoveMember(t *testing.T) { } func TestOrganizationsService_RemoveMember_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Organizations.RemoveMember(context.Background(), "%", "u") testURLParseError(t, err) } func TestOrganizationsService_ListOrgMemberships(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/memberships/orgs", func(w http.ResponseWriter, r *http.Request) { @@ -244,7 +256,7 @@ func TestOrganizationsService_ListOrgMemberships(t *testing.T) { } func TestOrganizationsService_GetOrgMembership_AuthenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/memberships/orgs/o", func(w http.ResponseWriter, r *http.Request) { @@ -264,7 +276,7 @@ func TestOrganizationsService_GetOrgMembership_AuthenticatedUser(t *testing.T) { } func TestOrganizationsService_GetOrgMembership_SpecifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/memberships/u", func(w http.ResponseWriter, r *http.Request) { @@ -284,7 +296,7 @@ func TestOrganizationsService_GetOrgMembership_SpecifiedUser(t *testing.T) { } func TestOrganizationsService_EditOrgMembership_AuthenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Membership{State: String("active")} @@ -313,7 +325,7 @@ func TestOrganizationsService_EditOrgMembership_AuthenticatedUser(t *testing.T) } func TestOrganizationsService_EditOrgMembership_SpecifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Membership{State: String("active")} @@ -342,7 +354,7 @@ func TestOrganizationsService_EditOrgMembership_SpecifiedUser(t *testing.T) { } func TestOrganizationsService_RemoveOrgMembership(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/memberships/u", func(w http.ResponseWriter, r *http.Request) { @@ -357,7 +369,7 @@ func TestOrganizationsService_RemoveOrgMembership(t *testing.T) { } func TestOrganizationsService_ListPendingOrgInvitations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/invitations", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/orgs_outside_collaborators_test.go b/github/orgs_outside_collaborators_test.go index 536006119b0..816db7156f7 100644 --- a/github/orgs_outside_collaborators_test.go +++ b/github/orgs_outside_collaborators_test.go @@ -14,7 +14,7 @@ import ( ) func TestOrganizationsService_ListOutsideCollaborators(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/outside_collaborators", func(w http.ResponseWriter, r *http.Request) { @@ -42,6 +42,9 @@ func TestOrganizationsService_ListOutsideCollaborators(t *testing.T) { } func TestOrganizationsService_ListOutsideCollaborators_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.ListOutsideCollaborators(context.Background(), "%", nil) testURLParseError(t, err) } diff --git a/github/orgs_projects_test.go b/github/orgs_projects_test.go index 533f691968d..b829a9cf385 100644 --- a/github/orgs_projects_test.go +++ b/github/orgs_projects_test.go @@ -15,7 +15,7 @@ import ( ) func TestOrganizationsService_ListProjects(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/projects", func(w http.ResponseWriter, r *http.Request) { @@ -38,7 +38,7 @@ func TestOrganizationsService_ListProjects(t *testing.T) { } func TestOrganizationsService_CreateProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectOptions{Name: "Project Name", Body: "Project body."} diff --git a/github/orgs_teams_test.go b/github/orgs_teams_test.go index 04669866a18..7e0832e74ee 100644 --- a/github/orgs_teams_test.go +++ b/github/orgs_teams_test.go @@ -17,7 +17,7 @@ import ( ) func TestOrganizationsService_ListTeams(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) { @@ -40,12 +40,15 @@ func TestOrganizationsService_ListTeams(t *testing.T) { } func TestOrganizationsService_ListTeams_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.ListTeams(context.Background(), "%", nil) testURLParseError(t, err) } func TestOrganizationsService_GetTeam(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { @@ -66,7 +69,7 @@ func TestOrganizationsService_GetTeam(t *testing.T) { } func TestOrganizationService_GetTeam_nestedTeams(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { @@ -90,7 +93,7 @@ func TestOrganizationService_GetTeam_nestedTeams(t *testing.T) { } func TestOrganizationsService_CreateTeam(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &NewTeam{Name: "n", Privacy: String("closed"), RepoNames: []string{"r"}} @@ -120,12 +123,15 @@ func TestOrganizationsService_CreateTeam(t *testing.T) { } func TestOrganizationsService_CreateTeam_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.CreateTeam(context.Background(), "%", nil) testURLParseError(t, err) } func TestOrganizationsService_EditTeam(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &NewTeam{Name: "n", Privacy: String("closed")} @@ -155,7 +161,7 @@ func TestOrganizationsService_EditTeam(t *testing.T) { } func TestOrganizationsService_DeleteTeam(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1", func(w http.ResponseWriter, r *http.Request) { @@ -170,7 +176,7 @@ func TestOrganizationsService_DeleteTeam(t *testing.T) { } func TestOrganizationsService_ListChildTeams(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/teams", func(w http.ResponseWriter, r *http.Request) { @@ -193,7 +199,7 @@ func TestOrganizationsService_ListChildTeams(t *testing.T) { } func TestOrganizationsService_ListTeamMembers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/members", func(w http.ResponseWriter, r *http.Request) { @@ -216,7 +222,7 @@ func TestOrganizationsService_ListTeamMembers(t *testing.T) { } func TestOrganizationsService_IsTeamMember_true(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -234,7 +240,7 @@ func TestOrganizationsService_IsTeamMember_true(t *testing.T) { // ensure that a 404 response is interpreted as "false" and not an error func TestOrganizationsService_IsTeamMember_false(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -254,7 +260,7 @@ func TestOrganizationsService_IsTeamMember_false(t *testing.T) { // ensure that a 400 response is interpreted as an actual error, and not simply // as "false" like the above case of a 404 func TestOrganizationsService_IsTeamMember_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { @@ -272,12 +278,15 @@ func TestOrganizationsService_IsTeamMember_error(t *testing.T) { } func TestOrganizationsService_IsTeamMember_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "%") testURLParseError(t, err) } func TestOrganizationsService_PublicizeMembership(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { @@ -292,12 +301,15 @@ func TestOrganizationsService_PublicizeMembership(t *testing.T) { } func TestOrganizationsService_PublicizeMembership_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Organizations.PublicizeMembership(context.Background(), "%", "u") testURLParseError(t, err) } func TestOrganizationsService_ConcealMembership(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/public_members/u", func(w http.ResponseWriter, r *http.Request) { @@ -312,12 +324,15 @@ func TestOrganizationsService_ConcealMembership(t *testing.T) { } func TestOrganizationsService_ConcealMembership_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Organizations.ConcealMembership(context.Background(), "%", "u") testURLParseError(t, err) } func TestOrganizationsService_ListTeamRepos(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/repos", func(w http.ResponseWriter, r *http.Request) { @@ -341,7 +356,7 @@ func TestOrganizationsService_ListTeamRepos(t *testing.T) { } func TestOrganizationsService_IsTeamRepo_true(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -363,7 +378,7 @@ func TestOrganizationsService_IsTeamRepo_true(t *testing.T) { } func TestOrganizationsService_IsTeamRepo_false(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -384,7 +399,7 @@ func TestOrganizationsService_IsTeamRepo_false(t *testing.T) { } func TestOrganizationsService_IsTeamRepo_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -405,12 +420,15 @@ func TestOrganizationsService_IsTeamRepo_error(t *testing.T) { } func TestOrganizationsService_IsTeamRepo_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.IsTeamRepo(context.Background(), 1, "%", "r") testURLParseError(t, err) } func TestOrganizationsService_AddTeamRepo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() opt := &OrganizationAddTeamRepoOptions{Permission: "admin"} @@ -434,7 +452,7 @@ func TestOrganizationsService_AddTeamRepo(t *testing.T) { } func TestOrganizationsService_AddTeamRepo_noAccess(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -449,12 +467,15 @@ func TestOrganizationsService_AddTeamRepo_noAccess(t *testing.T) { } func TestOrganizationsService_AddTeamRepo_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Organizations.AddTeamRepo(context.Background(), 1, "%", "r", nil) testURLParseError(t, err) } func TestOrganizationsService_RemoveTeamRepo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/repos/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -469,12 +490,15 @@ func TestOrganizationsService_RemoveTeamRepo(t *testing.T) { } func TestOrganizationsService_RemoveTeamRepo_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Organizations.RemoveTeamRepo(context.Background(), 1, "%", "r") testURLParseError(t, err) } func TestOrganizationsService_GetTeamMembership(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { @@ -495,7 +519,7 @@ func TestOrganizationsService_GetTeamMembership(t *testing.T) { } func TestOrganizationsService_AddTeamMembership(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() opt := &OrganizationAddTeamMembershipOptions{Role: "maintainer"} @@ -524,7 +548,7 @@ func TestOrganizationsService_AddTeamMembership(t *testing.T) { } func TestOrganizationsService_RemoveTeamMembership(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { @@ -539,7 +563,7 @@ func TestOrganizationsService_RemoveTeamMembership(t *testing.T) { } func TestOrganizationsService_ListUserTeams(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/teams", func(w http.ResponseWriter, r *http.Request) { @@ -562,7 +586,7 @@ func TestOrganizationsService_ListUserTeams(t *testing.T) { } func TestOrganizationsService_ListPendingTeamInvitations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/teams/1/invitations", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/orgs_test.go b/github/orgs_test.go index 6e227e8e555..90b356ed379 100644 --- a/github/orgs_test.go +++ b/github/orgs_test.go @@ -15,7 +15,7 @@ import ( ) func TestOrganizationsService_ListAll(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() since := 1342004 @@ -38,7 +38,7 @@ func TestOrganizationsService_ListAll(t *testing.T) { } func TestOrganizationsService_List_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/orgs", func(w http.ResponseWriter, r *http.Request) { @@ -58,7 +58,7 @@ func TestOrganizationsService_List_authenticatedUser(t *testing.T) { } func TestOrganizationsService_List_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/orgs", func(w http.ResponseWriter, r *http.Request) { @@ -80,12 +80,15 @@ func TestOrganizationsService_List_specifiedUser(t *testing.T) { } func TestOrganizationsService_List_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.List(context.Background(), "%", nil) testURLParseError(t, err) } func TestOrganizationsService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o", func(w http.ResponseWriter, r *http.Request) { @@ -105,12 +108,15 @@ func TestOrganizationsService_Get(t *testing.T) { } func TestOrganizationsService_Get_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.Get(context.Background(), "%") testURLParseError(t, err) } func TestOrganizationsService_GetByID(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/organizations/1", func(w http.ResponseWriter, r *http.Request) { @@ -130,7 +136,7 @@ func TestOrganizationsService_GetByID(t *testing.T) { } func TestOrganizationsService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Organization{Login: String("l")} @@ -159,6 +165,9 @@ func TestOrganizationsService_Edit(t *testing.T) { } func TestOrganizationsService_Edit_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Organizations.Edit(context.Background(), "%", nil) testURLParseError(t, err) } diff --git a/github/orgs_users_blocking_test.go b/github/orgs_users_blocking_test.go index 53be507ef21..5d38cc44ea8 100644 --- a/github/orgs_users_blocking_test.go +++ b/github/orgs_users_blocking_test.go @@ -14,7 +14,7 @@ import ( ) func TestOrganizationsService_ListBlockedUsers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/blocks", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestOrganizationsService_ListBlockedUsers(t *testing.T) { } func TestOrganizationsService_IsBlocked(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/blocks/u", func(w http.ResponseWriter, r *http.Request) { @@ -58,7 +58,7 @@ func TestOrganizationsService_IsBlocked(t *testing.T) { } func TestOrganizationsService_BlockUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/blocks/u", func(w http.ResponseWriter, r *http.Request) { @@ -74,7 +74,7 @@ func TestOrganizationsService_BlockUser(t *testing.T) { } func TestOrganizationsService_UnblockUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/orgs/o/blocks/u", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/projects_test.go b/github/projects_test.go index bf287e0263b..6e28f864c98 100644 --- a/github/projects_test.go +++ b/github/projects_test.go @@ -15,7 +15,7 @@ import ( ) func TestProjectsService_UpdateProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectOptions{Name: "Project Name", Body: "Project body.", State: "open"} @@ -45,7 +45,7 @@ func TestProjectsService_UpdateProject(t *testing.T) { } func TestProjectsService_GetProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/1", func(w http.ResponseWriter, r *http.Request) { @@ -66,7 +66,7 @@ func TestProjectsService_GetProject(t *testing.T) { } func TestProjectsService_DeleteProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/1", func(w http.ResponseWriter, r *http.Request) { @@ -81,7 +81,7 @@ func TestProjectsService_DeleteProject(t *testing.T) { } func TestProjectsService_ListProjectColumns(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/1/columns", func(w http.ResponseWriter, r *http.Request) { @@ -104,7 +104,7 @@ func TestProjectsService_ListProjectColumns(t *testing.T) { } func TestProjectsService_GetProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/1", func(w http.ResponseWriter, r *http.Request) { @@ -125,7 +125,7 @@ func TestProjectsService_GetProjectColumn(t *testing.T) { } func TestProjectsService_CreateProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectColumnOptions{Name: "Column Name"} @@ -155,7 +155,7 @@ func TestProjectsService_CreateProjectColumn(t *testing.T) { } func TestProjectsService_UpdateProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectColumnOptions{Name: "Column Name"} @@ -185,7 +185,7 @@ func TestProjectsService_UpdateProjectColumn(t *testing.T) { } func TestProjectsService_DeleteProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/1", func(w http.ResponseWriter, r *http.Request) { @@ -200,7 +200,7 @@ func TestProjectsService_DeleteProjectColumn(t *testing.T) { } func TestProjectsService_MoveProjectColumn(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectColumnMoveOptions{Position: "after:12345"} @@ -223,7 +223,7 @@ func TestProjectsService_MoveProjectColumn(t *testing.T) { } func TestProjectsService_ListProjectCards(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/1/cards", func(w http.ResponseWriter, r *http.Request) { @@ -246,7 +246,7 @@ func TestProjectsService_ListProjectCards(t *testing.T) { } func TestProjectsService_GetProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/cards/1", func(w http.ResponseWriter, r *http.Request) { @@ -267,7 +267,7 @@ func TestProjectsService_GetProjectCard(t *testing.T) { } func TestProjectsService_CreateProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectCardOptions{ @@ -300,7 +300,7 @@ func TestProjectsService_CreateProjectCard(t *testing.T) { } func TestProjectsService_UpdateProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectCardOptions{ @@ -333,7 +333,7 @@ func TestProjectsService_UpdateProjectCard(t *testing.T) { } func TestProjectsService_DeleteProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/projects/columns/cards/1", func(w http.ResponseWriter, r *http.Request) { @@ -348,7 +348,7 @@ func TestProjectsService_DeleteProjectCard(t *testing.T) { } func TestProjectsService_MoveProjectCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectCardMoveOptions{Position: "after:12345"} diff --git a/github/pulls_comments_test.go b/github/pulls_comments_test.go index e35b04f7b7b..0a839aaeaba 100644 --- a/github/pulls_comments_test.go +++ b/github/pulls_comments_test.go @@ -16,7 +16,7 @@ import ( ) func TestPullRequestsService_ListComments_allPulls(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments", func(w http.ResponseWriter, r *http.Request) { @@ -49,7 +49,7 @@ func TestPullRequestsService_ListComments_allPulls(t *testing.T) { } func TestPullRequestsService_ListComments_specificPull(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -70,12 +70,15 @@ func TestPullRequestsService_ListComments_specificPull(t *testing.T) { } func TestPullRequestsService_ListComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.ListComments(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestPullRequestsService_GetComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -96,12 +99,15 @@ func TestPullRequestsService_GetComment(t *testing.T) { } func TestPullRequestsService_GetComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.GetComment(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestPullRequestsService_CreateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestComment{Body: String("b")} @@ -130,12 +136,15 @@ func TestPullRequestsService_CreateComment(t *testing.T) { } func TestPullRequestsService_CreateComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.CreateComment(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestPullRequestsService_EditComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestComment{Body: String("b")} @@ -164,12 +173,15 @@ func TestPullRequestsService_EditComment(t *testing.T) { } func TestPullRequestsService_EditComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.EditComment(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestPullRequestsService_DeleteComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -183,6 +195,9 @@ func TestPullRequestsService_DeleteComment(t *testing.T) { } func TestPullRequestsService_DeleteComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.PullRequests.DeleteComment(context.Background(), "%", "r", 1) testURLParseError(t, err) } diff --git a/github/pulls_reviewers_test.go b/github/pulls_reviewers_test.go index fddea6d0891..d76951e190c 100644 --- a/github/pulls_reviewers_test.go +++ b/github/pulls_reviewers_test.go @@ -14,7 +14,7 @@ import ( ) func TestRequestReviewers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) { @@ -36,7 +36,7 @@ func TestRequestReviewers(t *testing.T) { } func TestRemoveReviewers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) { @@ -52,7 +52,7 @@ func TestRemoveReviewers(t *testing.T) { } func TestListReviewers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) { @@ -86,7 +86,7 @@ func TestListReviewers(t *testing.T) { } func TestListReviewers_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/pulls_reviews_test.go b/github/pulls_reviews_test.go index b69d76adca9..e9dba35bd6a 100644 --- a/github/pulls_reviews_test.go +++ b/github/pulls_reviews_test.go @@ -15,7 +15,7 @@ import ( ) func TestPullRequestsService_ListReviews(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews", func(w http.ResponseWriter, r *http.Request) { @@ -42,12 +42,15 @@ func TestPullRequestsService_ListReviews(t *testing.T) { } func TestPullRequestsService_ListReviews_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.ListReviews(context.Background(), "%", "r", 1, nil) testURLParseError(t, err) } func TestPullRequestsService_GetReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) { @@ -67,12 +70,15 @@ func TestPullRequestsService_GetReview(t *testing.T) { } func TestPullRequestsService_GetReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.GetReview(context.Background(), "%", "r", 1, 1) testURLParseError(t, err) } func TestPullRequestsService_DeletePendingReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) { @@ -92,12 +98,15 @@ func TestPullRequestsService_DeletePendingReview(t *testing.T) { } func TestPullRequestsService_DeletePendingReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.DeletePendingReview(context.Background(), "%", "r", 1, 1) testURLParseError(t, err) } func TestPullRequestsService_ListReviewComments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -120,7 +129,7 @@ func TestPullRequestsService_ListReviewComments(t *testing.T) { } func TestPullRequestsService_ListReviewComments_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/comments", func(w http.ResponseWriter, r *http.Request) { @@ -138,12 +147,15 @@ func TestPullRequestsService_ListReviewComments_withOptions(t *testing.T) { } func TestPullRequestsService_ListReviewComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.ListReviewComments(context.Background(), "%", "r", 1, 1, nil) testURLParseError(t, err) } func TestPullRequestsService_CreateReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestReviewRequest{ @@ -176,12 +188,15 @@ func TestPullRequestsService_CreateReview(t *testing.T) { } func TestPullRequestsService_CreateReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.CreateReview(context.Background(), "%", "r", 1, &PullRequestReviewRequest{}) testURLParseError(t, err) } func TestPullRequestsService_SubmitReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestReviewRequest{ @@ -213,12 +228,15 @@ func TestPullRequestsService_SubmitReview(t *testing.T) { } func TestPullRequestsService_SubmitReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.SubmitReview(context.Background(), "%", "r", 1, 1, &PullRequestReviewRequest{}) testURLParseError(t, err) } func TestPullRequestsService_DismissReview(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestReviewDismissalRequest{Message: String("m")} @@ -247,6 +265,9 @@ func TestPullRequestsService_DismissReview(t *testing.T) { } func TestPullRequestsService_DismissReview_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.DismissReview(context.Background(), "%", "r", 1, 1, &PullRequestReviewDismissalRequest{}) testURLParseError(t, err) } diff --git a/github/pulls_test.go b/github/pulls_test.go index 89adf239463..fabc7110511 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -17,7 +17,7 @@ import ( ) func TestPullRequestsService_List(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) { @@ -46,12 +46,15 @@ func TestPullRequestsService_List(t *testing.T) { } func TestPullRequestsService_List_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.List(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestPullRequestsService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { @@ -71,7 +74,7 @@ func TestPullRequestsService_Get(t *testing.T) { } func TestPullRequestsService_GetRaw_diff(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() const rawStr = "@@diff content" @@ -93,7 +96,7 @@ func TestPullRequestsService_GetRaw_diff(t *testing.T) { } func TestPullRequestsService_GetRaw_patch(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() const rawStr = "@@patch content" @@ -115,7 +118,7 @@ func TestPullRequestsService_GetRaw_patch(t *testing.T) { } func TestPullRequestsService_GetRaw_invalid(t *testing.T) { - setup() + client, _, _, teardown := setup() defer teardown() _, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{100}) @@ -128,7 +131,7 @@ func TestPullRequestsService_GetRaw_invalid(t *testing.T) { } func TestPullRequestsService_Get_headAndBase(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { @@ -158,7 +161,7 @@ func TestPullRequestsService_Get_headAndBase(t *testing.T) { } func TestPullRequestsService_Get_urlFields(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { @@ -197,12 +200,15 @@ func TestPullRequestsService_Get_urlFields(t *testing.T) { } func TestPullRequestsService_Get_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.Get(context.Background(), "%", "r", 1) testURLParseError(t, err) } func TestPullRequestsService_Create(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &NewPullRequest{Title: String("t")} @@ -231,12 +237,15 @@ func TestPullRequestsService_Create(t *testing.T) { } func TestPullRequestsService_Create_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.Create(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestPullRequestsService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() tests := []struct { @@ -289,12 +298,15 @@ func TestPullRequestsService_Edit(t *testing.T) { } func TestPullRequestsService_Edit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.PullRequests.Edit(context.Background(), "%", "r", 1, &PullRequest{}) testURLParseError(t, err) } func TestPullRequestsService_ListCommits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/commits", func(w http.ResponseWriter, r *http.Request) { @@ -352,7 +364,7 @@ func TestPullRequestsService_ListCommits(t *testing.T) { } func TestPullRequestsService_ListFiles(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/files", func(w http.ResponseWriter, r *http.Request) { @@ -414,7 +426,7 @@ func TestPullRequestsService_ListFiles(t *testing.T) { } func TestPullRequestsService_IsMerged(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/merge", func(w http.ResponseWriter, r *http.Request) { @@ -434,7 +446,7 @@ func TestPullRequestsService_IsMerged(t *testing.T) { } func TestPullRequestsService_Merge(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/1/merge", func(w http.ResponseWriter, r *http.Request) { @@ -465,7 +477,7 @@ func TestPullRequestsService_Merge(t *testing.T) { // Test that different merge options produce expected PUT requests. See issue https://github.com/google/go-github/issues/500. func TestPullRequestsService_Merge_options(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() tests := []struct { diff --git a/github/reactions_test.go b/github/reactions_test.go index 2725298279e..fc3fe7e5295 100644 --- a/github/reactions_test.go +++ b/github/reactions_test.go @@ -13,7 +13,7 @@ import ( ) func TestReactionsService_ListCommentReactions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -34,7 +34,7 @@ func TestReactionsService_ListCommentReactions(t *testing.T) { } func TestReactionsService_CreateCommentReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -56,7 +56,7 @@ func TestReactionsService_CreateCommentReaction(t *testing.T) { } func TestReactionsService_ListIssueReactions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -77,7 +77,7 @@ func TestReactionsService_ListIssueReactions(t *testing.T) { } func TestReactionsService_CreateIssueReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -99,7 +99,7 @@ func TestReactionsService_CreateIssueReaction(t *testing.T) { } func TestReactionsService_ListIssueCommentReactions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -120,7 +120,7 @@ func TestReactionsService_ListIssueCommentReactions(t *testing.T) { } func TestReactionsService_CreateIssueCommentReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -142,7 +142,7 @@ func TestReactionsService_CreateIssueCommentReaction(t *testing.T) { } func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -163,7 +163,7 @@ func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) { } func TestReactionsService_CreatePullRequestCommentReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { @@ -185,7 +185,7 @@ func TestReactionsService_CreatePullRequestCommentReaction(t *testing.T) { } func TestReactionsService_DeleteReaction(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/reactions/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/repos_collaborators_test.go b/github/repos_collaborators_test.go index 4f3d47707d4..14be59c173c 100644 --- a/github/repos_collaborators_test.go +++ b/github/repos_collaborators_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListCollaborators(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators", func(w http.ResponseWriter, r *http.Request) { @@ -40,7 +40,7 @@ func TestRepositoriesService_ListCollaborators(t *testing.T) { } func TestRepositoriesService_ListCollaborators_withAffiliation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators", func(w http.ResponseWriter, r *http.Request) { @@ -65,12 +65,15 @@ func TestRepositoriesService_ListCollaborators_withAffiliation(t *testing.T) { } func TestRepositoriesService_ListCollaborators_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListCollaborators(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_IsCollaborator_True(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators/u", func(w http.ResponseWriter, r *http.Request) { @@ -89,7 +92,7 @@ func TestRepositoriesService_IsCollaborator_True(t *testing.T) { } func TestRepositoriesService_IsCollaborator_False(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators/u", func(w http.ResponseWriter, r *http.Request) { @@ -108,12 +111,15 @@ func TestRepositoriesService_IsCollaborator_False(t *testing.T) { } func TestRepositoriesService_IsCollaborator_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.IsCollaborator(context.Background(), "%", "%", "%") testURLParseError(t, err) } func TestRepositoryService_GetPermissionLevel(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators/u/permission", func(w http.ResponseWriter, r *http.Request) { @@ -139,7 +145,7 @@ func TestRepositoryService_GetPermissionLevel(t *testing.T) { } func TestRepositoriesService_AddCollaborator(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() opt := &RepositoryAddCollaboratorOptions{Permission: "admin"} @@ -164,12 +170,15 @@ func TestRepositoriesService_AddCollaborator(t *testing.T) { } func TestRepositoriesService_AddCollaborator_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.AddCollaborator(context.Background(), "%", "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_RemoveCollaborator(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/collaborators/u", func(w http.ResponseWriter, r *http.Request) { @@ -184,6 +193,9 @@ func TestRepositoriesService_RemoveCollaborator(t *testing.T) { } func TestRepositoriesService_RemoveCollaborator_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.RemoveCollaborator(context.Background(), "%", "%", "%") testURLParseError(t, err) } diff --git a/github/repos_comments_test.go b/github/repos_comments_test.go index 249a37a3677..95aa2eca44a 100644 --- a/github/repos_comments_test.go +++ b/github/repos_comments_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListComments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments", func(w http.ResponseWriter, r *http.Request) { @@ -38,12 +38,15 @@ func TestRepositoriesService_ListComments(t *testing.T) { } func TestRepositoriesService_ListComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListComments(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_ListCommitComments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/commits/s/comments", func(w http.ResponseWriter, r *http.Request) { @@ -66,12 +69,15 @@ func TestRepositoriesService_ListCommitComments(t *testing.T) { } func TestRepositoriesService_ListCommitComments_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListCommitComments(context.Background(), "%", "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_CreateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepositoryComment{Body: String("b")} @@ -100,12 +106,15 @@ func TestRepositoriesService_CreateComment(t *testing.T) { } func TestRepositoriesService_CreateComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateComment(context.Background(), "%", "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_GetComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -126,12 +135,15 @@ func TestRepositoriesService_GetComment(t *testing.T) { } func TestRepositoriesService_GetComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.GetComment(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestRepositoriesService_UpdateComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepositoryComment{Body: String("b")} @@ -160,12 +172,15 @@ func TestRepositoriesService_UpdateComment(t *testing.T) { } func TestRepositoriesService_UpdateComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.UpdateComment(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestRepositoriesService_DeleteComment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/comments/1", func(w http.ResponseWriter, r *http.Request) { @@ -179,6 +194,9 @@ func TestRepositoriesService_DeleteComment(t *testing.T) { } func TestRepositoriesService_DeleteComment_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.DeleteComment(context.Background(), "%", "%", 1) testURLParseError(t, err) } diff --git a/github/repos_commits_test.go b/github/repos_commits_test.go index 1d5f5ec936a..3f7039da2de 100644 --- a/github/repos_commits_test.go +++ b/github/repos_commits_test.go @@ -16,7 +16,7 @@ import ( ) func TestRepositoriesService_ListCommits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() // given @@ -53,7 +53,7 @@ func TestRepositoriesService_ListCommits(t *testing.T) { } func TestRepositoriesService_GetCommit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/commits/s", func(w http.ResponseWriter, r *http.Request) { @@ -128,7 +128,7 @@ func TestRepositoriesService_GetCommit(t *testing.T) { } func TestRepositoriesService_GetCommitRaw_diff(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() const rawStr = "@@diff content" @@ -150,7 +150,7 @@ func TestRepositoriesService_GetCommitRaw_diff(t *testing.T) { } func TestRepositoriesService_GetCommitRaw_patch(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() const rawStr = "@@patch content" @@ -172,7 +172,7 @@ func TestRepositoriesService_GetCommitRaw_patch(t *testing.T) { } func TestRepositoriesService_GetCommitRaw_invalid(t *testing.T) { - setup() + client, _, _, teardown := setup() defer teardown() _, _, err := client.Repositories.GetCommitRaw(context.Background(), "o", "r", "s", RawOptions{100}) @@ -185,7 +185,7 @@ func TestRepositoriesService_GetCommitRaw_invalid(t *testing.T) { } func TestRepositoriesService_GetCommitSHA1(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() const sha1 = "01234abcde" @@ -226,7 +226,7 @@ func TestRepositoriesService_GetCommitSHA1(t *testing.T) { } func TestRepositoriesService_CompareCommits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/compare/b...h", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/repos_community_health_test.go b/github/repos_community_health_test.go index a90c8c03802..c9499aa1fc6 100644 --- a/github/repos_community_health_test.go +++ b/github/repos_community_health_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_GetCommunityHealthMetrics(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/community/profile", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go index 770098e8c31..0a08e8c70f3 100644 --- a/github/repos_contents_test.go +++ b/github/repos_contents_test.go @@ -68,7 +68,7 @@ func TestRepositoryContent_GetContent(t *testing.T) { } func TestRepositoriesService_GetReadme(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/readme", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -91,14 +91,14 @@ func TestRepositoriesService_GetReadme(t *testing.T) { } func TestRepositoriesService_DownloadContents_Success(t *testing.T) { - setup() + client, mux, serverURL, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `[{ "type": "file", "name": "f", - "download_url": "`+server.URL+baseURLPath+`/download/f" + "download_url": "`+serverURL+baseURLPath+`/download/f" }]`) }) mux.HandleFunc("/download/f", func(w http.ResponseWriter, r *http.Request) { @@ -123,7 +123,7 @@ func TestRepositoriesService_DownloadContents_Success(t *testing.T) { } func TestRepositoriesService_DownloadContents_NoDownloadURL(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -140,7 +140,7 @@ func TestRepositoriesService_DownloadContents_NoDownloadURL(t *testing.T) { } func TestRepositoriesService_DownloadContents_NoFile(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -154,7 +154,7 @@ func TestRepositoriesService_DownloadContents_NoFile(t *testing.T) { } func TestRepositoriesService_GetContents_File(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -177,7 +177,7 @@ func TestRepositoriesService_GetContents_File(t *testing.T) { } func TestRepositoriesService_GetContents_FilenameNeedsEscape(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p#?%/δΈ­.go", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -190,7 +190,7 @@ func TestRepositoriesService_GetContents_FilenameNeedsEscape(t *testing.T) { } func TestRepositoriesService_GetContents_DirectoryWithSpaces(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/some directory/file.go", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -203,7 +203,7 @@ func TestRepositoriesService_GetContents_DirectoryWithSpaces(t *testing.T) { } func TestRepositoriesService_GetContents_DirectoryWithPlusChars(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/some directory+name/file.go", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -216,7 +216,7 @@ func TestRepositoriesService_GetContents_DirectoryWithPlusChars(t *testing.T) { } func TestRepositoriesService_GetContents_Directory(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") @@ -244,7 +244,7 @@ func TestRepositoriesService_GetContents_Directory(t *testing.T) { } func TestRepositoriesService_CreateFile(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") @@ -282,7 +282,7 @@ func TestRepositoriesService_CreateFile(t *testing.T) { } func TestRepositoriesService_UpdateFile(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") @@ -322,7 +322,7 @@ func TestRepositoriesService_UpdateFile(t *testing.T) { } func TestRepositoriesService_DeleteFile(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") @@ -358,7 +358,7 @@ func TestRepositoriesService_DeleteFile(t *testing.T) { } func TestRepositoriesService_GetArchiveLink(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/tarball", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") diff --git a/github/repos_deployments_test.go b/github/repos_deployments_test.go index 9fa44b2ba4c..d9d4080f628 100644 --- a/github/repos_deployments_test.go +++ b/github/repos_deployments_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListDeployments(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/deployments", func(w http.ResponseWriter, r *http.Request) { @@ -37,7 +37,7 @@ func TestRepositoriesService_ListDeployments(t *testing.T) { } func TestRepositoriesService_GetDeployment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/deployments/3", func(w http.ResponseWriter, r *http.Request) { @@ -58,7 +58,7 @@ func TestRepositoriesService_GetDeployment(t *testing.T) { } func TestRepositoriesService_CreateDeployment(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &DeploymentRequest{Ref: String("1111"), Task: String("deploy"), TransientEnvironment: Bool(true)} @@ -88,7 +88,7 @@ func TestRepositoriesService_CreateDeployment(t *testing.T) { } func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/deployments/1/statuses", func(w http.ResponseWriter, r *http.Request) { @@ -110,7 +110,7 @@ func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) { } func TestRepositoriesService_GetDeploymentStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/deployments/3/statuses/4", func(w http.ResponseWriter, r *http.Request) { @@ -131,7 +131,7 @@ func TestRepositoriesService_GetDeploymentStatus(t *testing.T) { } func TestRepositoriesService_CreateDeploymentStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &DeploymentStatusRequest{State: String("inactive"), Description: String("deploy"), AutoInactive: Bool(false)} diff --git a/github/repos_forks_test.go b/github/repos_forks_test.go index f9cf1e3a325..e9d9a108b21 100644 --- a/github/repos_forks_test.go +++ b/github/repos_forks_test.go @@ -14,7 +14,7 @@ import ( ) func TestRepositoriesService_ListForks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) { @@ -43,12 +43,15 @@ func TestRepositoriesService_ListForks(t *testing.T) { } func TestRepositoriesService_ListForks_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListForks(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestRepositoriesService_CreateFork(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) { @@ -70,6 +73,9 @@ func TestRepositoriesService_CreateFork(t *testing.T) { } func TestRepositoriesService_CreateFork_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateFork(context.Background(), "%", "r", nil) testURLParseError(t, err) } diff --git a/github/repos_hooks_test.go b/github/repos_hooks_test.go index 364f4583f08..e8e3e1681c9 100644 --- a/github/repos_hooks_test.go +++ b/github/repos_hooks_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_CreateHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Hook{Name: String("t")} @@ -44,12 +44,15 @@ func TestRepositoriesService_CreateHook(t *testing.T) { } func TestRepositoriesService_CreateHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateHook(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_ListHooks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks", func(w http.ResponseWriter, r *http.Request) { @@ -72,12 +75,15 @@ func TestRepositoriesService_ListHooks(t *testing.T) { } func TestRepositoriesService_ListHooks_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListHooks(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_GetHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) { @@ -97,12 +103,15 @@ func TestRepositoriesService_GetHook(t *testing.T) { } func TestRepositoriesService_GetHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.GetHook(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestRepositoriesService_EditHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Hook{Name: String("t")} @@ -131,12 +140,15 @@ func TestRepositoriesService_EditHook(t *testing.T) { } func TestRepositoriesService_EditHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.EditHook(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestRepositoriesService_DeleteHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) { @@ -150,12 +162,15 @@ func TestRepositoriesService_DeleteHook(t *testing.T) { } func TestRepositoriesService_DeleteHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.DeleteHook(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestRepositoriesService_PingHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks/1/pings", func(w http.ResponseWriter, r *http.Request) { @@ -169,7 +184,7 @@ func TestRepositoriesService_PingHook(t *testing.T) { } func TestRepositoriesService_TestHook(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/hooks/1/tests", func(w http.ResponseWriter, r *http.Request) { @@ -183,6 +198,9 @@ func TestRepositoriesService_TestHook(t *testing.T) { } func TestRepositoriesService_TestHook_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.TestHook(context.Background(), "%", "%", 1) testURLParseError(t, err) } diff --git a/github/repos_invitations_test.go b/github/repos_invitations_test.go index 01ac66657fc..729601f77a5 100644 --- a/github/repos_invitations_test.go +++ b/github/repos_invitations_test.go @@ -14,7 +14,7 @@ import ( ) func TestRepositoriesService_ListInvitations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/invitations", func(w http.ResponseWriter, r *http.Request) { @@ -37,7 +37,7 @@ func TestRepositoriesService_ListInvitations(t *testing.T) { } func TestRepositoriesService_DeleteInvitation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) { @@ -53,7 +53,7 @@ func TestRepositoriesService_DeleteInvitation(t *testing.T) { } func TestRepositoriesService_UpdateInvitation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/repos_keys_test.go b/github/repos_keys_test.go index 2ef04fdcb62..33cc1970f15 100644 --- a/github/repos_keys_test.go +++ b/github/repos_keys_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListKeys(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/keys", func(w http.ResponseWriter, r *http.Request) { @@ -37,12 +37,15 @@ func TestRepositoriesService_ListKeys(t *testing.T) { } func TestRepositoriesService_ListKeys_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListKeys(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_GetKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/keys/1", func(w http.ResponseWriter, r *http.Request) { @@ -62,12 +65,15 @@ func TestRepositoriesService_GetKey(t *testing.T) { } func TestRepositoriesService_GetKey_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.GetKey(context.Background(), "%", "%", 1) testURLParseError(t, err) } func TestRepositoriesService_CreateKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Key{Key: String("k"), Title: String("t")} @@ -96,12 +102,15 @@ func TestRepositoriesService_CreateKey(t *testing.T) { } func TestRepositoriesService_CreateKey_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateKey(context.Background(), "%", "%", nil) testURLParseError(t, err) } func TestRepositoriesService_EditKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Key{Key: String("k"), Title: String("t")} @@ -130,12 +139,15 @@ func TestRepositoriesService_EditKey(t *testing.T) { } func TestRepositoriesService_EditKey_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.EditKey(context.Background(), "%", "%", 1, nil) testURLParseError(t, err) } func TestRepositoriesService_DeleteKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/keys/1", func(w http.ResponseWriter, r *http.Request) { @@ -149,6 +161,9 @@ func TestRepositoriesService_DeleteKey(t *testing.T) { } func TestRepositoriesService_DeleteKey_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Repositories.DeleteKey(context.Background(), "%", "%", 1) testURLParseError(t, err) } diff --git a/github/repos_merging_test.go b/github/repos_merging_test.go index e2e264fd660..086f24bbc3e 100644 --- a/github/repos_merging_test.go +++ b/github/repos_merging_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_Merge(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepositoryMergeRequest{ diff --git a/github/repos_pages_test.go b/github/repos_pages_test.go index c9e19a1f5a1..21a00f9dd78 100644 --- a/github/repos_pages_test.go +++ b/github/repos_pages_test.go @@ -14,7 +14,7 @@ import ( ) func TestRepositoriesService_GetPagesInfo(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages", func(w http.ResponseWriter, r *http.Request) { @@ -35,7 +35,7 @@ func TestRepositoriesService_GetPagesInfo(t *testing.T) { } func TestRepositoriesService_ListPagesBuilds(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { @@ -55,7 +55,7 @@ func TestRepositoriesService_ListPagesBuilds(t *testing.T) { } func TestRepositoriesService_ListPagesBuilds_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { @@ -73,7 +73,7 @@ func TestRepositoriesService_ListPagesBuilds_withOptions(t *testing.T) { } func TestRepositoriesService_GetLatestPagesBuild(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds/latest", func(w http.ResponseWriter, r *http.Request) { @@ -93,7 +93,7 @@ func TestRepositoriesService_GetLatestPagesBuild(t *testing.T) { } func TestRepositoriesService_GetPageBuild(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds/1", func(w http.ResponseWriter, r *http.Request) { @@ -113,7 +113,7 @@ func TestRepositoriesService_GetPageBuild(t *testing.T) { } func TestRepositoriesService_RequestPageBuild(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/repos_projects_test.go b/github/repos_projects_test.go index 57dbdd1b3fe..fe02f378837 100644 --- a/github/repos_projects_test.go +++ b/github/repos_projects_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListProjects(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/projects", func(w http.ResponseWriter, r *http.Request) { @@ -38,7 +38,7 @@ func TestRepositoriesService_ListProjects(t *testing.T) { } func TestRepositoriesService_CreateProject(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProjectOptions{Name: "Project Name", Body: "Project body."} diff --git a/github/repos_releases_test.go b/github/repos_releases_test.go index 9a2c4c8afff..b7420e8a108 100644 --- a/github/repos_releases_test.go +++ b/github/repos_releases_test.go @@ -19,7 +19,7 @@ import ( ) func TestRepositoriesService_ListReleases(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) { @@ -40,7 +40,7 @@ func TestRepositoriesService_ListReleases(t *testing.T) { } func TestRepositoriesService_GetRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/1", func(w http.ResponseWriter, r *http.Request) { @@ -60,7 +60,7 @@ func TestRepositoriesService_GetRelease(t *testing.T) { } func TestRepositoriesService_GetLatestRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/latest", func(w http.ResponseWriter, r *http.Request) { @@ -80,7 +80,7 @@ func TestRepositoriesService_GetLatestRelease(t *testing.T) { } func TestRepositoriesService_GetReleaseByTag(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/tags/foo", func(w http.ResponseWriter, r *http.Request) { @@ -100,7 +100,7 @@ func TestRepositoriesService_GetReleaseByTag(t *testing.T) { } func TestRepositoriesService_CreateRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepositoryRelease{Name: String("v1.0")} @@ -128,7 +128,7 @@ func TestRepositoriesService_CreateRelease(t *testing.T) { } func TestRepositoriesService_EditRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepositoryRelease{Name: String("n")} @@ -155,7 +155,7 @@ func TestRepositoriesService_EditRelease(t *testing.T) { } func TestRepositoriesService_DeleteRelease(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/1", func(w http.ResponseWriter, r *http.Request) { @@ -169,7 +169,7 @@ func TestRepositoriesService_DeleteRelease(t *testing.T) { } func TestRepositoriesService_ListReleaseAssets(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/1/assets", func(w http.ResponseWriter, r *http.Request) { @@ -190,7 +190,7 @@ func TestRepositoriesService_ListReleaseAssets(t *testing.T) { } func TestRepositoriesService_GetReleaseAsset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -209,7 +209,7 @@ func TestRepositoriesService_GetReleaseAsset(t *testing.T) { } func TestRepositoriesService_DownloadReleaseAsset_Stream(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -235,7 +235,7 @@ func TestRepositoriesService_DownloadReleaseAsset_Stream(t *testing.T) { } func TestRepositoriesService_DownloadReleaseAsset_Redirect(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -255,7 +255,7 @@ func TestRepositoriesService_DownloadReleaseAsset_Redirect(t *testing.T) { } func TestRepositoriesService_DownloadReleaseAsset_APIError(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -281,7 +281,7 @@ func TestRepositoriesService_DownloadReleaseAsset_APIError(t *testing.T) { } func TestRepositoriesService_EditReleaseAsset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ReleaseAsset{Name: String("n")} @@ -308,7 +308,7 @@ func TestRepositoriesService_EditReleaseAsset(t *testing.T) { } func TestRepositoriesService_DeleteReleaseAsset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) { @@ -322,7 +322,7 @@ func TestRepositoriesService_DeleteReleaseAsset(t *testing.T) { } func TestRepositoriesService_UploadReleaseAsset(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/releases/1/assets", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/repos_stats_test.go b/github/repos_stats_test.go index 1da94d01338..db136bcbd8f 100644 --- a/github/repos_stats_test.go +++ b/github/repos_stats_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListContributorsStats(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/contributors", func(w http.ResponseWriter, r *http.Request) { @@ -69,7 +69,7 @@ func TestRepositoriesService_ListContributorsStats(t *testing.T) { } func TestRepositoriesService_ListCommitActivity(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/commit_activity", func(w http.ResponseWriter, r *http.Request) { @@ -105,7 +105,7 @@ func TestRepositoriesService_ListCommitActivity(t *testing.T) { } func TestRepositoriesService_ListCodeFrequency(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/code_frequency", func(w http.ResponseWriter, r *http.Request) { @@ -131,7 +131,7 @@ func TestRepositoriesService_ListCodeFrequency(t *testing.T) { } func TestRepositoriesService_Participation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/participation", func(w http.ResponseWriter, r *http.Request) { @@ -181,7 +181,7 @@ func TestRepositoriesService_Participation(t *testing.T) { } func TestRepositoriesService_ListPunchCard(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/stats/punch_card", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/repos_statuses_test.go b/github/repos_statuses_test.go index 8e6c9378d27..21cc238cf4d 100644 --- a/github/repos_statuses_test.go +++ b/github/repos_statuses_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListStatuses(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/commits/r/statuses", func(w http.ResponseWriter, r *http.Request) { @@ -37,12 +37,15 @@ func TestRepositoriesService_ListStatuses(t *testing.T) { } func TestRepositoriesService_ListStatuses_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListStatuses(context.Background(), "%", "r", "r", nil) testURLParseError(t, err) } func TestRepositoriesService_CreateStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &RepoStatus{State: String("s"), TargetURL: String("t"), Description: String("d")} @@ -70,12 +73,15 @@ func TestRepositoriesService_CreateStatus(t *testing.T) { } func TestRepositoriesService_CreateStatus_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.CreateStatus(context.Background(), "%", "r", "r", nil) testURLParseError(t, err) } func TestRepositoriesService_GetCombinedStatus(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/commits/r/status", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/repos_test.go b/github/repos_test.go index 31b9e25ece6..573c48ab98b 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -16,7 +16,7 @@ import ( ) func TestRepositoriesService_List_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} @@ -38,7 +38,7 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) { } func TestRepositoriesService_List_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} @@ -74,7 +74,7 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) { } func TestRepositoriesService_List_specifiedUser_type(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} @@ -102,12 +102,15 @@ func TestRepositoriesService_List_specifiedUser_type(t *testing.T) { } func TestRepositoriesService_List_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.List(context.Background(), "%", nil) testURLParseError(t, err) } func TestRepositoriesService_ListByOrg(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} @@ -134,12 +137,15 @@ func TestRepositoriesService_ListByOrg(t *testing.T) { } func TestRepositoriesService_ListByOrg_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListByOrg(context.Background(), "%", nil) testURLParseError(t, err) } func TestRepositoriesService_ListAll(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repositories", func(w http.ResponseWriter, r *http.Request) { @@ -163,7 +169,7 @@ func TestRepositoriesService_ListAll(t *testing.T) { } func TestRepositoriesService_Create_user(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Repository{Name: String("n")} @@ -192,7 +198,7 @@ func TestRepositoriesService_Create_user(t *testing.T) { } func TestRepositoriesService_Create_org(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Repository{Name: String("n")} @@ -221,12 +227,15 @@ func TestRepositoriesService_Create_org(t *testing.T) { } func TestRepositoriesService_Create_invalidOrg(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.Create(context.Background(), "%", nil) testURLParseError(t, err) } func TestRepositoriesService_Get(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview} @@ -248,7 +257,7 @@ func TestRepositoriesService_Get(t *testing.T) { } func TestRepositoriesService_GetCodeOfConduct(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/community/code_of_conduct", func(w http.ResponseWriter, r *http.Request) { @@ -280,7 +289,7 @@ func TestRepositoriesService_GetCodeOfConduct(t *testing.T) { } func TestRepositoriesService_GetByID(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repositories/1", func(w http.ResponseWriter, r *http.Request) { @@ -301,7 +310,7 @@ func TestRepositoriesService_GetByID(t *testing.T) { } func TestRepositoriesService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() i := true @@ -330,7 +339,7 @@ func TestRepositoriesService_Edit(t *testing.T) { } func TestRepositoriesService_Delete(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) { @@ -344,17 +353,23 @@ func TestRepositoriesService_Delete(t *testing.T) { } func TestRepositoriesService_Get_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.Get(context.Background(), "%", "r") testURLParseError(t, err) } func TestRepositoriesService_Edit_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.Edit(context.Background(), "%", "r", nil) testURLParseError(t, err) } func TestRepositoriesService_ListContributors(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/contributors", func(w http.ResponseWriter, r *http.Request) { @@ -379,7 +394,7 @@ func TestRepositoriesService_ListContributors(t *testing.T) { } func TestRepositoriesService_ListLanguages(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/languages", func(w http.ResponseWriter, r *http.Request) { @@ -399,7 +414,7 @@ func TestRepositoriesService_ListLanguages(t *testing.T) { } func TestRepositoriesService_ListTeams(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/teams", func(w http.ResponseWriter, r *http.Request) { @@ -422,7 +437,7 @@ func TestRepositoriesService_ListTeams(t *testing.T) { } func TestRepositoriesService_ListTags(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/tags", func(w http.ResponseWriter, r *http.Request) { @@ -454,7 +469,7 @@ func TestRepositoriesService_ListTags(t *testing.T) { } func TestRepositoriesService_ListBranches(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches", func(w http.ResponseWriter, r *http.Request) { @@ -477,7 +492,7 @@ func TestRepositoriesService_ListBranches(t *testing.T) { } func TestRepositoriesService_GetBranch(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b", func(w http.ResponseWriter, r *http.Request) { @@ -508,7 +523,7 @@ func TestRepositoriesService_GetBranch(t *testing.T) { } func TestRepositoriesService_GetBranchProtection(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection", func(w http.ResponseWriter, r *http.Request) { @@ -561,7 +576,7 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { } func TestRepositoriesService_UpdateBranchProtection(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &ProtectionRequest{ @@ -631,7 +646,7 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) { } func TestRepositoriesService_RemoveBranchProtection(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection", func(w http.ResponseWriter, r *http.Request) { @@ -647,12 +662,15 @@ func TestRepositoriesService_RemoveBranchProtection(t *testing.T) { } func TestRepositoriesService_ListLanguages_invalidOwner(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Repositories.ListLanguages(context.Background(), "%", "%") testURLParseError(t, err) } func TestRepositoriesService_License(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/license", func(w http.ResponseWriter, r *http.Request) { @@ -683,7 +701,7 @@ func TestRepositoriesService_License(t *testing.T) { } func TestRepositoriesService_GetRequiredStatusChecks(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_status_checks", func(w http.ResponseWriter, r *http.Request) { @@ -710,7 +728,7 @@ func TestRepositoriesService_GetRequiredStatusChecks(t *testing.T) { } func TestRepositoriesService_ListRequiredStatusChecksContexts(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_status_checks/contexts", func(w http.ResponseWriter, r *http.Request) { @@ -734,7 +752,7 @@ func TestRepositoriesService_ListRequiredStatusChecksContexts(t *testing.T) { } func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_pull_request_reviews", func(w http.ResponseWriter, r *http.Request) { @@ -767,7 +785,7 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { } func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &PullRequestReviewsEnforcementUpdate{ @@ -812,7 +830,7 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { } func TestRepositoriesService_DisableDismissalRestrictions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_pull_request_reviews", func(w http.ResponseWriter, r *http.Request) { @@ -841,7 +859,7 @@ func TestRepositoriesService_DisableDismissalRestrictions(t *testing.T) { } func TestRepositoriesService_RemovePullRequestReviewEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/required_pull_request_reviews", func(w http.ResponseWriter, r *http.Request) { @@ -857,7 +875,7 @@ func TestRepositoriesService_RemovePullRequestReviewEnforcement(t *testing.T) { } func TestRepositoriesService_GetAdminEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) { @@ -882,7 +900,7 @@ func TestRepositoriesService_GetAdminEnforcement(t *testing.T) { } func TestRepositoriesService_AddAdminEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) { @@ -906,7 +924,7 @@ func TestRepositoriesService_AddAdminEnforcement(t *testing.T) { } func TestRepositoriesService_RemoveAdminEnforcement(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/branches/b/protection/enforce_admins", func(w http.ResponseWriter, r *http.Request) { @@ -936,7 +954,7 @@ func TestPullRequestReviewsEnforcementRequest_MarshalJSON_nilDismissalRestirctio } func TestRepositoriesService_ListAllTopics(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { @@ -957,7 +975,7 @@ func TestRepositoriesService_ListAllTopics(t *testing.T) { } func TestRepositoriesService_ListAllTopics_emptyTopics(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { @@ -978,7 +996,7 @@ func TestRepositoriesService_ListAllTopics_emptyTopics(t *testing.T) { } func TestRepositoriesService_ReplaceAllTopics(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { @@ -999,7 +1017,7 @@ func TestRepositoriesService_ReplaceAllTopics(t *testing.T) { } func TestRepositoriesService_ReplaceAllTopics_nilSlice(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { @@ -1021,7 +1039,7 @@ func TestRepositoriesService_ReplaceAllTopics_nilSlice(t *testing.T) { } func TestRepositoriesService_ReplaceAllTopics_emptySlice(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) { @@ -1043,7 +1061,7 @@ func TestRepositoriesService_ReplaceAllTopics_emptySlice(t *testing.T) { } func TestRepositoriesService_Transfer(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := TransferRequest{NewOwner: "a", TeamID: []int{123}} diff --git a/github/repos_traffic_test.go b/github/repos_traffic_test.go index c425f5cd5d1..0a2eb4f36d2 100644 --- a/github/repos_traffic_test.go +++ b/github/repos_traffic_test.go @@ -15,7 +15,7 @@ import ( ) func TestRepositoriesService_ListTrafficReferrers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/traffic/popular/referrers", func(w http.ResponseWriter, r *http.Request) { @@ -43,7 +43,7 @@ func TestRepositoriesService_ListTrafficReferrers(t *testing.T) { } func TestRepositoriesService_ListTrafficPaths(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/traffic/popular/paths", func(w http.ResponseWriter, r *http.Request) { @@ -73,7 +73,7 @@ func TestRepositoriesService_ListTrafficPaths(t *testing.T) { } func TestRepositoriesService_ListTrafficViews(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/traffic/views", func(w http.ResponseWriter, r *http.Request) { @@ -109,7 +109,7 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) { } func TestRepositoriesService_ListTrafficClones(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/repos/o/r/traffic/clones", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/search_test.go b/github/search_test.go index 1276e01d8b2..30014a550bd 100644 --- a/github/search_test.go +++ b/github/search_test.go @@ -15,7 +15,7 @@ import ( ) func TestSearchService_Repositories(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/repositories", func(w http.ResponseWriter, r *http.Request) { @@ -48,7 +48,7 @@ func TestSearchService_Repositories(t *testing.T) { } func TestSearchService_Commits(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/commits", func(w http.ResponseWriter, r *http.Request) { @@ -79,7 +79,7 @@ func TestSearchService_Commits(t *testing.T) { } func TestSearchService_Issues(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/issues", func(w http.ResponseWriter, r *http.Request) { @@ -112,7 +112,7 @@ func TestSearchService_Issues(t *testing.T) { } func TestSearchService_Issues_withQualifiers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/issues", func(w http.ResponseWriter, r *http.Request) { @@ -141,7 +141,7 @@ func TestSearchService_Issues_withQualifiers(t *testing.T) { } func TestSearchService_Users(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/users", func(w http.ResponseWriter, r *http.Request) { @@ -174,7 +174,7 @@ func TestSearchService_Users(t *testing.T) { } func TestSearchService_Code(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/code", func(w http.ResponseWriter, r *http.Request) { @@ -207,7 +207,7 @@ func TestSearchService_Code(t *testing.T) { } func TestSearchService_CodeTextMatch(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/search/code", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/users_administration_test.go b/github/users_administration_test.go index 8f02b88cea7..4b0955e9090 100644 --- a/github/users_administration_test.go +++ b/github/users_administration_test.go @@ -12,7 +12,7 @@ import ( ) func TestUsersService_PromoteSiteAdmin(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/site_admin", func(w http.ResponseWriter, r *http.Request) { @@ -27,7 +27,7 @@ func TestUsersService_PromoteSiteAdmin(t *testing.T) { } func TestUsersService_DemoteSiteAdmin(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/site_admin", func(w http.ResponseWriter, r *http.Request) { @@ -42,7 +42,7 @@ func TestUsersService_DemoteSiteAdmin(t *testing.T) { } func TestUsersService_Suspend(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) { @@ -57,7 +57,7 @@ func TestUsersService_Suspend(t *testing.T) { } func TestUsersService_Unsuspend(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/users_blocking_test.go b/github/users_blocking_test.go index ea7a8abdc23..83e8e30c83d 100644 --- a/github/users_blocking_test.go +++ b/github/users_blocking_test.go @@ -14,7 +14,7 @@ import ( ) func TestUsersService_ListBlockedUsers(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/blocks", func(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func TestUsersService_ListBlockedUsers(t *testing.T) { } func TestUsersService_IsBlocked(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { @@ -58,7 +58,7 @@ func TestUsersService_IsBlocked(t *testing.T) { } func TestUsersService_BlockUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { @@ -74,7 +74,7 @@ func TestUsersService_BlockUser(t *testing.T) { } func TestUsersService_UnblockUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/blocks/u", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/users_emails_test.go b/github/users_emails_test.go index 3f8176a0078..3f72b409bb1 100644 --- a/github/users_emails_test.go +++ b/github/users_emails_test.go @@ -15,7 +15,7 @@ import ( ) func TestUsersService_ListEmails(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) { @@ -41,7 +41,7 @@ func TestUsersService_ListEmails(t *testing.T) { } func TestUsersService_AddEmails(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []string{"new@example.com"} @@ -73,7 +73,7 @@ func TestUsersService_AddEmails(t *testing.T) { } func TestUsersService_DeleteEmails(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := []string{"user@example.com"} diff --git a/github/users_followers_test.go b/github/users_followers_test.go index 688af2c4450..255efbdab83 100644 --- a/github/users_followers_test.go +++ b/github/users_followers_test.go @@ -14,7 +14,7 @@ import ( ) func TestUsersService_ListFollowers_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/followers", func(w http.ResponseWriter, r *http.Request) { @@ -36,7 +36,7 @@ func TestUsersService_ListFollowers_authenticatedUser(t *testing.T) { } func TestUsersService_ListFollowers_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/followers", func(w http.ResponseWriter, r *http.Request) { @@ -56,12 +56,15 @@ func TestUsersService_ListFollowers_specifiedUser(t *testing.T) { } func TestUsersService_ListFollowers_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.ListFollowers(context.Background(), "%", nil) testURLParseError(t, err) } func TestUsersService_ListFollowing_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/following", func(w http.ResponseWriter, r *http.Request) { @@ -83,7 +86,7 @@ func TestUsersService_ListFollowing_authenticatedUser(t *testing.T) { } func TestUsersService_ListFollowing_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/following", func(w http.ResponseWriter, r *http.Request) { @@ -103,12 +106,15 @@ func TestUsersService_ListFollowing_specifiedUser(t *testing.T) { } func TestUsersService_ListFollowing_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.ListFollowing(context.Background(), "%", nil) testURLParseError(t, err) } func TestUsersService_IsFollowing_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/following/t", func(w http.ResponseWriter, r *http.Request) { @@ -126,7 +132,7 @@ func TestUsersService_IsFollowing_authenticatedUser(t *testing.T) { } func TestUsersService_IsFollowing_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/following/t", func(w http.ResponseWriter, r *http.Request) { @@ -144,7 +150,7 @@ func TestUsersService_IsFollowing_specifiedUser(t *testing.T) { } func TestUsersService_IsFollowing_false(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/following/t", func(w http.ResponseWriter, r *http.Request) { @@ -162,7 +168,7 @@ func TestUsersService_IsFollowing_false(t *testing.T) { } func TestUsersService_IsFollowing_error(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/following/t", func(w http.ResponseWriter, r *http.Request) { @@ -180,12 +186,15 @@ func TestUsersService_IsFollowing_error(t *testing.T) { } func TestUsersService_IsFollowing_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.IsFollowing(context.Background(), "%", "%") testURLParseError(t, err) } func TestUsersService_Follow(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/following/u", func(w http.ResponseWriter, r *http.Request) { @@ -199,12 +208,15 @@ func TestUsersService_Follow(t *testing.T) { } func TestUsersService_Follow_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Users.Follow(context.Background(), "%") testURLParseError(t, err) } func TestUsersService_Unfollow(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/following/u", func(w http.ResponseWriter, r *http.Request) { @@ -218,6 +230,9 @@ func TestUsersService_Unfollow(t *testing.T) { } func TestUsersService_Unfollow_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, err := client.Users.Unfollow(context.Background(), "%") testURLParseError(t, err) } diff --git a/github/users_gpg_keys_test.go b/github/users_gpg_keys_test.go index f4180df9881..dc89712b4ac 100644 --- a/github/users_gpg_keys_test.go +++ b/github/users_gpg_keys_test.go @@ -15,7 +15,7 @@ import ( ) func TestUsersService_ListGPGKeys_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/gpg_keys", func(w http.ResponseWriter, r *http.Request) { @@ -38,7 +38,7 @@ func TestUsersService_ListGPGKeys_authenticatedUser(t *testing.T) { } func TestUsersService_ListGPGKeys_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/gpg_keys", func(w http.ResponseWriter, r *http.Request) { @@ -59,12 +59,15 @@ func TestUsersService_ListGPGKeys_specifiedUser(t *testing.T) { } func TestUsersService_ListGPGKeys_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.ListGPGKeys(context.Background(), "%", nil) testURLParseError(t, err) } func TestUsersService_GetGPGKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/gpg_keys/1", func(w http.ResponseWriter, r *http.Request) { @@ -85,7 +88,7 @@ func TestUsersService_GetGPGKey(t *testing.T) { } func TestUsersService_CreateGPGKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := ` @@ -124,7 +127,7 @@ mQINBFcEd9kBEACo54TDbGhKlXKWMvJgecEUKPPcv7XdnpKdGb3LRw5MvFwT0V0f } func TestUsersService_DeleteGPGKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/gpg_keys/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/users_keys_test.go b/github/users_keys_test.go index 8554c50cd92..801f44fdf41 100644 --- a/github/users_keys_test.go +++ b/github/users_keys_test.go @@ -15,7 +15,7 @@ import ( ) func TestUsersService_ListKeys_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/keys", func(w http.ResponseWriter, r *http.Request) { @@ -37,7 +37,7 @@ func TestUsersService_ListKeys_authenticatedUser(t *testing.T) { } func TestUsersService_ListKeys_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u/keys", func(w http.ResponseWriter, r *http.Request) { @@ -57,12 +57,15 @@ func TestUsersService_ListKeys_specifiedUser(t *testing.T) { } func TestUsersService_ListKeys_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.ListKeys(context.Background(), "%", nil) testURLParseError(t, err) } func TestUsersService_GetKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/keys/1", func(w http.ResponseWriter, r *http.Request) { @@ -82,7 +85,7 @@ func TestUsersService_GetKey(t *testing.T) { } func TestUsersService_CreateKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &Key{Key: String("k"), Title: String("t")} @@ -111,7 +114,7 @@ func TestUsersService_CreateKey(t *testing.T) { } func TestUsersService_DeleteKey(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/keys/1", func(w http.ResponseWriter, r *http.Request) { diff --git a/github/users_test.go b/github/users_test.go index 34c239a6666..c0c99560c7f 100644 --- a/github/users_test.go +++ b/github/users_test.go @@ -57,7 +57,7 @@ func TestUser_marshall(t *testing.T) { } func TestUsersService_Get_authenticatedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) { @@ -77,7 +77,7 @@ func TestUsersService_Get_authenticatedUser(t *testing.T) { } func TestUsersService_Get_specifiedUser(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users/u", func(w http.ResponseWriter, r *http.Request) { @@ -97,12 +97,15 @@ func TestUsersService_Get_specifiedUser(t *testing.T) { } func TestUsersService_Get_invalidUser(t *testing.T) { + client, _, _, teardown := setup() + defer teardown() + _, _, err := client.Users.Get(context.Background(), "%") testURLParseError(t, err) } func TestUsersService_GetByID(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/1", func(w http.ResponseWriter, r *http.Request) { @@ -122,7 +125,7 @@ func TestUsersService_GetByID(t *testing.T) { } func TestUsersService_Edit(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() input := &User{Name: String("n")} @@ -151,7 +154,7 @@ func TestUsersService_Edit(t *testing.T) { } func TestUsersService_ListAll(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) { @@ -173,7 +176,7 @@ func TestUsersService_ListAll(t *testing.T) { } func TestUsersService_ListInvitations(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/repository_invitations", func(w http.ResponseWriter, r *http.Request) { @@ -194,7 +197,7 @@ func TestUsersService_ListInvitations(t *testing.T) { } func TestUsersService_ListInvitations_withOptions(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/repository_invitations", func(w http.ResponseWriter, r *http.Request) { @@ -212,7 +215,7 @@ func TestUsersService_ListInvitations_withOptions(t *testing.T) { } } func TestUsersService_AcceptInvitation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/repository_invitations/1", func(w http.ResponseWriter, r *http.Request) { @@ -227,7 +230,7 @@ func TestUsersService_AcceptInvitation(t *testing.T) { } func TestUsersService_DeclineInvitation(t *testing.T) { - setup() + client, mux, _, teardown := setup() defer teardown() mux.HandleFunc("/user/repository_invitations/1", func(w http.ResponseWriter, r *http.Request) {