lnd.xprv/channeldb/db_test.go
2017-06-17 01:00:07 +02:00

36 lines
806 B
Go

package channeldb
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestOpenWithCreate(t *testing.T) {
t.Parallel()
// First, create a temporary directory to be used for the duration of
// this test.
tempDirName, err := ioutil.TempDir("", "channeldb")
if err != nil {
t.Fatalf("unable to create temp dir: %v", err)
}
defer os.RemoveAll(tempDirName)
// Next, open thereby creating channeldb for the first time.
dbPath := filepath.Join(tempDirName, "cdb")
cdb, err := Open(dbPath)
if err != nil {
t.Fatalf("unable to create channeldb: %v", err)
}
if err := cdb.Close(); err != nil {
t.Fatalf("unable to close channeldb: %v", err)
}
// The path should have been succesfully created.
if !fileExists(dbPath) {
t.Fatalf("channeldb failed to create data directory")
}
}