Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package recordio | |
| 6 | |
| 7 import ( | |
| 8 "bytes" | |
| 9 "fmt" | |
| 10 "testing" | |
| 11 | |
| 12 . "github.com/smartystreets/goconvey/convey" | |
| 13 ) | |
| 14 | |
| 15 func TestFrameHeaderSize(t *testing.T) { | |
| 16 t.Parallel() | |
| 17 | |
| 18 Convey(`Testing FrameHeaderSize`, t, func() { | |
|
nodir
2016/04/19 23:41:16
I believe this test must use binary.PutUvarint
dnj
2016/04/20 00:45:07
I'm not sure what you mean by "must use"? It indir
nodir
2016/04/20 16:42:57
yeah indeed
| |
| 19 prev := -1 | |
| 20 for i := 0; i < 5; i++ { | |
| 21 base := 1 << uint(7*i) | |
| 22 for delta := range []int{-1, 0, 1} { | |
| 23 base += delta | |
| 24 if base <= prev { | |
| 25 continue | |
| 26 } | |
| 27 prev = base | |
| 28 | |
| 29 Convey(fmt.Sprintf(`Is accurate for buffer size %d.`, base), func() { | |
| 30 data := bytes.Repeat([]byte{0x55}, base) | |
| 31 | |
| 32 amt, err := WriteFrame(devNull{}, data) | |
| 33 if err != nil { | |
| 34 panic(err) | |
| 35 } | |
| 36 | |
| 37 So(amt-len(data), ShouldEqual, FrameHead erSize(int64(len(data)))) | |
| 38 }) | |
| 39 } | |
| 40 } | |
| 41 }) | |
| 42 } | |
| 43 | |
| 44 type devNull struct{} | |
|
nodir
2016/04/19 23:41:17
Use ioutil.Discard
dnj
2016/04/20 00:45:07
Done.
| |
| 45 | |
| 46 func (devNull) Write(d []byte) (int, error) { | |
| 47 return len(d), nil | |
| 48 } | |
| OLD | NEW |