| 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 bundler | 
 |    6  | 
 |    7 import ( | 
 |    8         "testing" | 
 |    9         "time" | 
 |   10  | 
 |   11         "github.com/luci/luci-go/common/logdog/protocol" | 
 |   12         . "github.com/smartystreets/goconvey/convey" | 
 |   13 ) | 
 |   14  | 
 |   15 func TestBinaryParser(t *testing.T) { | 
 |   16         Convey(`A binaryParser with a threshold of 2.`, t, func() { | 
 |   17                 s := &parserTestStream{ | 
 |   18                         now:         time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC)
     , | 
 |   19                         prefixIndex: 1337, | 
 |   20                 } | 
 |   21                 p := &binaryParser{ | 
 |   22                         baseParser: s.base(), | 
 |   23                         threshold:  2, | 
 |   24                 } | 
 |   25                 c := &constraints{ | 
 |   26                         limit: 32, | 
 |   27                 } | 
 |   28  | 
 |   29                 Convey(`Loaded with data below the threshold`, func() { | 
 |   30                         p.Append(data(s.now, 1)) | 
 |   31                         Convey(`Returns nil when reading data smaller than the t
     hresold.`, func() { | 
 |   32                                 le, err := p.nextEntry(c) | 
 |   33                                 So(err, ShouldBeNil) | 
 |   34                                 So(le, ShouldBeNil) | 
 |   35                         }) | 
 |   36  | 
 |   37                         Convey(`Returns a LogEntry when truncating.`, func() { | 
 |   38                                 c.truncate = true | 
 |   39                                 le, err := p.nextEntry(c) | 
 |   40                                 So(err, ShouldBeNil) | 
 |   41                                 So(le, shouldMatchLogEntry, s.le(0, protocol.Bin
     ary{ | 
 |   42                                         Data: []byte{1}, | 
 |   43                                 })) | 
 |   44  | 
 |   45                                 le, err = p.nextEntry(c) | 
 |   46                                 So(err, ShouldBeNil) | 
 |   47                                 So(le, ShouldBeNil) | 
 |   48                         }) | 
 |   49                 }) | 
 |   50  | 
 |   51                 Convey(`Loaded with 10 bytes of data`, func() { | 
 |   52                         p.Append(data(s.now, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) | 
 |   53  | 
 |   54                         Convey(`Should yield all data with a limit of 32.`, func
     () { | 
 |   55                                 le, err := p.nextEntry(c) | 
 |   56                                 So(err, ShouldBeNil) | 
 |   57                                 So(le, shouldMatchLogEntry, s.le(0, protocol.Bin
     ary{ | 
 |   58                                         Data: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 
     9}, | 
 |   59                                 })) | 
 |   60  | 
 |   61                                 le, err = p.nextEntry(c) | 
 |   62                                 So(err, ShouldBeNil) | 
 |   63                                 So(le, ShouldBeNil) | 
 |   64                         }) | 
 |   65  | 
 |   66                         Convey(`Should yield [0..5], [6..9] with a limit of 6.`,
      func() { | 
 |   67                                 c.limit = 6 | 
 |   68                                 le, err := p.nextEntry(c) | 
 |   69                                 So(err, ShouldBeNil) | 
 |   70                                 So(le, shouldMatchLogEntry, s.le(0, protocol.Bin
     ary{ | 
 |   71                                         Data: []byte{0, 1, 2, 3, 4, 5}, | 
 |   72                                 })) | 
 |   73  | 
 |   74                                 le, err = p.nextEntry(c) | 
 |   75                                 So(err, ShouldBeNil) | 
 |   76                                 So(le, shouldMatchLogEntry, s.le(6, protocol.Bin
     ary{ | 
 |   77                                         Offset: 6, | 
 |   78                                         Data:   []byte{6, 7, 8, 9}, | 
 |   79                                 })) | 
 |   80  | 
 |   81                                 le, err = p.nextEntry(c) | 
 |   82                                 So(err, ShouldBeNil) | 
 |   83                                 So(le, ShouldBeNil) | 
 |   84                         }) | 
 |   85                 }) | 
 |   86  | 
 |   87                 Convey(`Loaded with 8 bytes of data from different times.`, func
     () { | 
 |   88                         for i := 0; i < 8; i++ { | 
 |   89                                 p.Append(data(s.now.Add(time.Duration(i)*time.Se
     cond), byte(i))) | 
 |   90                         } | 
 |   91  | 
 |   92                         Convey(`Ignores the time boundary and returns all 8 byte
     s.`, func() { | 
 |   93                                 le, err := p.nextEntry(c) | 
 |   94                                 So(err, ShouldBeNil) | 
 |   95                                 So(le, shouldMatchLogEntry, s.le(0, protocol.Bin
     ary{ | 
 |   96                                         Data: []byte{0, 1, 2, 3, 4, 5, 6, 7}, | 
 |   97                                 })) | 
 |   98  | 
 |   99                                 le, err = p.nextEntry(c) | 
 |  100                                 So(err, ShouldBeNil) | 
 |  101                                 So(le, ShouldBeNil) | 
 |  102                         }) | 
 |  103                 }) | 
 |  104         }) | 
 |  105 } | 
| OLD | NEW |