mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
remove context.TODOs from tests
This commit is contained in:
parent
6cdfdfd3ee
commit
fa0510910c
@ -19,7 +19,7 @@ func TestDump(t *testing.T) {
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
db, err := newEtcdBackend(context.Background(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
|
||||
err = db.Update(func(tx walletdb.ReadWriteTx) error {
|
||||
|
@ -16,7 +16,7 @@ func TestChangeDuringManualTx(t *testing.T) {
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
db, err := newEtcdBackend(context.Background(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
|
||||
tx, err := db.BeginReadWriteTx()
|
||||
@ -44,7 +44,7 @@ func TestChangeDuringUpdate(t *testing.T) {
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
db, err := newEtcdBackend(context.Background(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
|
||||
count := 0
|
||||
|
@ -15,5 +15,5 @@ import (
|
||||
func TestWalletDBInterface(t *testing.T) {
|
||||
f := NewEtcdTestFixture(t)
|
||||
cfg := f.BackendConfig()
|
||||
walletdbtest.TestInterface(t, dbType, context.TODO(), &cfg)
|
||||
walletdbtest.TestInterface(t, dbType, context.Background(), &cfg)
|
||||
}
|
||||
|
@ -55,6 +55,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()
|
||||
|
||||
// First, initialize a dummy DB file with a store that the service
|
||||
// can read from. Make sure the file is removed in the end.
|
||||
@ -74,13 +75,13 @@ func TestNewService(t *testing.T) {
|
||||
require.NoError(t, err, "Error unlocking root key storage")
|
||||
|
||||
// Third, check if the created service can bake macaroons.
|
||||
_, err = service.NewMacaroon(context.TODO(), nil, testOperation)
|
||||
_, err = service.NewMacaroon(ctx, nil, testOperation)
|
||||
if err != macaroons.ErrMissingRootKeyID {
|
||||
t.Fatalf("Received %v instead of ErrMissingRootKeyID", err)
|
||||
}
|
||||
|
||||
macaroon, err := service.NewMacaroon(
|
||||
context.TODO(), macaroons.DefaultRootKeyID, testOperation,
|
||||
ctx, macaroons.DefaultRootKeyID, testOperation,
|
||||
)
|
||||
require.NoError(t, err, "Error creating macaroon from service")
|
||||
if macaroon.Namespace().String() != "std:" {
|
||||
@ -108,6 +109,7 @@ func TestNewService(t *testing.T) {
|
||||
// incoming context.
|
||||
func TestValidateMacaroon(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
// First, initialize the service and unlock it.
|
||||
db := setupTestRootKeyStorage(t)
|
||||
@ -124,7 +126,7 @@ func TestValidateMacaroon(t *testing.T) {
|
||||
|
||||
// Then, create a new macaroon that we can serialize.
|
||||
macaroon, err := service.NewMacaroon(
|
||||
context.TODO(), macaroons.DefaultRootKeyID, testOperation,
|
||||
ctx, macaroons.DefaultRootKeyID, testOperation,
|
||||
testOperationURI,
|
||||
)
|
||||
require.NoError(t, err, "Error creating macaroon from service")
|
||||
@ -155,6 +157,7 @@ func TestValidateMacaroon(t *testing.T) {
|
||||
// TestListMacaroonIDs checks that ListMacaroonIDs returns the expected result.
|
||||
func TestListMacaroonIDs(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
// First, initialize a dummy DB file with a store that the service
|
||||
// can read from. Make sure the file is removed in the end.
|
||||
@ -176,12 +179,12 @@ func TestListMacaroonIDs(t *testing.T) {
|
||||
// Third, make 3 new macaroons with different root key IDs.
|
||||
expectedIDs := [][]byte{{1}, {2}, {3}}
|
||||
for _, v := range expectedIDs {
|
||||
_, err := service.NewMacaroon(context.TODO(), v, testOperation)
|
||||
_, err := service.NewMacaroon(ctx, v, testOperation)
|
||||
require.NoError(t, err, "Error creating macaroon from service")
|
||||
}
|
||||
|
||||
// Finally, check that calling List return the expected values.
|
||||
ids, _ := service.ListMacaroonIDs(context.TODO())
|
||||
ids, _ := service.ListMacaroonIDs(ctx)
|
||||
require.Equal(t, expectedIDs, ids, "root key IDs mismatch")
|
||||
}
|
||||
|
||||
|
@ -58,12 +58,13 @@ func openTestStore(t *testing.T, tempDir string) *macaroons.RootKeyStorage {
|
||||
// TestStore tests the normal use cases of the store like creating, unlocking,
|
||||
// reading keys and closing it.
|
||||
func TestStore(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tempDir, store := newTestStore(t)
|
||||
|
||||
_, _, err := store.RootKey(context.TODO())
|
||||
_, _, err := store.RootKey(ctx)
|
||||
require.Equal(t, macaroons.ErrStoreLocked, err)
|
||||
|
||||
_, err = store.Get(context.TODO(), nil)
|
||||
_, err = store.Get(ctx, nil)
|
||||
require.Equal(t, macaroons.ErrStoreLocked, err)
|
||||
|
||||
pw := []byte("weks")
|
||||
@ -72,18 +73,18 @@ func TestStore(t *testing.T) {
|
||||
|
||||
// Check ErrContextRootKeyID is returned when no root key ID found in
|
||||
// context.
|
||||
_, _, err = store.RootKey(context.TODO())
|
||||
_, _, err = store.RootKey(ctx)
|
||||
require.Equal(t, macaroons.ErrContextRootKeyID, err)
|
||||
|
||||
// Check ErrMissingRootKeyID is returned when empty root key ID is used.
|
||||
emptyKeyID := make([]byte, 0)
|
||||
badCtx := macaroons.ContextWithRootKeyID(context.TODO(), emptyKeyID)
|
||||
badCtx := macaroons.ContextWithRootKeyID(ctx, emptyKeyID)
|
||||
_, _, err = store.RootKey(badCtx)
|
||||
require.Equal(t, macaroons.ErrMissingRootKeyID, err)
|
||||
|
||||
// Create a context with illegal root key ID value.
|
||||
encryptedKeyID := []byte("enckey")
|
||||
badCtx = macaroons.ContextWithRootKeyID(context.TODO(), encryptedKeyID)
|
||||
badCtx = macaroons.ContextWithRootKeyID(ctx, encryptedKeyID)
|
||||
_, _, err = store.RootKey(badCtx)
|
||||
require.Equal(t, macaroons.ErrKeyValueForbidden, err)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user