2016-03-24 08:11:57 +03:00
|
|
|
package channeldb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2016-03-25 00:31:46 +03:00
|
|
|
"path/filepath"
|
2016-03-24 08:11:57 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-03-25 00:31:46 +03:00
|
|
|
func TestOpenWithCreate(t *testing.T) {
|
2017-06-17 01:59:20 +03:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-03-24 08:11:57 +03:00
|
|
|
// First, create a temporary directory to be used for the duration of
|
|
|
|
// this test.
|
|
|
|
tempDirName, err := ioutil.TempDir("", "channeldb")
|
|
|
|
if err != nil {
|
2017-02-08 03:51:58 +03:00
|
|
|
t.Fatalf("unable to create temp dir: %v", err)
|
2016-03-24 08:11:57 +03:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(tempDirName)
|
|
|
|
|
2016-03-25 00:31:46 +03:00
|
|
|
// Next, open thereby creating channeldb for the first time.
|
|
|
|
dbPath := filepath.Join(tempDirName, "cdb")
|
2016-12-22 23:09:19 +03:00
|
|
|
cdb, err := Open(dbPath)
|
2016-03-24 08:11:57 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2018-02-07 06:11:11 +03:00
|
|
|
// The path should have been successfully created.
|
2016-03-25 00:31:46 +03:00
|
|
|
if !fileExists(dbPath) {
|
|
|
|
t.Fatalf("channeldb failed to create data directory")
|
2016-03-24 08:11:57 +03:00
|
|
|
}
|
|
|
|
}
|