Skip to content

Commit 80d443f

Browse files
committed
test: make golangci-lint happy
1 parent 3681f2d commit 80d443f

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

caddy/caddy_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ example.com:9080 {
7777
received.Add(1)
7878

7979
go func() {
80-
cx, cancel := context.WithCancel(context.Background())
80+
cx, cancel := context.WithCancel(t.Context())
8181
req, _ := http.NewRequest(http.MethodGet, "http://localhost:9080/.well-known/mercure?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1", nil)
8282
req = req.WithContext(cx)
8383
resp := tester.AssertResponseCode(req, http.StatusOK)
@@ -158,7 +158,7 @@ func TestJWTPlaceholders(t *testing.T) {
158158
received.Add(1)
159159

160160
go func() {
161-
cx, cancel := context.WithCancel(context.Background())
161+
cx, cancel := context.WithCancel(t.Context())
162162
req, _ := http.NewRequest(http.MethodGet, "http://localhost:9080/.well-known/mercure?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1", nil)
163163
req = req.WithContext(cx)
164164
resp := tester.AssertResponseCode(req, http.StatusOK)
@@ -260,7 +260,7 @@ func TestCookieName(t *testing.T) {
260260
received.Add(1)
261261

262262
go func() {
263-
cx, cancel := context.WithCancel(context.Background())
263+
cx, cancel := context.WithCancel(t.Context())
264264
req, _ := http.NewRequest(http.MethodGet, "http://localhost:9080/.well-known/mercure?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1", nil)
265265
req.Header.Add("Origin", "http://localhost:9080")
266266
req.AddCookie(&http.Cookie{Name: "foo", Value: subscriberJWT})

local_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func subBenchLocalTransport(b *testing.B, topics, concurrency, matchPct int, tes
5050
s.out = out
5151
tr.AddSubscriber(s)
5252
}
53-
ctx, done := context.WithCancel(context.Background())
53+
ctx, done := context.WithCancel(b.Context())
5454
defer done()
5555
for i := 0; i < 1; i++ {
5656
go func() {

server_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestForwardedHeaders(t *testing.T) {
5656

5757
assert.Equal(t, 1, logs.FilterField(zap.String("remote_addr", "192.0.2.1")).Len())
5858

59-
h.server.Shutdown(context.Background())
59+
h.server.Shutdown(t.Context())
6060
}
6161

6262
func TestSecurityOptions(t *testing.T) {
@@ -105,7 +105,7 @@ func TestSecurityOptions(t *testing.T) {
105105
assert.Equal(t, http.StatusUnauthorized, resp3.StatusCode)
106106
resp3.Body.Close()
107107

108-
h.server.Shutdown(context.Background())
108+
h.server.Shutdown(t.Context())
109109
}
110110

111111
func TestSecurityOptionsWithCorsOrigin(t *testing.T) {
@@ -152,7 +152,7 @@ func TestSecurityOptionsWithCorsOrigin(t *testing.T) {
152152
assert.Equal(t, "https://subscriber.com", resp2.Header.Get("Access-Control-Allow-Origin"))
153153
resp2.Body.Close()
154154

155-
h.server.Shutdown(context.Background())
155+
h.server.Shutdown(t.Context())
156156
}
157157

158158
func TestServe(t *testing.T) {
@@ -216,7 +216,7 @@ func TestServe(t *testing.T) {
216216
require.NoError(t, err)
217217
defer resp2.Body.Close()
218218

219-
h.server.Shutdown(context.Background())
219+
h.server.Shutdown(t.Context())
220220
wgTested.Wait()
221221
}
222222

@@ -243,7 +243,7 @@ func TestClientClosesThenReconnects(t *testing.T) {
243243
var wg, subscribingWG sync.WaitGroup
244244

245245
subscribe := func(expectedBodyData string) {
246-
cx, cancel := context.WithCancel(context.Background())
246+
cx, cancel := context.WithCancel(t.Context())
247247
req, _ := http.NewRequest(http.MethodGet, testURL+"?topic=http%3A%2F%2Fexample.com%2Ffoo%2F1", nil)
248248
req = req.WithContext(cx)
249249
resp, err := http.DefaultClient.Do(req)
@@ -316,7 +316,7 @@ func TestClientClosesThenReconnects(t *testing.T) {
316316
go publish("second")
317317
}
318318
wg.Wait()
319-
h.server.Shutdown(context.Background())
319+
h.server.Shutdown(t.Context())
320320
}
321321

322322
func TestServeAcme(t *testing.T) {
@@ -347,7 +347,7 @@ func TestServeAcme(t *testing.T) {
347347
defer resp.Body.Close()
348348

349349
assert.Equal(t, 403, resp.StatusCode)
350-
h.server.Shutdown(context.Background())
350+
h.server.Shutdown(t.Context())
351351
}
352352

353353
func TestMetricsAccess(t *testing.T) {
@@ -441,8 +441,8 @@ func newTestServer(t *testing.T) testServer {
441441
}
442442

443443
func (s *testServer) shutdown() {
444-
s.h.server.Shutdown(context.Background())
445-
s.h.metricsServer.Shutdown(context.Background())
444+
s.h.server.Shutdown(s.t.Context())
445+
s.h.metricsServer.Shutdown(s.t.Context())
446446
s.wgShutdown.Done()
447447
s.wgTested.Wait()
448448
}

subscribe_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func testSubscribe(h interface{ Helper() }, numberOfSubscribers int) {
326326
for i := 0; i < numberOfSubscribers; i++ {
327327
go func() {
328328
defer wg.Done()
329-
ctx, cancel := context.WithCancel(context.Background())
329+
ctx, cancel := context.WithCancel(t.Context())
330330
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/books/1&topic=string&topic=http://example.com/reviews/{id}&topic=http://example.com/hub?topic=faulty{iri", nil).WithContext(ctx)
331331

332332
w := &responseTester{
@@ -351,7 +351,7 @@ func TestSubscribe(t *testing.T) {
351351
func testSubscribeLogs(t *testing.T, hub *Hub, payload interface{}) {
352352
t.Helper()
353353

354-
ctx, cancel := context.WithCancel(context.Background())
354+
ctx, cancel := context.WithCancel(t.Context())
355355
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/reviews/{id}", nil).WithContext(ctx)
356356
req.AddCookie(&http.Cookie{Name: "mercureAuthorization", Value: createDummyAuthorizedJWTWithPayload(roleSubscriber, []string{"http://example.com/reviews/22"}, payload)})
357357

@@ -405,7 +405,7 @@ func TestSubscribeLogAnonymousSubscriber(t *testing.T) {
405405

406406
h := createAnonymousDummy(WithLogger(zap.New(core)))
407407

408-
ctx, cancel := context.WithCancel(context.Background())
408+
ctx, cancel := context.WithCancel(t.Context())
409409
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/", nil).WithContext(ctx)
410410

411411
w := &responseTester{
@@ -427,7 +427,7 @@ func TestUnsubscribe(t *testing.T) {
427427

428428
s, _ := hub.transport.(*LocalTransport)
429429
assert.Equal(t, 0, s.subscribers.Len())
430-
ctx, cancel := context.WithCancel(context.Background())
430+
ctx, cancel := context.WithCancel(t.Context())
431431

432432
var wg sync.WaitGroup
433433
wg.Add(1)
@@ -493,7 +493,7 @@ func TestSubscribePrivate(t *testing.T) {
493493
}
494494
}()
495495

496-
ctx, cancel := context.WithCancel(context.Background())
496+
ctx, cancel := context.WithCancel(t.Context())
497497
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/reviews/{id}", nil).WithContext(ctx)
498498
req.AddCookie(&http.Cookie{Name: "mercureAuthorization", Value: createDummyAuthorizedJWT(roleSubscriber, []string{"http://example.com/reviews/22", "http://example.com/reviews/23"})})
499499

@@ -513,8 +513,8 @@ func TestSubscriptionEvents(t *testing.T) {
513513
hub := createDummy(WithSubscriptions())
514514

515515
var wg sync.WaitGroup
516-
ctx1, cancel1 := context.WithCancel(context.Background())
517-
ctx2, cancel2 := context.WithCancel(context.Background())
516+
ctx1, cancel1 := context.WithCancel(t.Context())
517+
ctx2, cancel2 := context.WithCancel(t.Context())
518518
wg.Add(3)
519519
go func() {
520520
// Authorized to receive connection events
@@ -567,7 +567,7 @@ func TestSubscriptionEvents(t *testing.T) {
567567
}
568568
}
569569

570-
ctx, cancelRequest2 := context.WithCancel(context.Background())
570+
ctx, cancelRequest2 := context.WithCancel(t.Context())
571571
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=https://example.com", nil).WithContext(ctx)
572572
req.AddCookie(&http.Cookie{Name: "mercureAuthorization", Value: createDummyAuthorizedJWT(roleSubscriber, []string{})})
573573

@@ -617,7 +617,7 @@ func TestSubscribeAll(t *testing.T) {
617617
}
618618
}()
619619

620-
ctx, cancel := context.WithCancel(context.Background())
620+
ctx, cancel := context.WithCancel(t.Context())
621621
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/reviews/{id}", nil).WithContext(ctx)
622622
req.Header.Add("Authorization", bearerPrefix+createDummyAuthorizedJWT(roleSubscriber, []string{"random", "*"}))
623623

@@ -661,7 +661,7 @@ func TestSendMissedEvents(t *testing.T) {
661661
go func() {
662662
defer wg.Done()
663663

664-
ctx, cancel := context.WithCancel(context.Background())
664+
ctx, cancel := context.WithCancel(t.Context())
665665
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}&Last-Event-ID=a", nil).WithContext(ctx)
666666

667667
w := &responseTester{
@@ -677,7 +677,7 @@ func TestSendMissedEvents(t *testing.T) {
677677
go func() {
678678
defer wg.Done()
679679

680-
ctx, cancel := context.WithCancel(context.Background())
680+
ctx, cancel := context.WithCancel(t.Context())
681681
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}&lastEventID=a", nil).WithContext(ctx)
682682

683683
w := &responseTester{
@@ -693,7 +693,7 @@ func TestSendMissedEvents(t *testing.T) {
693693
go func() {
694694
defer wg.Done()
695695

696-
ctx, cancel := context.WithCancel(context.Background())
696+
ctx, cancel := context.WithCancel(t.Context())
697697
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}", nil).WithContext(ctx)
698698
req.Header.Add("Last-Event-ID", "a")
699699

@@ -738,7 +738,7 @@ func TestSendAllEvents(t *testing.T) {
738738
go func() {
739739
defer wg.Done()
740740

741-
ctx, cancel := context.WithCancel(context.Background())
741+
ctx, cancel := context.WithCancel(t.Context())
742742
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}&lastEventID="+EarliestLastEventID, nil).WithContext(ctx)
743743

744744
w := &responseTester{
@@ -755,7 +755,7 @@ func TestSendAllEvents(t *testing.T) {
755755
go func() {
756756
defer wg.Done()
757757

758-
ctx, cancel := context.WithCancel(context.Background())
758+
ctx, cancel := context.WithCancel(t.Context())
759759
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}", nil).WithContext(ctx)
760760
req.Header.Add("Last-Event-ID", EarliestLastEventID)
761761

@@ -795,7 +795,7 @@ func TestUnknownLastEventID(t *testing.T) {
795795
go func() {
796796
defer wg.Done()
797797

798-
ctx, cancel := context.WithCancel(context.Background())
798+
ctx, cancel := context.WithCancel(t.Context())
799799
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}&lastEventID=unknown", nil).WithContext(ctx)
800800

801801
w := &responseTester{
@@ -813,7 +813,7 @@ func TestUnknownLastEventID(t *testing.T) {
813813
go func() {
814814
defer wg.Done()
815815

816-
ctx, cancel := context.WithCancel(context.Background())
816+
ctx, cancel := context.WithCancel(t.Context())
817817
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}", nil).WithContext(ctx)
818818
req.Header.Add("Last-Event-ID", "unknown")
819819

@@ -864,7 +864,7 @@ func TestUnknownLastEventIDEmptyHistory(t *testing.T) {
864864
go func() {
865865
defer wg.Done()
866866

867-
ctx, cancel := context.WithCancel(context.Background())
867+
ctx, cancel := context.WithCancel(t.Context())
868868
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}&lastEventID=unknown", nil).WithContext(ctx)
869869

870870
w := &responseTester{
@@ -882,7 +882,7 @@ func TestUnknownLastEventIDEmptyHistory(t *testing.T) {
882882
go func() {
883883
defer wg.Done()
884884

885-
ctx, cancel := context.WithCancel(context.Background())
885+
ctx, cancel := context.WithCancel(t.Context())
886886
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/foos/{id}", nil).WithContext(ctx)
887887
req.Header.Add("Last-Event-ID", "unknown")
888888

@@ -942,7 +942,7 @@ func TestSubscribeHeartbeat(t *testing.T) {
942942
}
943943
}()
944944

945-
ctx, cancel := context.WithCancel(context.Background())
945+
ctx, cancel := context.WithCancel(t.Context())
946946
req := httptest.NewRequest(http.MethodGet, defaultHubURL+"?topic=http://example.com/books/1&topic=http://example.com/reviews/{id}", nil).WithContext(ctx)
947947

948948
w := &responseTester{

subscriber_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func subBenchSubscriber(b *testing.B, topics, concurrency, matchPct int, testNam
101101
}
102102
s.SetTopics(ts, nil)
103103
defer s.Disconnect()
104-
ctx, done := context.WithCancel(context.Background())
104+
ctx, done := context.WithCancel(b.Context())
105105
defer done()
106106
for i := 0; i < 1; i++ {
107107
go func() {

0 commit comments

Comments
 (0)