From 95c332c71a7280c2f23986e3b72dbabce007672a Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 31 May 2019 13:00:22 +0200 Subject: [PATCH] Update database tests and checks --- database/database_test.go | 6 +++++- database/record/meta.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/database/database_test.go b/database/database_test.go index 462d054..388a25c 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -12,6 +12,8 @@ import ( q "github.com/Safing/portbase/database/query" _ "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 { @@ -102,7 +104,7 @@ func testDatabase(t *testing.T, storageType string) { t.Fatal(it.Err()) } if cnt != 2 { - t.Fatal("expected two records") + t.Fatalf("expected two records, got %d", cnt) } err = hook.Cancel() @@ -142,6 +144,8 @@ func TestDatabaseSystem(t *testing.T) { defer os.RemoveAll(testDir) // clean up testDatabase(t, "badger") + testDatabase(t, "bbolt") + testDatabase(t, "fstree") err = MaintainRecordStates() if err != nil { diff --git a/database/record/meta.go b/database/record/meta.go index 4e09c48..23ed287 100644 --- a/database/record/meta.go +++ b/database/record/meta.go @@ -85,6 +85,10 @@ func (m *Meta) IsDeleted() bool { // CheckValidity checks whether the database record is valid. func (m *Meta) CheckValidity() (valid bool) { + if m == nil { + return false + } + switch { case m.Deleted > 0: 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. func (m *Meta) CheckPermission(local, internal bool) (permitted bool) { + if m == nil { + return false + } + switch { case !local && m.cronjewel: return false