mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-25 03:34:05 -05:00
Add ReadTableFooter test
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
package nbs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -229,6 +231,39 @@ func TestAmbiguousShortHash(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadTableFooter(t *testing.T) {
|
||||
// Less than 20 bytes is not enough to read the footer
|
||||
reader := bytes.NewReader(make([]byte, 19))
|
||||
_, _, err := ReadTableFooter(reader)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "negative position")
|
||||
|
||||
data := make([]byte, 20)
|
||||
binary.BigEndian.PutUint32(data[:4], 98765) // Chunk Count.
|
||||
binary.BigEndian.PutUint64(data[4:12], 12345) // Total Size
|
||||
copy(data[12:], magicNumber)
|
||||
reader = bytes.NewReader(data)
|
||||
chunkCount, totalSize, err := ReadTableFooter(reader)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, uint32(98765), chunkCount)
|
||||
assert.Equal(t, uint64(12345), totalSize)
|
||||
|
||||
// Now with a future magic number
|
||||
data[12] = 0
|
||||
copy(data[13:], doltMagicNumber)
|
||||
reader = bytes.NewReader(data)
|
||||
_, _, err = ReadTableFooter(reader)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "unsupported table file format")
|
||||
|
||||
// Now with corrupted info that we don't recognize.
|
||||
copy(data[12:], "DEADBEEF")
|
||||
reader = bytes.NewReader(data)
|
||||
_, _, err = ReadTableFooter(reader)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "invalid or corrupt table file")
|
||||
}
|
||||
|
||||
// fakeChunk is chunk with a faked address
|
||||
type fakeChunk struct {
|
||||
address hash.Hash
|
||||
|
||||
Reference in New Issue
Block a user