MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / tryShrink

Function tryShrink

cmd/cql-fuse/block_test.go:373–408  ·  view source on GitHub ↗
(db *sql.DB, data []byte, id, newSize uint64)

Source from the content-addressed store, hash-verified

371}
372
373func tryShrink(db *sql.DB, data []byte, id, newSize uint64) ([]byte, error) {
374 originalSize := uint64(len(data))
375 data = data[:newSize]
376 if err := shrink(db, id, originalSize, newSize); err != nil {
377 return nil, err
378 }
379 newData, err := getAllBlocks(db, id)
380 if err != nil {
381 return nil, err
382 }
383 if uint64(len(newData)) != newSize {
384 return nil, fmt.Errorf("getAllData lengths don't match: got %d, expected %d", len(newData), newSize)
385 }
386 if !bytes.Equal(data, newData) {
387 return nil, fmt.Errorf("getAllData data doesn't match")
388 }
389
390 if newSize == 0 {
391 return newData, nil
392 }
393
394 // Check the read as well.
395 newData, err = read(db, id, 0, newSize)
396 if err != nil {
397 return nil, err
398 }
399
400 if uint64(len(newData)) != newSize {
401 return nil, fmt.Errorf("read lengths don't match: got %d, expected %d", len(newData), newSize)
402 }
403 if !bytes.Equal(data, newData) {
404 return nil, fmt.Errorf("read data doesn't match")
405 }
406
407 return newData, nil
408}
409
410func TestShrinkGrow(t *testing.T) {
411

Callers 1

TestShrinkGrowFunction · 0.85

Calls 4

shrinkFunction · 0.85
getAllBlocksFunction · 0.85
readFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected