multi: context.Background() -> t.Context()

Use the new feature of Go 1.24, fix linter warnings.

This change was produced by:
 - running golangci-lint run --fix
 - sed 's/context.Background/t.Context/' -i `git grep -l context.Background | grep test.go`
 - manually fixing broken tests
 - itest, lntest: use ht.Context() where ht or hn is available
 - in HarnessNode.Stop() we keep using context.Background(), because it is
   called from a cleanup handler in which t.Context() is canceled already.
This commit is contained in:
Boris Nagaev committed 2025-08-30 14:13:44 -03:00
1 parent 6ffe257004
commit dee8ad3754
71 files changed
+361 -393

No files matched your search

+8 -9
View File
@@ -1,7 +1,6 @@
package sqldb
import (
"context"
"database/sql"
"fmt"
"path/filepath"
@@ -75,7 +74,7 @@ func TestMigrations(t *testing.T) {
// 2592000 seconds for AMP invoices.
func testInvoiceExpiryMigration(t *testing.T, makeDB makeMigrationTestDB) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
// Create a new database that already has the first version of the
// native invoice schema.
@@ -276,7 +275,7 @@ func TestCustomMigration(t *testing.T) {
},
}
ctxb := context.Background()
ctxb := t.Context()
for _, test := range tests {
// checkSchemaVersion checks the database schema version against
// the expected version.
@@ -391,7 +390,7 @@ func TestCustomMigration(t *testing.T) {
"migrations", dbName)
_, err := fixture.db.ExecContext(
context.Background(), "CREATE DATABASE "+dbName,
t.Context(), "CREATE DATABASE "+dbName,
)
require.NoError(t, err)
@@ -490,7 +489,7 @@ func TestSchemaMigrationIdempotency(t *testing.T) {
)
})
ctxb := context.Background()
ctxb := t.Context()
require.NoError(
t, db.ApplyAllMigrations(ctxb, GetMigrations()),
)
@@ -536,7 +535,7 @@ func TestSchemaMigrationIdempotency(t *testing.T) {
"migrations", dbName)
_, err := fixture.db.ExecContext(
context.Background(), "CREATE DATABASE "+dbName,
t.Context(), "CREATE DATABASE "+dbName,
)
require.NoError(t, err)
@@ -550,7 +549,7 @@ func TestSchemaMigrationIdempotency(t *testing.T) {
db, err = NewPostgresStore(cfg)
require.NoError(t, err)
ctxb := context.Background()
ctxb := t.Context()
require.NoError(
t, db.ApplyAllMigrations(ctxb, GetMigrations()),
)
@@ -601,7 +600,7 @@ func TestMigrationSucceedsAfterDirtyStateMigrationFailure19RC1(t *testing.T) {
failingSchemaVersion = 3
)
ctxb := context.Background()
ctxb := t.Context()
migrations := GetMigrations()
migrations = migrations[:maxSchemaVersionBefore19RC1]
lastMigration := migrations[len(migrations)-1]
@@ -692,7 +691,7 @@ func TestMigrationSucceedsAfterDirtyStateMigrationFailure19RC1(t *testing.T) {
"migrations", dbName)
_, err := fixture.db.ExecContext(
context.Background(), "CREATE DATABASE "+dbName,
t.Context(), "CREATE DATABASE "+dbName,
)
require.NoError(t, err)
+4 -4
View File
@@ -18,7 +18,7 @@ import (
func TestExecuteBatchQuery(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
t.Run("empty input returns nil", func(t *testing.T) {
var (
@@ -245,7 +245,7 @@ func TestExecuteBatchQuery(t *testing.T) {
// executing the query in pages.
func TestSQLSliceQueries(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
db := NewTestDB(t)
@@ -327,7 +327,7 @@ func TestSQLSliceQueries(t *testing.T) {
// page until all items are processed or an error occurs.
func TestExecutePaginatedQuery(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
type testItem struct {
id int64
@@ -944,7 +944,7 @@ func TestExecuteCollectAndBatchWithSharedDataQuery(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
cfg := &QueryConfig{
MaxPageSize: tt.maxPageSize,
}