zk/internal/adapter/sqlite/metadata_dao_test.go
Mickaël Menu 50855154e2
Architecture (#27)
* 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.
2021-04-14 20:14:01 +02:00

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))
})
}