forked from TrueCloudLab/restic
pack: slightly expand testing of compressed blobs
This commit is contained in:
parent
ec2b25565a
commit
bcab548617
2 changed files with 49 additions and 9 deletions
|
@ -54,10 +54,18 @@ var plainEntrySize = uint(binary.Size(restic.BlobType(0)) + headerLengthSize + l
|
|||
// headerEntry describes the format of header entries. It serves only as
|
||||
// documentation.
|
||||
type headerEntry struct {
|
||||
Type uint8
|
||||
Length uint32
|
||||
ID restic.ID
|
||||
CompressedLength uint32
|
||||
Type uint8
|
||||
Length uint32
|
||||
ID restic.ID
|
||||
}
|
||||
|
||||
// compressedHeaderEntry describes the format of header entries for compressed blobs.
|
||||
// It serves only as documentation.
|
||||
type compressedHeaderEntry struct {
|
||||
Type uint8
|
||||
Length uint32
|
||||
UncompressedLength uint32
|
||||
ID restic.ID
|
||||
}
|
||||
|
||||
// Finalize writes the header for all added blobs and finalizes the pack.
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
func TestParseHeaderEntry(t *testing.T) {
|
||||
h := headerEntry{
|
||||
Type: 0, // Blob.
|
||||
Type: 0, // Blob
|
||||
Length: 100,
|
||||
}
|
||||
for i := range h.ID {
|
||||
|
@ -28,21 +28,53 @@ func TestParseHeaderEntry(t *testing.T) {
|
|||
rtest.Equals(t, restic.DataBlob, b.Type)
|
||||
rtest.Equals(t, plainEntrySize, size)
|
||||
t.Logf("%v %v", h.ID, b.ID)
|
||||
rtest.Assert(t, bytes.Equal(h.ID[:], b.ID[:]), "id mismatch")
|
||||
rtest.Equals(t, h.ID[:], b.ID[:])
|
||||
rtest.Equals(t, uint(h.Length), b.Length)
|
||||
rtest.Equals(t, uint(0), b.UncompressedLength)
|
||||
|
||||
c := compressedHeaderEntry{
|
||||
Type: 2, // compressed Blob
|
||||
Length: 100,
|
||||
UncompressedLength: 200,
|
||||
}
|
||||
for i := range c.ID {
|
||||
c.ID[i] = byte(i)
|
||||
}
|
||||
|
||||
buf = new(bytes.Buffer)
|
||||
_ = binary.Write(buf, binary.LittleEndian, &c)
|
||||
|
||||
b, size, err = parseHeaderEntry(buf.Bytes())
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, restic.DataBlob, b.Type)
|
||||
rtest.Equals(t, entrySize, size)
|
||||
t.Logf("%v %v", c.ID, b.ID)
|
||||
rtest.Equals(t, c.ID[:], b.ID[:])
|
||||
rtest.Equals(t, uint(c.Length), b.Length)
|
||||
rtest.Equals(t, uint(c.UncompressedLength), b.UncompressedLength)
|
||||
}
|
||||
|
||||
func TestParseHeaderEntryErrors(t *testing.T) {
|
||||
h := headerEntry{
|
||||
Type: 0, // Blob
|
||||
Length: 100,
|
||||
}
|
||||
for i := range h.ID {
|
||||
h.ID[i] = byte(i)
|
||||
}
|
||||
|
||||
h.Type = 0xae
|
||||
buf.Reset()
|
||||
buf := new(bytes.Buffer)
|
||||
_ = binary.Write(buf, binary.LittleEndian, &h)
|
||||
|
||||
b, _, err = parseHeaderEntry(buf.Bytes())
|
||||
_, _, err := parseHeaderEntry(buf.Bytes())
|
||||
rtest.Assert(t, err != nil, "no error for invalid type")
|
||||
|
||||
h.Type = 0
|
||||
buf.Reset()
|
||||
_ = binary.Write(buf, binary.LittleEndian, &h)
|
||||
|
||||
b, _, err = parseHeaderEntry(buf.Bytes()[:plainEntrySize-1])
|
||||
_, _, err = parseHeaderEntry(buf.Bytes()[:plainEntrySize-1])
|
||||
rtest.Assert(t, err != nil, "no error for short input")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue