channeldb: switch to Open/Create methods rather than New
Commit includes basic tests for Open/Create. Additionally, rather than relying on btcwallet’s addmgr for encryption/decryption, this package now exposes a simple crypto system interface.
This commit is contained in:
1 parent
3faa2c2ef5
commit
631e76519e
3 files changed
+135
-36
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package channeldb
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOpenNotCreated(t *testing.T) {
|
||||
if _, err := Open("path doesn't exist"); err != ErrNoExists {
|
||||
t.Fatalf("channeldb Open should fail due to non-existant dir")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateThenOpen(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, create channeldb for the first time.
|
||||
cdb, err := Create(tempDirName)
|
||||
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)
|
||||
}
|
||||
|
||||
// Open should now succeed as the cdb was created above.
|
||||
cdb, err = Open(tempDirName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channeldb: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user