replace Redis with an embedded SQLite string->string KV store (group commit, in-tx events, SQL search)
Build and Push Docker Image / build (push) Successful in 2m44s
Build and Push Docker Image / build (push) Successful in 2m44s
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/metazla/meta-core/internal/kv"
|
||||
)
|
||||
|
||||
func TestRebuildDerivesTypesFromTheStore(t *testing.T) {
|
||||
store, err := kv.Open(filepath.Join(t.TempDir(), "kv.db"), kv.Options{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if err := store.Update(context.Background(), func(tx *kv.Tx) error {
|
||||
for k, v := range map[string]string{
|
||||
"file:A/sizeByte": "100",
|
||||
"file:B/sizeByte": "200",
|
||||
"file:A/title/eng": "One",
|
||||
"file:B/title/fre": "Deux",
|
||||
"file:A/mixed": "1",
|
||||
"file:B/mixed": "x",
|
||||
"cid:bafknotrecord": "A",
|
||||
} {
|
||||
if err := tx.Put(k, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ix := NewIndexer(store)
|
||||
if got := ix.Snapshot(); got.Source != "pending" || len(got.Fields) != 0 {
|
||||
t.Fatalf("before a scan: %+v", got)
|
||||
}
|
||||
snap, err := ix.Rebuild(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f := snap.Fields["sizeByte"]; f == nil || f.Type != PrimInt || f.Breakdown["int"] != 2 {
|
||||
t.Fatalf("sizeByte = %+v", f)
|
||||
}
|
||||
if f := snap.Fields["title"]; f == nil || f.KeyHint != KeyHintLanguageCode {
|
||||
t.Fatalf("title = %+v (want language-keyed)", f)
|
||||
}
|
||||
if f := snap.Fields["mixed"]; f == nil || f.Type != PrimMixed {
|
||||
t.Fatalf("mixed = %+v", f)
|
||||
}
|
||||
if len(snap.Fields) != 3 {
|
||||
t.Fatalf("fields = %v (non-record keys must not count)", snap.Fields)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user