Skip to content

Commit df88dd9

Browse files
chriskingnetdmitshur
authored andcommitted
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.
1 parent b527232 commit df88dd9

File tree

70 files changed

+898
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+898
-505
lines changed

github/activity_events_test.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestActivityService_ListEvents(t *testing.T) {
18-
setup()
18+
client, mux, _, teardown := setup()
1919
defer teardown()
2020

2121
mux.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) {
@@ -39,7 +39,7 @@ func TestActivityService_ListEvents(t *testing.T) {
3939
}
4040

4141
func TestActivityService_ListRepositoryEvents(t *testing.T) {
42-
setup()
42+
client, mux, _, teardown := setup()
4343
defer teardown()
4444

4545
mux.HandleFunc("/repos/o/r/events", func(w http.ResponseWriter, r *http.Request) {
@@ -63,12 +63,15 @@ func TestActivityService_ListRepositoryEvents(t *testing.T) {
6363
}
6464

6565
func TestActivityService_ListRepositoryEvents_invalidOwner(t *testing.T) {
66+
client, _, _, teardown := setup()
67+
defer teardown()
68+
6669
_, _, err := client.Activity.ListRepositoryEvents(context.Background(), "%", "%", nil)
6770
testURLParseError(t, err)
6871
}
6972

7073
func TestActivityService_ListIssueEventsForRepository(t *testing.T) {
71-
setup()
74+
client, mux, _, teardown := setup()
7275
defer teardown()
7376

7477
mux.HandleFunc("/repos/o/r/issues/events", func(w http.ResponseWriter, r *http.Request) {
@@ -92,12 +95,15 @@ func TestActivityService_ListIssueEventsForRepository(t *testing.T) {
9295
}
9396

9497
func TestActivityService_ListIssueEventsForRepository_invalidOwner(t *testing.T) {
98+
client, _, _, teardown := setup()
99+
defer teardown()
100+
95101
_, _, err := client.Activity.ListIssueEventsForRepository(context.Background(), "%", "%", nil)
96102
testURLParseError(t, err)
97103
}
98104

99105
func TestActivityService_ListEventsForRepoNetwork(t *testing.T) {
100-
setup()
106+
client, mux, _, teardown := setup()
101107
defer teardown()
102108

103109
mux.HandleFunc("/networks/o/r/events", func(w http.ResponseWriter, r *http.Request) {
@@ -121,12 +127,15 @@ func TestActivityService_ListEventsForRepoNetwork(t *testing.T) {
121127
}
122128

123129
func TestActivityService_ListEventsForRepoNetwork_invalidOwner(t *testing.T) {
130+
client, _, _, teardown := setup()
131+
defer teardown()
132+
124133
_, _, err := client.Activity.ListEventsForRepoNetwork(context.Background(), "%", "%", nil)
125134
testURLParseError(t, err)
126135
}
127136

128137
func TestActivityService_ListEventsForOrganization(t *testing.T) {
129-
setup()
138+
client, mux, _, teardown := setup()
130139
defer teardown()
131140

132141
mux.HandleFunc("/orgs/o/events", func(w http.ResponseWriter, r *http.Request) {
@@ -150,12 +159,15 @@ func TestActivityService_ListEventsForOrganization(t *testing.T) {
150159
}
151160

152161
func TestActivityService_ListEventsForOrganization_invalidOrg(t *testing.T) {
162+
client, _, _, teardown := setup()
163+
defer teardown()
164+
153165
_, _, err := client.Activity.ListEventsForOrganization(context.Background(), "%", nil)
154166
testURLParseError(t, err)
155167
}
156168

157169
func TestActivityService_ListEventsPerformedByUser_all(t *testing.T) {
158-
setup()
170+
client, mux, _, teardown := setup()
159171
defer teardown()
160172

161173
mux.HandleFunc("/users/u/events", func(w http.ResponseWriter, r *http.Request) {
@@ -179,7 +191,7 @@ func TestActivityService_ListEventsPerformedByUser_all(t *testing.T) {
179191
}
180192

181193
func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) {
182-
setup()
194+
client, mux, _, teardown := setup()
183195
defer teardown()
184196

185197
mux.HandleFunc("/users/u/events/public", func(w http.ResponseWriter, r *http.Request) {
@@ -199,12 +211,15 @@ func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) {
199211
}
200212

201213
func TestActivityService_ListEventsPerformedByUser_invalidUser(t *testing.T) {
214+
client, _, _, teardown := setup()
215+
defer teardown()
216+
202217
_, _, err := client.Activity.ListEventsPerformedByUser(context.Background(), "%", false, nil)
203218
testURLParseError(t, err)
204219
}
205220

206221
func TestActivityService_ListEventsReceivedByUser_all(t *testing.T) {
207-
setup()
222+
client, mux, _, teardown := setup()
208223
defer teardown()
209224

210225
mux.HandleFunc("/users/u/received_events", func(w http.ResponseWriter, r *http.Request) {
@@ -228,7 +243,7 @@ func TestActivityService_ListEventsReceivedByUser_all(t *testing.T) {
228243
}
229244

230245
func TestActivityService_ListEventsReceivedByUser_publicOnly(t *testing.T) {
231-
setup()
246+
client, mux, _, teardown := setup()
232247
defer teardown()
233248

234249
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) {
248263
}
249264

250265
func TestActivityService_ListEventsReceivedByUser_invalidUser(t *testing.T) {
266+
client, _, _, teardown := setup()
267+
defer teardown()
268+
251269
_, _, err := client.Activity.ListEventsReceivedByUser(context.Background(), "%", false, nil)
252270
testURLParseError(t, err)
253271
}
254272

255273
func TestActivityService_ListUserEventsForOrganization(t *testing.T) {
256-
setup()
274+
client, mux, _, teardown := setup()
257275
defer teardown()
258276

259277
mux.HandleFunc("/users/u/events/orgs/o", func(w http.ResponseWriter, r *http.Request) {

github/activity_notifications_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
func TestActivityService_ListNotification(t *testing.T) {
19-
setup()
19+
client, mux, _, teardown := setup()
2020
defer teardown()
2121

2222
mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) {
@@ -49,7 +49,7 @@ func TestActivityService_ListNotification(t *testing.T) {
4949
}
5050

5151
func TestActivityService_ListRepositoryNotification(t *testing.T) {
52-
setup()
52+
client, mux, _, teardown := setup()
5353
defer teardown()
5454

5555
mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) {
@@ -69,7 +69,7 @@ func TestActivityService_ListRepositoryNotification(t *testing.T) {
6969
}
7070

7171
func TestActivityService_MarkNotificationsRead(t *testing.T) {
72-
setup()
72+
client, mux, _, teardown := setup()
7373
defer teardown()
7474

7575
mux.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) {
@@ -87,7 +87,7 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) {
8787
}
8888

8989
func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) {
90-
setup()
90+
client, mux, _, teardown := setup()
9191
defer teardown()
9292

9393
mux.HandleFunc("/repos/o/r/notifications", func(w http.ResponseWriter, r *http.Request) {
@@ -105,7 +105,7 @@ func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) {
105105
}
106106

107107
func TestActivityService_GetThread(t *testing.T) {
108-
setup()
108+
client, mux, _, teardown := setup()
109109
defer teardown()
110110

111111
mux.HandleFunc("/notifications/threads/1", func(w http.ResponseWriter, r *http.Request) {
@@ -125,7 +125,7 @@ func TestActivityService_GetThread(t *testing.T) {
125125
}
126126

127127
func TestActivityService_MarkThreadRead(t *testing.T) {
128-
setup()
128+
client, mux, _, teardown := setup()
129129
defer teardown()
130130

131131
mux.HandleFunc("/notifications/threads/1", func(w http.ResponseWriter, r *http.Request) {
@@ -140,7 +140,7 @@ func TestActivityService_MarkThreadRead(t *testing.T) {
140140
}
141141

142142
func TestActivityService_GetThreadSubscription(t *testing.T) {
143-
setup()
143+
client, mux, _, teardown := setup()
144144
defer teardown()
145145

146146
mux.HandleFunc("/notifications/threads/1/subscription", func(w http.ResponseWriter, r *http.Request) {
@@ -160,7 +160,7 @@ func TestActivityService_GetThreadSubscription(t *testing.T) {
160160
}
161161

162162
func TestActivityService_SetThreadSubscription(t *testing.T) {
163-
setup()
163+
client, mux, _, teardown := setup()
164164
defer teardown()
165165

166166
input := &Subscription{Subscribed: Bool(true)}
@@ -189,7 +189,7 @@ func TestActivityService_SetThreadSubscription(t *testing.T) {
189189
}
190190

191191
func TestActivityService_DeleteThreadSubscription(t *testing.T) {
192-
setup()
192+
client, mux, _, teardown := setup()
193193
defer teardown()
194194

195195
mux.HandleFunc("/notifications/threads/1/subscription", func(w http.ResponseWriter, r *http.Request) {

github/activity_star_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestActivityService_ListStargazers(t *testing.T) {
18-
setup()
18+
client, mux, _, teardown := setup()
1919
defer teardown()
2020

2121
mux.HandleFunc("/repos/o/r/stargazers", func(w http.ResponseWriter, r *http.Request) {
@@ -40,7 +40,7 @@ func TestActivityService_ListStargazers(t *testing.T) {
4040
}
4141

4242
func TestActivityService_ListStarred_authenticatedUser(t *testing.T) {
43-
setup()
43+
client, mux, _, teardown := setup()
4444
defer teardown()
4545

4646
mux.HandleFunc("/user/starred", func(w http.ResponseWriter, r *http.Request) {
@@ -61,7 +61,7 @@ func TestActivityService_ListStarred_authenticatedUser(t *testing.T) {
6161
}
6262

6363
func TestActivityService_ListStarred_specifiedUser(t *testing.T) {
64-
setup()
64+
client, mux, _, teardown := setup()
6565
defer teardown()
6666

6767
mux.HandleFunc("/users/u/starred", func(w http.ResponseWriter, r *http.Request) {
@@ -88,12 +88,15 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) {
8888
}
8989

9090
func TestActivityService_ListStarred_invalidUser(t *testing.T) {
91+
client, _, _, teardown := setup()
92+
defer teardown()
93+
9194
_, _, err := client.Activity.ListStarred(context.Background(), "%", nil)
9295
testURLParseError(t, err)
9396
}
9497

9598
func TestActivityService_IsStarred_hasStar(t *testing.T) {
96-
setup()
99+
client, mux, _, teardown := setup()
97100
defer teardown()
98101

99102
mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) {
@@ -111,7 +114,7 @@ func TestActivityService_IsStarred_hasStar(t *testing.T) {
111114
}
112115

113116
func TestActivityService_IsStarred_noStar(t *testing.T) {
114-
setup()
117+
client, mux, _, teardown := setup()
115118
defer teardown()
116119

117120
mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) {
@@ -129,12 +132,15 @@ func TestActivityService_IsStarred_noStar(t *testing.T) {
129132
}
130133

131134
func TestActivityService_IsStarred_invalidID(t *testing.T) {
135+
client, _, _, teardown := setup()
136+
defer teardown()
137+
132138
_, _, err := client.Activity.IsStarred(context.Background(), "%", "%")
133139
testURLParseError(t, err)
134140
}
135141

136142
func TestActivityService_Star(t *testing.T) {
137-
setup()
143+
client, mux, _, teardown := setup()
138144
defer teardown()
139145

140146
mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) {
@@ -148,12 +154,15 @@ func TestActivityService_Star(t *testing.T) {
148154
}
149155

150156
func TestActivityService_Star_invalidID(t *testing.T) {
157+
client, _, _, teardown := setup()
158+
defer teardown()
159+
151160
_, err := client.Activity.Star(context.Background(), "%", "%")
152161
testURLParseError(t, err)
153162
}
154163

155164
func TestActivityService_Unstar(t *testing.T) {
156-
setup()
165+
client, mux, _, teardown := setup()
157166
defer teardown()
158167

159168
mux.HandleFunc("/user/starred/o/r", func(w http.ResponseWriter, r *http.Request) {
@@ -167,6 +176,9 @@ func TestActivityService_Unstar(t *testing.T) {
167176
}
168177

169178
func TestActivityService_Unstar_invalidID(t *testing.T) {
179+
client, _, _, teardown := setup()
180+
defer teardown()
181+
170182
_, err := client.Activity.Unstar(context.Background(), "%", "%")
171183
testURLParseError(t, err)
172184
}

github/activity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func TestActivityService_List(t *testing.T) {
16-
setup()
16+
client, mux, _, teardown := setup()
1717
defer teardown()
1818

1919
mux.HandleFunc("/feeds", func(w http.ResponseWriter, r *http.Request) {

github/activity_watching_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestActivityService_ListWatchers(t *testing.T) {
18-
setup()
18+
client, mux, _, teardown := setup()
1919
defer teardown()
2020

2121
mux.HandleFunc("/repos/o/r/subscribers", func(w http.ResponseWriter, r *http.Request) {
@@ -39,7 +39,7 @@ func TestActivityService_ListWatchers(t *testing.T) {
3939
}
4040

4141
func TestActivityService_ListWatched_authenticatedUser(t *testing.T) {
42-
setup()
42+
client, mux, _, teardown := setup()
4343
defer teardown()
4444

4545
mux.HandleFunc("/user/subscriptions", func(w http.ResponseWriter, r *http.Request) {
@@ -62,7 +62,7 @@ func TestActivityService_ListWatched_authenticatedUser(t *testing.T) {
6262
}
6363

6464
func TestActivityService_ListWatched_specifiedUser(t *testing.T) {
65-
setup()
65+
client, mux, _, teardown := setup()
6666
defer teardown()
6767

6868
mux.HandleFunc("/users/u/subscriptions", func(w http.ResponseWriter, r *http.Request) {
@@ -85,7 +85,7 @@ func TestActivityService_ListWatched_specifiedUser(t *testing.T) {
8585
}
8686

8787
func TestActivityService_GetRepositorySubscription_true(t *testing.T) {
88-
setup()
88+
client, mux, _, teardown := setup()
8989
defer teardown()
9090

9191
mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) {
@@ -105,7 +105,7 @@ func TestActivityService_GetRepositorySubscription_true(t *testing.T) {
105105
}
106106

107107
func TestActivityService_GetRepositorySubscription_false(t *testing.T) {
108-
setup()
108+
client, mux, _, teardown := setup()
109109
defer teardown()
110110

111111
mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) {
@@ -125,7 +125,7 @@ func TestActivityService_GetRepositorySubscription_false(t *testing.T) {
125125
}
126126

127127
func TestActivityService_GetRepositorySubscription_error(t *testing.T) {
128-
setup()
128+
client, mux, _, teardown := setup()
129129
defer teardown()
130130

131131
mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) {
@@ -140,7 +140,7 @@ func TestActivityService_GetRepositorySubscription_error(t *testing.T) {
140140
}
141141

142142
func TestActivityService_SetRepositorySubscription(t *testing.T) {
143-
setup()
143+
client, mux, _, teardown := setup()
144144
defer teardown()
145145

146146
input := &Subscription{Subscribed: Bool(true)}
@@ -169,7 +169,7 @@ func TestActivityService_SetRepositorySubscription(t *testing.T) {
169169
}
170170

171171
func TestActivityService_DeleteRepositorySubscription(t *testing.T) {
172-
setup()
172+
client, mux, _, teardown := setup()
173173
defer teardown()
174174

175175
mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)