Update database tests and checks

This commit is contained in:
Daniel 2019-05-31 13:00:22 +02:00
parent 4d1659e2c2
commit 95c332c71a
2 changed files with 13 additions and 1 deletions

View file

@ -12,6 +12,8 @@ import (
q "github.com/Safing/portbase/database/query" q "github.com/Safing/portbase/database/query"
_ "github.com/Safing/portbase/database/storage/badger" _ "github.com/Safing/portbase/database/storage/badger"
_ "github.com/Safing/portbase/database/storage/bbolt"
_ "github.com/Safing/portbase/database/storage/fstree"
) )
func makeKey(dbName, key string) string { func makeKey(dbName, key string) string {
@ -102,7 +104,7 @@ func testDatabase(t *testing.T, storageType string) {
t.Fatal(it.Err()) t.Fatal(it.Err())
} }
if cnt != 2 { if cnt != 2 {
t.Fatal("expected two records") t.Fatalf("expected two records, got %d", cnt)
} }
err = hook.Cancel() err = hook.Cancel()
@ -142,6 +144,8 @@ func TestDatabaseSystem(t *testing.T) {
defer os.RemoveAll(testDir) // clean up defer os.RemoveAll(testDir) // clean up
testDatabase(t, "badger") testDatabase(t, "badger")
testDatabase(t, "bbolt")
testDatabase(t, "fstree")
err = MaintainRecordStates() err = MaintainRecordStates()
if err != nil { if err != nil {

View file

@ -85,6 +85,10 @@ func (m *Meta) IsDeleted() bool {
// CheckValidity checks whether the database record is valid. // CheckValidity checks whether the database record is valid.
func (m *Meta) CheckValidity() (valid bool) { func (m *Meta) CheckValidity() (valid bool) {
if m == nil {
return false
}
switch { switch {
case m.Deleted > 0: case m.Deleted > 0:
return false return false
@ -97,6 +101,10 @@ func (m *Meta) CheckValidity() (valid bool) {
// CheckPermission checks whether the database record may be accessed with the following scope. // CheckPermission checks whether the database record may be accessed with the following scope.
func (m *Meta) CheckPermission(local, internal bool) (permitted bool) { func (m *Meta) CheckPermission(local, internal bool) (permitted bool) {
if m == nil {
return false
}
switch { switch {
case !local && m.cronjewel: case !local && m.cronjewel:
return false return false