mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
test writemeta
This commit is contained in:
parent
68a6605209
commit
9bb6e27201
@ -43,6 +43,20 @@ type CacheEntry struct {
|
||||
DataEntries []*DataCacheEntry
|
||||
}
|
||||
|
||||
// for testing
|
||||
func (s *BlockStore) getCacheSize() int {
|
||||
s.Lock.Lock()
|
||||
defer s.Lock.Unlock()
|
||||
return len(s.Cache)
|
||||
}
|
||||
|
||||
// for testing
|
||||
func (s *BlockStore) clearCache() {
|
||||
s.Lock.Lock()
|
||||
defer s.Lock.Unlock()
|
||||
s.Cache = make(map[cacheKey]*CacheEntry)
|
||||
}
|
||||
|
||||
func (e *CacheEntry) ensurePart(partIdx int, create bool) *DataCacheEntry {
|
||||
for len(e.DataEntries) <= partIdx {
|
||||
e.DataEntries = append(e.DataEntries, nil)
|
||||
|
@ -32,6 +32,7 @@ func cleanupDb(t *testing.T) {
|
||||
globalDBErr = nil
|
||||
useTestingDb = false
|
||||
partDataSize = DefaultPartDataSize
|
||||
GBS.clearCache()
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
@ -77,3 +78,45 @@ func TestCreate(t *testing.T) {
|
||||
t.Fatalf("opts not empty")
|
||||
}
|
||||
}
|
||||
|
||||
func checkMapsEqual(t *testing.T, m1 map[string]any, m2 map[string]any, msg string) {
|
||||
if len(m1) != len(m2) {
|
||||
t.Errorf("%s: map length mismatch", msg)
|
||||
}
|
||||
for k, v := range m1 {
|
||||
if m2[k] != v {
|
||||
t.Errorf("%s: value mismatch for key %q", msg, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetMeta(t *testing.T) {
|
||||
initDb(t)
|
||||
defer cleanupDb(t)
|
||||
|
||||
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancelFn()
|
||||
blockId := uuid.New().String()
|
||||
err := GBS.MakeFile(ctx, blockId, "testfile", nil, FileOptsType{})
|
||||
if err != nil {
|
||||
t.Fatalf("error creating file: %v", err)
|
||||
}
|
||||
if GBS.getCacheSize() != 0 {
|
||||
t.Errorf("cache size mismatch -- should have 0 entries after create")
|
||||
}
|
||||
err = GBS.WriteMeta(ctx, blockId, "testfile", map[string]any{"a": 5, "b": "hello"})
|
||||
if err != nil {
|
||||
t.Fatalf("error setting meta: %v", err)
|
||||
}
|
||||
file, err := GBS.Stat(ctx, blockId, "testfile")
|
||||
if err != nil {
|
||||
t.Fatalf("error stating file: %v", err)
|
||||
}
|
||||
if file == nil {
|
||||
t.Fatalf("file not found")
|
||||
}
|
||||
checkMapsEqual(t, map[string]any{"a": 5, "b": "hello"}, file.Meta, "meta")
|
||||
if GBS.getCacheSize() != 1 {
|
||||
t.Errorf("cache size mismatch")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user