mirror of
https://github.com/mickael-menu/zk
synced 2024-11-11 07:10:25 +00:00
50855154e2
* Move everything under the internal package. * Better separation between core and adapter packages, for easier unit testing. * Simplify data models. * Support multiple opened notebooks during runtime (useful for the LSP server). * Proper surface API which might be exposed later as a public Go package.
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mickael-menu/zk/internal/util/test/assert"
|
|
)
|
|
|
|
func TestMetadataDAOGetUnknown(t *testing.T) {
|
|
testMetadataDAO(t, func(tx Transaction, dao *MetadataDAO) {
|
|
res, err := dao.Get("unknown")
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, res, "")
|
|
})
|
|
}
|
|
|
|
func TestMetadataDAOGetExisting(t *testing.T) {
|
|
testMetadataDAO(t, func(tx Transaction, dao *MetadataDAO) {
|
|
res, err := dao.Get("a_metadata")
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, res, "value")
|
|
})
|
|
}
|
|
|
|
func TestMetadataDAOSetUnknown(t *testing.T) {
|
|
testMetadataDAO(t, func(tx Transaction, dao *MetadataDAO) {
|
|
res, err := dao.Get("new_metadata")
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, res, "")
|
|
|
|
err = dao.Set("new_metadata", "pamplemousse")
|
|
assert.Nil(t, err)
|
|
|
|
res, err = dao.Get("new_metadata")
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, res, "pamplemousse")
|
|
})
|
|
}
|
|
|
|
func TestMetadataDAOSetExisting(t *testing.T) {
|
|
testMetadataDAO(t, func(tx Transaction, dao *MetadataDAO) {
|
|
err := dao.Set("a_metadata", "new_value")
|
|
assert.Nil(t, err)
|
|
|
|
res, err := dao.Get("a_metadata")
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, res, "new_value")
|
|
})
|
|
}
|
|
|
|
func testMetadataDAO(t *testing.T, callback func(tx Transaction, dao *MetadataDAO)) {
|
|
testTransaction(t, func(tx Transaction) {
|
|
callback(tx, NewMetadataDAO(tx))
|
|
})
|
|
}
|