commit ad0d00dbc2d8ddb8bb1946fc95c38cad1dcd3317
parent ad80e6e1a19fee0fbd4601ae41c93a5b6f54a252
Author: lash <dev@holbrook.no>
Date: Sun, 1 Sep 2024 19:47:16 +0100
Mem, Fs, Gdbm tests pass test vectors
Diffstat:
4 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/db/db_test.go b/db/db_test.go
@@ -261,27 +261,20 @@ func runTest(t *testing.T, ctx context.Context, db Db, vs testVector) error {
if i == -1 {
break
}
- ts := dataTypeDebug[tc.Typ()]
- s := fmt.Sprintf("Test%s[%d]Type%sKey%s", vs.label(), i, ts, tc.Key())
- if tc.Session() != "" {
- s += "Session" + tc.Session()
- } else {
- s += "NoSession"
- }
- if tc.Lang() != "" {
- ln, err := lang.LanguageFromCode(tc.Lang())
- if err != nil {
- return err
- }
- s += "Lang" + ln.Code
- db.SetLanguage(&ln)
- } else {
- s += "DefaultLang"
- db.SetLanguage(nil)
- }
+ s := fmt.Sprintf("Test%s[%d]%s", vs.label(), i, tc.Label())
r := t.Run(s, func(t *testing.T) {
db.SetPrefix(tc.Typ())
db.SetSession(tc.Session())
+ if tc.Lang() != "" {
+ ln, err := lang.LanguageFromCode(tc.Lang())
+ if err != nil {
+ t.Fatal(err)
+ }
+ db.SetLanguage(&ln)
+ } else {
+ db.SetLanguage(nil)
+ }
+ db.SetSession(tc.Session())
v, err := db.Get(ctx, tc.Key())
if err != nil {
t.Fatal(err)
diff --git a/db/fs.go b/db/fs.go
@@ -94,11 +94,13 @@ func(fdb *fsDb) Put(ctx context.Context, key []byte, val []byte) error {
if err != nil {
return err
}
+ logg.TraceCtxf(ctx, "fs put", "key", key, "lk", lk, "flk", flk, "val", val)
if flk.Translation != "" {
err = ioutil.WriteFile(flk.Translation, val, 0600)
if err != nil {
return err
}
+ return nil
}
return ioutil.WriteFile(flk.Default, val, 0600)
}
diff --git a/db/gdbm.go b/db/gdbm.go
@@ -54,6 +54,7 @@ func(gdb *gdbmDb) Put(ctx context.Context, key []byte, val []byte) error {
if err != nil {
return err
}
+ logg.TraceCtxf(ctx, "gdbm put", "key", key, "lk", lk, "val", val)
if lk.Translation != nil {
return gdb.conn.Store(lk.Translation, val, true)
}
@@ -74,6 +75,7 @@ func(gdb *gdbmDb) Get(ctx context.Context, key []byte) ([]byte, error) {
return nil, err
}
}
+ return v, nil
}
v, err = gdb.conn.Fetch(lk.Default)
if err != nil {
diff --git a/db/mem.go b/db/mem.go
@@ -85,7 +85,7 @@ func(mdb *memDb) Put(ctx context.Context, key []byte, val []byte) error {
k = mk.Default
}
mdb.store[k] = val
- logg.TraceCtxf(ctx, "mem put", "k", k, "v", val)
+ logg.TraceCtxf(ctx, "mem put", "k", k, "mk", mk, "v", val)
return nil
}