lnd/channeldb/db_test.go
2017-02-07 16:52:04 -08:00

34 lines
791 B
Go

package channeldb
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestOpenWithCreate(t *testing.T) {
// 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")
}
}