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

+1 -2
View File
@@ -1,7 +1,6 @@
package macaroons_test
import (
"context"
"encoding/hex"
"testing"
@@ -49,7 +48,7 @@ func TestBakeFromRootKey(t *testing.T) {
md := metadata.New(map[string]string{
"macaroon": hex.EncodeToString(macaroonBytes),
})
macCtx := metadata.NewIncomingContext(context.Background(), md)
macCtx := metadata.NewIncomingContext(t.Context(), md)
// The macaroon should be valid for the service, since the root key was
// the same.
+1 -2
View File
@@ -1,7 +1,6 @@
package macaroons
import (
"context"
"testing"
"gopkg.in/macaroon-bakery.v2/bakery"
@@ -17,7 +16,7 @@ func FuzzUnmarshalMacaroon(f *testing.F) {
func FuzzAuthChecker(f *testing.F) {
rootKeyStore := bakery.NewMemRootKeyStore()
ctx := context.Background()
ctx := f.Context()
f.Fuzz(func(t *testing.T, location, entity, action, method string,
rootKey, id []byte) {
+5 -6
View File
@@ -1,7 +1,6 @@
package macaroons_test
import (
"context"
"encoding/hex"
"path"
"testing"
@@ -55,7 +54,7 @@ func setupTestRootKeyStorage(t *testing.T) kvdb.Backend {
// TestNewService tests the creation of the macaroon service.
func TestNewService(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
// First, initialize a dummy DB file with a store that the service
// can read from. Make sure the file is removed in the end.
@@ -109,7 +108,7 @@ func TestNewService(t *testing.T) {
// incoming context.
func TestValidateMacaroon(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
// First, initialize the service and unlock it.
db := setupTestRootKeyStorage(t)
@@ -157,7 +156,7 @@ func TestValidateMacaroon(t *testing.T) {
// TestListMacaroonIDs checks that ListMacaroonIDs returns the expected result.
func TestListMacaroonIDs(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
// First, initialize a dummy DB file with a store that the service
// can read from. Make sure the file is removed in the end.
@@ -192,7 +191,7 @@ func TestListMacaroonIDs(t *testing.T) {
func TestDeleteMacaroonID(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
// First, initialize a dummy DB file with a store that the service
// can read from. Make sure the file is removed in the end.
@@ -308,7 +307,7 @@ func TestCloneMacaroons(t *testing.T) {
func TestMacaroonVersionDecode(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
// First, initialize a dummy DB file with a store that the service
// can read from. Make sure the file is removed in the end.
+1 -1
View File
@@ -59,7 +59,7 @@ func openTestStore(t *testing.T, tempDir string) *macaroons.RootKeyStorage {
// reading keys and closing it.
func TestStore(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
tempDir, store := newTestStore(t)