mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-28 05:42:37 +02:00
kvdb: unify how the db backend for tests is set
This commit is contained in:
committed by
Elle Mouton
parent
170160f28a
commit
3d91bb65f7
@@ -247,12 +247,17 @@ func updateLastCompactionDate(dbFile string) error {
|
|||||||
func GetTestBackend(path, name string) (Backend, func(), error) {
|
func GetTestBackend(path, name string) (Backend, func(), error) {
|
||||||
empty := func() {}
|
empty := func() {}
|
||||||
|
|
||||||
|
// Note that for tests, we expect only one db backend build flag
|
||||||
|
// (or none) to be set at a time and thus one of the following switch
|
||||||
|
// cases should ever be true
|
||||||
switch {
|
switch {
|
||||||
case PostgresBackend:
|
case PostgresBackend:
|
||||||
key := filepath.Join(path, name)
|
key := filepath.Join(path, name)
|
||||||
keyHash := sha256.Sum256([]byte(key))
|
keyHash := sha256.Sum256([]byte(key))
|
||||||
|
|
||||||
f, err := NewPostgresFixture("test_" + hex.EncodeToString(keyHash[:]))
|
f, err := NewPostgresFixture("test_" + hex.EncodeToString(
|
||||||
|
keyHash[:]),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, func() {}, err
|
return nil, func() {}, err
|
||||||
}
|
}
|
||||||
@@ -260,7 +265,17 @@ func GetTestBackend(path, name string) (Backend, func(), error) {
|
|||||||
_ = f.DB().Close()
|
_ = f.DB().Close()
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
case TestBackend == BoltBackendName:
|
case EtcdBackend:
|
||||||
|
etcdConfig, cancel, err := StartEtcdTestBackend(path, 0, 0, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, empty, err
|
||||||
|
}
|
||||||
|
backend, err := Open(
|
||||||
|
EtcdBackendName, context.TODO(), etcdConfig,
|
||||||
|
)
|
||||||
|
return backend, cancel, err
|
||||||
|
|
||||||
|
default:
|
||||||
db, err := GetBoltBackend(&BoltBackendConfig{
|
db, err := GetBoltBackend(&BoltBackendConfig{
|
||||||
DBPath: path,
|
DBPath: path,
|
||||||
DBFileName: name,
|
DBFileName: name,
|
||||||
@@ -271,17 +286,6 @@ func GetTestBackend(path, name string) (Backend, func(), error) {
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return db, empty, nil
|
return db, empty, nil
|
||||||
|
|
||||||
case TestBackend == EtcdBackendName:
|
|
||||||
etcdConfig, cancel, err := StartEtcdTestBackend(path, 0, 0, "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, empty, err
|
|
||||||
}
|
|
||||||
backend, err := Open(
|
|
||||||
EtcdBackendName, context.TODO(), etcdConfig,
|
|
||||||
)
|
|
||||||
return backend, cancel, err
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil, fmt.Errorf("unknown backend")
|
return nil, nil, fmt.Errorf("unknown backend")
|
||||||
|
@@ -7,9 +7,9 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/kvdb/etcd"
|
"github.com/lightningnetwork/lnd/kvdb/etcd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestBackend is conditionally set to etcd when the kvdb_etcd build tag is
|
// EtcdBackend is conditionally set to etcd when the kvdb_etcd build tag is
|
||||||
// defined, allowing testing our database code with etcd backend.
|
// defined, allowing testing our database code with etcd backend.
|
||||||
const TestBackend = EtcdBackendName
|
const EtcdBackend = true
|
||||||
|
|
||||||
// GetEtcdTestBackend creates an embedded etcd backend for testing
|
// GetEtcdTestBackend creates an embedded etcd backend for testing
|
||||||
// storig the database at the passed path.
|
// storig the database at the passed path.
|
||||||
|
@@ -9,9 +9,9 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/kvdb/etcd"
|
"github.com/lightningnetwork/lnd/kvdb/etcd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestBackend is conditionally set to bdb when the kvdb_etcd build tag is
|
// EtcdBackend is conditionally set to false when the kvdb_etcd build tag is not
|
||||||
// not defined, allowing testing our database code with bolt backend.
|
// defined. This will allow testing of other database backends.
|
||||||
const TestBackend = BoltBackendName
|
const EtcdBackend = false
|
||||||
|
|
||||||
var errEtcdNotAvailable = fmt.Errorf("etcd backend not available")
|
var errEtcdNotAvailable = fmt.Errorf("etcd backend not available")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user