Skip to content

Commit 43a72e2

Browse files
authored
context.Background() -> t.Context() (#3739)
1 parent 1d89310 commit 43a72e2

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

pkg/acquisition/modules/file/file_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fileacquisition_test
22

33
import (
4-
"context"
54
"fmt"
65
"os"
76
"path/filepath"
@@ -545,6 +544,7 @@ mode: tail
545544
}
546545

547546
func TestDiscoveryPolling(t *testing.T) {
547+
ctx := t.Context()
548548
dir := t.TempDir()
549549

550550
pattern := filepath.Join(dir, "*.log")
@@ -569,7 +569,7 @@ mode: tail
569569
tomb := tomb.Tomb{}
570570

571571
// Start acquisition
572-
err = f.StreamingAcquisition(context.Background(), eventChan, &tomb)
572+
err = f.StreamingAcquisition(ctx, eventChan, &tomb)
573573
require.NoError(t, err)
574574

575575
// Create a test file

pkg/apiserver/alerts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestCreateAlert(t *testing.T) {
148148
}
149149

150150
func TestCreateAllowlistedAlert(t *testing.T) {
151-
ctx := context.Background()
151+
ctx := t.Context()
152152
lapi := SetupLAPITest(t, ctx)
153153

154154
allowlist, err := lapi.DBClient.CreateAllowList(ctx, "test", "test", "", false)

pkg/apiserver/allowlists_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package apiserver
22

33
import (
4-
"context"
54
"encoding/json"
65
"net/http"
76
"strings"
@@ -16,7 +15,7 @@ import (
1615
)
1716

1817
func TestAllowlistList(t *testing.T) {
19-
ctx := context.Background()
18+
ctx := t.Context()
2019
lapi := SetupLAPITest(t, ctx)
2120

2221
_, err := lapi.DBClient.CreateAllowList(ctx, "test", "test", "", false)
@@ -37,7 +36,7 @@ func TestAllowlistList(t *testing.T) {
3736
}
3837

3938
func TestGetAllowlist(t *testing.T) {
40-
ctx := context.Background()
39+
ctx := t.Context()
4140
lapi := SetupLAPITest(t, ctx)
4241

4342
l, err := lapi.DBClient.CreateAllowList(ctx, "test", "test", "", false)
@@ -72,7 +71,7 @@ func TestGetAllowlist(t *testing.T) {
7271
}
7372

7473
func TestCheckInAllowlist(t *testing.T) {
75-
ctx := context.Background()
74+
ctx := t.Context()
7675
lapi := SetupLAPITest(t, ctx)
7776

7877
l, err := lapi.DBClient.CreateAllowList(ctx, "test", "test", "", false)
@@ -150,7 +149,7 @@ func TestCheckInAllowlist(t *testing.T) {
150149
}
151150

152151
func TestBulkCheckAllowlist(t *testing.T) {
153-
ctx := context.Background()
152+
ctx := t.Context()
154153
lapi := SetupLAPITest(t, ctx)
155154

156155
// create an allowlist and add one live entry
@@ -191,7 +190,7 @@ func TestBulkCheckAllowlist(t *testing.T) {
191190
}
192191

193192
func TestBulkCheckAllowlist_BadRequest(t *testing.T) {
194-
ctx := context.Background()
193+
ctx := t.Context()
195194
lapi := SetupLAPITest(t, ctx)
196195

197196
// missing or empty body should yield 400

pkg/database/allowlists_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func getDBClient(t *testing.T, ctx context.Context) *Client {
2727
}
2828

2929
func TestCheckAllowlist(t *testing.T) {
30-
ctx := context.Background()
30+
ctx := t.Context()
3131
dbClient := getDBClient(t, ctx)
3232

3333
allowlist, err := dbClient.CreateAllowList(ctx, "test", "test", "", false)
@@ -106,7 +106,7 @@ func TestCheckAllowlist(t *testing.T) {
106106
}
107107

108108
func TestIsAllowListedBy_SingleAndMultiple(t *testing.T) {
109-
ctx := context.Background()
109+
ctx := t.Context()
110110
dbClient := getDBClient(t, ctx)
111111

112112
list1, err := dbClient.CreateAllowList(ctx, "list1", "first list", "", false)
@@ -149,7 +149,7 @@ func TestIsAllowListedBy_SingleAndMultiple(t *testing.T) {
149149
}
150150

151151
func TestIsAllowListedBy_NoMatch(t *testing.T) {
152-
ctx := context.Background()
152+
ctx := t.Context()
153153
dbClient := getDBClient(t, ctx)
154154

155155
list, err := dbClient.CreateAllowList(ctx, "solo", "single", "", false)

0 commit comments

Comments
 (0)