status-protocol-go/sqlite/db_test.go

36 lines
812 B
Go
Raw Normal View History

2019-07-16 10:43:07 +00:00
package sqlite
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestOpen(t *testing.T) {
dir, err := ioutil.TempDir("", "test-open")
require.NoError(t, err)
defer os.Remove(dir)
dbPath := filepath.Join(dir, "db.sql")
// Open the db for the first time.
2019-08-21 08:31:20 +00:00
db, err := open(dbPath, "some-key", reducedKdfIterationsNumber)
2019-07-16 10:43:07 +00:00
require.NoError(t, err)
// Insert some data.
_, err = db.Exec("CREATE TABLE test(name TEXT)")
require.NoError(t, err)
_, err = db.Exec(`INSERT INTO test (name) VALUES ("abc")`)
require.NoError(t, err)
db.Close()
// Open again with different key should fail
// because the file already exists and it should not
// be recreated.
2019-08-21 08:31:20 +00:00
_, err = open(dbPath, "different-key", reducedKdfIterationsNumber)
require.Error(t, err)
}