mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
fix size bug, add more multi/writeat testing
This commit is contained in:
parent
75d2c48c57
commit
b5f7ff699c
@ -303,7 +303,7 @@ func (s *BlockStore) loadDataParts(ctx context.Context, blockId string, name str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *BlockStore) writeAt_nolock(entry *CacheEntry, offset int64, data []byte) {
|
func (s *BlockStore) writeAt_nolock(entry *CacheEntry, offset int64, data []byte) {
|
||||||
endWrite := entry.FileEntry.File.Size + int64(len(data))
|
endWrite := offset + int64(len(data))
|
||||||
entry.writeAt(offset, data)
|
entry.writeAt(offset, data)
|
||||||
if endWrite > entry.FileEntry.File.Size {
|
if endWrite > entry.FileEntry.File.Size {
|
||||||
entry.FileEntry.File.Size = endWrite
|
entry.FileEntry.File.Size = endWrite
|
||||||
|
@ -6,7 +6,6 @@ package blockstore
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -158,6 +157,17 @@ func checkFileData(t *testing.T, ctx context.Context, blockId string, name strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkFileDataAt(t *testing.T, ctx context.Context, blockId string, name string, offset int64, data string) {
|
||||||
|
_, rdata, err := GBS.ReadAt(ctx, blockId, name, offset, int64(len(data)))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error reading data for file %q: %v", name, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if string(rdata) != data {
|
||||||
|
t.Errorf("data mismatch for file %q: expected %q, got %q", name, data, string(rdata))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAppend(t *testing.T) {
|
func TestAppend(t *testing.T) {
|
||||||
initDb(t)
|
initDb(t)
|
||||||
defer cleanupDb(t)
|
defer cleanupDb(t)
|
||||||
@ -220,5 +230,8 @@ func TestMultiPart(t *testing.T) {
|
|||||||
if string(barr) != data[42:52] {
|
if string(barr) != data[42:52] {
|
||||||
t.Errorf("data mismatch: expected %q, got %q", data[42:52], string(barr))
|
t.Errorf("data mismatch: expected %q, got %q", data[42:52], string(barr))
|
||||||
}
|
}
|
||||||
fmt.Print(GBS.dump())
|
GBS.WriteAt(ctx, blockId, fileName, 49, []byte("world"))
|
||||||
|
checkFileSize(t, ctx, blockId, fileName, 80)
|
||||||
|
checkFileDataAt(t, ctx, blockId, fileName, 49, "world")
|
||||||
|
checkFileDataAt(t, ctx, blockId, fileName, 48, "8world4")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user