go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit b616752bedfae63a9fd5ae23de0328fe5960b9f2
parent 48d610aa4014389343bde4932bee97f6dfb6fe46
Author: lash <dev@holbrook.no>
Date:   Thu, 12 Sep 2024 19:46:37 +0100

Achieve >80% coverage on resource/db.go

Diffstat:
Mresource/db_test.go | 42++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+), 0 deletions(-)

diff --git a/resource/db_test.go b/resource/db_test.go @@ -92,3 +92,45 @@ func TestDb(t *testing.T) { rs.WithMenuGetter(tg.GetMenu) } + +func TestDbGetterDirect(t *testing.T) { + ctx := context.Background() + store := mem.NewMemDb() + store.Connect(ctx, "") + tg := NewDbResource(store) + + store.SetLock(db.DATATYPE_MENU, false) + store.SetPrefix(db.DATATYPE_MENU) + err := store.Put(ctx, []byte("foo"), []byte("bar")) + if err != nil { + t.Fatal(err) + } + store.SetLock(db.DATATYPE_MENU, true) + v, err := tg.GetMenu(ctx, "foo") + if err != nil { + t.Fatal(err) + } + if v != "foo" { + t.Fatalf("expected 'foo', got '%s'", v) + } + + tg.With(db.DATATYPE_STATICLOAD) + store.SetLock(db.DATATYPE_STATICLOAD, false) + store.SetPrefix(db.DATATYPE_STATICLOAD) + err = store.Put(ctx, []byte("inky.txt"), []byte("blinky")) + if err != nil { + t.Fatal(err) + } + store.SetLock(db.DATATYPE_STATICLOAD, true) + fn, err := tg.DbFuncFor(ctx, "inky") + if err != nil { + t.Fatal(err) + } + r, err := fn(ctx, "", nil) +if err != nil { + t.Fatal(err) + } + if r.Content != "blinky" { + t.Fatalf("expected 'foo', got '%s'", v) + } +}