2021-01-04 19:03:32 +00:00
|
|
|
package sqlite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-04-14 18:14:01 +00:00
|
|
|
"github.com/mickael-menu/zk/internal/util/fixtures"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/test/assert"
|
2021-01-04 19:03:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestOpen(t *testing.T) {
|
|
|
|
_, err := Open(fixtures.Path("sample.db"))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClose(t *testing.T) {
|
|
|
|
db, err := Open(fixtures.Path("sample.db"))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = db.Close()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMigrateFrom0(t *testing.T) {
|
|
|
|
db, err := OpenInMemory()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = db.WithTransaction(func(tx Transaction) error {
|
|
|
|
var version int
|
|
|
|
err := tx.QueryRow("PRAGMA user_version").Scan(&version)
|
|
|
|
assert.Nil(t, err)
|
2021-11-14 08:50:13 +00:00
|
|
|
assert.Equal(t, version, 6)
|
2021-01-04 19:03:32 +00:00
|
|
|
|
|
|
|
_, err = tx.Exec(`
|
2021-01-17 16:37:16 +00:00
|
|
|
INSERT INTO notes (path, sortable_path, title, body, word_count, checksum)
|
|
|
|
VALUES ("ref/tx1.md", "reftx1.md", "A reference", "Content", 1, "qwfpg")
|
2021-01-04 19:03:32 +00:00
|
|
|
`)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|