From bc5e0fa68f0aa4d73e3a8c82636816af92dca001 Mon Sep 17 00:00:00 2001 From: Chapuis Bertil Date: Tue, 18 Aug 2015 17:57:06 +0200 Subject: [PATCH] test the reader obtained with GetReader() --- backend/backend_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/backend_test.go b/backend/backend_test.go index 8d9c8e18e..0ff5f01b4 100644 --- a/backend/backend_test.go +++ b/backend/backend_test.go @@ -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)