Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(898)

Side by Side Diff: common/iotools/countingreader_test.go

Issue 2435883002: LogDog: Fix archival Get/Tail implementations. (Closed)
Patch Set: LogDog: Fix archival Get/Tail implementations. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package iotools 5 package iotools
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "io" 9 "io"
10 "testing" 10 "testing"
(...skipping 27 matching lines...) Expand all
38 func TestCountingReader(t *testing.T) { 38 func TestCountingReader(t *testing.T) {
39 Convey(`Given a CountingReader backed by a 32-byte not-ByteReader Reader .`, t, func() { 39 Convey(`Given a CountingReader backed by a 32-byte not-ByteReader Reader .`, t, func() {
40 buf := bytes.NewBuffer(bytes.Repeat([]byte{0x55}, 32)) 40 buf := bytes.NewBuffer(bytes.Repeat([]byte{0x55}, 32))
41 tr := &notAByteReader{buf} 41 tr := &notAByteReader{buf}
42 cr := CountingReader{Reader: tr} 42 cr := CountingReader{Reader: tr}
43 43
44 Convey(`When reading 10 bytes of data, registers a count of 10.` , func() { 44 Convey(`When reading 10 bytes of data, registers a count of 10.` , func() {
45 amount, err := cr.Read(make([]byte, 10)) 45 amount, err := cr.Read(make([]byte, 10))
46 So(err, ShouldBeNil) 46 So(err, ShouldBeNil)
47 So(amount, ShouldEqual, 10) 47 So(amount, ShouldEqual, 10)
48 » » » So(cr.Count(), ShouldEqual, 10) 48 » » » So(cr.Count, ShouldEqual, 10)
49 }) 49 })
50 50
51 Convey(`When using 32 sequential ReadByte, registers a count of 32.`, func() { 51 Convey(`When using 32 sequential ReadByte, registers a count of 32.`, func() {
52 for i := 0; i < 32; i++ { 52 for i := 0; i < 32; i++ {
53 b, err := cr.ReadByte() 53 b, err := cr.ReadByte()
54 So(err, ShouldBeNil) 54 So(err, ShouldBeNil)
55 So(b, ShouldEqual, 0x55) 55 So(b, ShouldEqual, 0x55)
56 » » » » So(cr.Count(), ShouldEqual, i+1) 56 » » » » So(cr.Count, ShouldEqual, i+1)
57 } 57 }
58 58
59 _, err := cr.ReadByte() 59 _, err := cr.ReadByte()
60 So(err, ShouldEqual, io.EOF) 60 So(err, ShouldEqual, io.EOF)
61 }) 61 })
62 62
63 Convey(`ReadByte should return EOF if no more data.`, func() { 63 Convey(`ReadByte should return EOF if no more data.`, func() {
64 buf.Reset() 64 buf.Reset()
65 65
66 b, err := cr.ReadByte() 66 b, err := cr.ReadByte()
67 So(err, ShouldEqual, io.EOF) 67 So(err, ShouldEqual, io.EOF)
68 So(b, ShouldEqual, 0) 68 So(b, ShouldEqual, 0)
69 }) 69 })
70 }) 70 })
71 71
72 Convey(`Given a CountingReader backed by a testByteReader.`, t, func() { 72 Convey(`Given a CountingReader backed by a testByteReader.`, t, func() {
73 tr := testByteReader{ByteReader: bytes.NewBuffer([]byte{0x55})} 73 tr := testByteReader{ByteReader: bytes.NewBuffer([]byte{0x55})}
74 cr := CountingReader{Reader: &tr} 74 cr := CountingReader{Reader: &tr}
75 75
76 Convey(`ReadByte should directly call the backing reader's ReadB yte.`, func() { 76 Convey(`ReadByte should directly call the backing reader's ReadB yte.`, func() {
77 b, err := cr.ReadByte() 77 b, err := cr.ReadByte()
78 So(err, ShouldBeNil) 78 So(err, ShouldBeNil)
79 So(b, ShouldEqual, 0x55) 79 So(b, ShouldEqual, 0x55)
80 » » » So(cr.Count(), ShouldEqual, 1) 80 » » » So(cr.Count, ShouldEqual, 1)
81 So(tr.called, ShouldBeTrue) 81 So(tr.called, ShouldBeTrue)
82 }) 82 })
83 }) 83 })
84 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698