mirror of
https://github.com/restic/restic.git
synced 2024-12-23 16:26:11 +00:00
test the reader obtained with GetReader()
This commit is contained in:
parent
513be4b8ab
commit
bc5e0fa68f
1 changed files with 13 additions and 2 deletions
|
@ -57,9 +57,20 @@ func testBackend(b backend.Backend, t *testing.T) {
|
|||
Assert(t, rd != nil, "Get() returned nil")
|
||||
|
||||
// try to read it out again
|
||||
r, err := b.GetReader(tpe, test.id, 0, uint(len(test.data)))
|
||||
reader, err := b.GetReader(tpe, test.id, 0, uint(len(test.data)))
|
||||
OK(t, err)
|
||||
Assert(t, r != nil, "GetReader() returned nil")
|
||||
Assert(t, reader != nil, "GetReader() returned nil")
|
||||
bytes := make([]byte, len(test.data))
|
||||
reader.Read(bytes)
|
||||
Assert(t, test.data == string(bytes), "Read() returned different content")
|
||||
|
||||
// try to read it out with an offset and a length
|
||||
readerOffLen, err := b.GetReader(tpe, test.id, 1, uint(len(test.data)-2))
|
||||
OK(t, err)
|
||||
Assert(t, readerOffLen != nil, "GetReader() returned nil")
|
||||
bytesOffLen := make([]byte, len(test.data)-2)
|
||||
readerOffLen.Read(bytesOffLen)
|
||||
Assert(t, test.data[1:len(test.data)-1] == string(bytesOffLen), "Read() with offset and length returned different content")
|
||||
|
||||
buf, err := ioutil.ReadAll(rd)
|
||||
OK(t, err)
|
||||
|
|
Loading…
Reference in a new issue