2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

Merge pull request #267 from bchapuis/fix-254

test the GetReader() function
This commit is contained in:
Alexander Neumann 2015-08-18 22:48:33 +02:00
commit 9367c57bcc

View File

@ -31,6 +31,10 @@ func testBackend(b backend.Backend, t *testing.T) {
_, err = b.Get(tpe, id.String())
Assert(t, err != nil, "blob data could be extracted before creation")
// try to read not existing blob
_, err = b.GetReader(tpe, id.String(), 0, 1)
Assert(t, err != nil, "blob reader could be obtained before creation")
// try to get string out, should fail
ret, err = b.Test(tpe, id.String())
OK(t, err)
@ -52,6 +56,22 @@ func testBackend(b backend.Backend, t *testing.T) {
OK(t, err)
Assert(t, rd != nil, "Get() returned nil")
// try to read it out again
reader, err := b.GetReader(tpe, test.id, 0, uint(len(test.data)))
OK(t, err)
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)
Equals(t, test.data, string(buf))