channeldb/migtest: remove channeldb dependency

Removes this unnecessary dependency allowing migration code to use
utility functions from channeldb/migtest.
This commit is contained in:
Joost Jager
2020-02-21 14:13:40 +01:00
parent 4c74c0817e
commit c357511051

View File

@@ -7,32 +7,30 @@ import (
"testing" "testing"
"github.com/coreos/bbolt" "github.com/coreos/bbolt"
"github.com/lightningnetwork/lnd/channeldb"
) )
// MakeDB creates a new instance of the ChannelDB for testing purposes. A // MakeDB creates a new instance of the ChannelDB for testing purposes. A
// callback which cleans up the created temporary directories is also returned // callback which cleans up the created temporary directories is also returned
// and intended to be executed after the test completes. // and intended to be executed after the test completes.
func MakeDB() (*channeldb.DB, func(), error) { func MakeDB() (*bbolt.DB, func(), error) {
// First, create a temporary directory to be used for the duration of // Create temporary database for mission control.
// this test. file, err := ioutil.TempFile("", "*.db")
tempDirName, err := ioutil.TempDir("", "channeldb")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
// Next, create channeldb for the first time. dbPath := file.Name()
cdb, err := channeldb.Open(tempDirName) db, err := bbolt.Open(dbPath, 0600, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
cleanUp := func() { cleanUp := func() {
cdb.Close() db.Close()
os.RemoveAll(tempDirName) os.RemoveAll(dbPath)
} }
return cdb, cleanUp, nil return db, cleanUp, nil
} }
// ApplyMigration is a helper test function that encapsulates the general steps // ApplyMigration is a helper test function that encapsulates the general steps