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) {
|
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)
|
|
|
|
}
|
|
|
|
|
2016-03-25 00:31:46 +03:00
|
|
|
// The path should have been succesfully created.
|
|
|
|
if !fileExists(dbPath) {
|
|
|
|
t.Fatalf("channeldb failed to create data directory")
|
2016-03-24 08:11:57 +03:00
|
|
|
}
|
|
|
|
}
|