lnd.xprv/channeldb/kvdb/kvdb_etcd.go
Andras Banki-Horvath 6757e14998
etcd: refactors to simplify etcd configuration
This refactor removes a redundancy where we had etcd configuration under
kvdb and kvdb/etcd packages.
2021-05-04 17:33:04 +02:00

45 lines
1.0 KiB
Go

// +build kvdb_etcd
package kvdb
import (
"context"
"github.com/lightningnetwork/lnd/channeldb/kvdb/etcd"
)
// TestBackend is conditionally set to etcd when the kvdb_etcd build tag is
// defined, allowing testing our database code with etcd backend.
const TestBackend = EtcdBackendName
// GetEtcdBackend returns an etcd backend configured according to the
// passed etcdConfig.
func GetEtcdBackend(ctx context.Context, etcdConfig *etcd.Config) (
Backend, error) {
return Open(EtcdBackendName, etcdConfig)
}
// GetEtcdTestBackend creates an embedded etcd backend for testing
// storig the database at the passed path.
func GetEtcdTestBackend(path string, clientPort, peerPort uint16) (
Backend, func(), error) {
empty := func() {}
config, cleanup, err := etcd.NewEmbeddedEtcdInstance(
path, clientPort, peerPort,
)
if err != nil {
return nil, empty, err
}
backend, err := Open(EtcdBackendName, context.Background(), config)
if err != nil {
cleanup()
return nil, empty, err
}
return backend, cleanup, nil
}