lnd.xprv/channeldb/db_test.go
Olaoluwa Osuntokun 3f5664b46d channeldb: unify Create/Open into simply Open
Open will now create, and initialize the db if it does not yet exist.
2016-03-24 14:31:46 -07:00

34 lines
786 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")
}
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")
}
}