631e76519e
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.
39 lines
910 B
Go
39 lines
910 B
Go
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)
|
|
}
|
|
}
|