Skip to content

Removes global test client and calls setup for each client test #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions github/activity_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions github/activity_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)}
Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 19 additions & 7 deletions github/activity_star_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion github/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions github/activity_watching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)}
Expand Down Expand Up @@ -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) {
Expand Down
Loading