Permalink
Browse files

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.
  • Loading branch information...
chriskingnet authored and dmitshur committed Dec 2, 2017
1 parent b527232 commit df88dd9538970888b81a73d41d6f0ae90129b067
Showing with 898 additions and 505 deletions.
  1. +28 −10 github/activity_events_test.go
  2. +9 −9 github/activity_notifications_test.go
  3. +19 −7 github/activity_star_test.go
  4. +1 −1 github/activity_test.go
  5. +8 −8 github/activity_watching_test.go
  6. +1 −1 github/admin_stats_test.go
  7. +2 −2 github/admin_test.go
  8. +4 −4 github/apps_installation_test.go
  9. +8 −8 github/apps_marketplace_test.go
  10. +6 −6 github/apps_test.go
  11. +16 −16 github/authorizations_test.go
  12. +20 −5 github/gists_comments_test.go
  13. +44 −17 github/gists_test.go
  14. +8 −2 github/git_blobs_test.go
  15. +8 −2 github/git_commits_test.go
  16. +10 −10 github/git_refs_test.go
  17. +2 −2 github/git_tags_test.go
  18. +9 −3 github/git_trees_test.go
  19. +20 −32 github/github_test.go
  20. +5 −2 github/gitignore_test.go
  21. +12 −6 github/issues_assignees_test.go
  22. +21 −6 github/issues_comments_test.go
  23. +3 −3 github/issues_events_test.go
  24. +44 −11 github/issues_labels_test.go
  25. +20 −5 github/issues_milestones_test.go
  26. +24 −9 github/issues_test.go
  27. +1 −1 github/issues_timeline_test.go
  28. +5 −2 github/licenses_test.go
  29. +8 −8 github/migrations_source_import_test.go
  30. +6 −6 github/migrations_test.go
  31. +8 −8 github/misc_test.go
  32. +17 −5 github/orgs_hooks_test.go
  33. +28 −16 github/orgs_members_test.go
  34. +4 −1 github/orgs_outside_collaborators_test.go
  35. +2 −2 github/orgs_projects_test.go
  36. +49 −25 github/orgs_teams_test.go
  37. +15 −6 github/orgs_test.go
  38. +4 −4 github/orgs_users_blocking_test.go
  39. +15 −15 github/projects_test.go
  40. +21 −6 github/pulls_comments_test.go
  41. +4 −4 github/pulls_reviewers_test.go
  42. +29 −8 github/pulls_reviews_test.go
  43. +26 −14 github/pulls_test.go
  44. +9 −9 github/reactions_test.go
  45. +19 −7 github/repos_collaborators_test.go
  46. +24 −6 github/repos_comments_test.go
  47. +7 −7 github/repos_commits_test.go
  48. +1 −1 github/repos_community_health_test.go
  49. +14 −14 github/repos_contents_test.go
  50. +6 −6 github/repos_deployments_test.go
  51. +8 −2 github/repos_forks_test.go
  52. +25 −7 github/repos_hooks_test.go
  53. +3 −3 github/repos_invitations_test.go
  54. +20 −5 github/repos_keys_test.go
  55. +1 −1 github/repos_merging_test.go
  56. +6 −6 github/repos_pages_test.go
  57. +2 −2 github/repos_projects_test.go
  58. +15 −15 github/repos_releases_test.go
  59. +5 −5 github/repos_stats_test.go
  60. +9 −3 github/repos_statuses_test.go
  61. +55 −37 github/repos_test.go
  62. +4 −4 github/repos_traffic_test.go
  63. +7 −7 github/search_test.go
  64. +4 −4 github/users_administration_test.go
  65. +4 −4 github/users_blocking_test.go
  66. +3 −3 github/users_emails_test.go
  67. +25 −10 github/users_followers_test.go
  68. +8 −5 github/users_gpg_keys_test.go
  69. +8 −5 github/users_keys_test.go
  70. +12 −9 github/users_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) {
@@ -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) {
@@ -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)
}
View
@@ -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) {
@@ -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) {
Oops, something went wrong.

0 comments on commit df88dd9

Please sign in to comment.