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

Unified Diff: client/internal/logdog/butler/bundler/binaryParser_test.go

Issue 1412063008: logdog: Add bundler library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Enhanced doc.go. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: client/internal/logdog/butler/bundler/binaryParser_test.go
diff --git a/client/internal/logdog/butler/bundler/binaryParser_test.go b/client/internal/logdog/butler/bundler/binaryParser_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..426bf3b87e06994212c5c13074dc0a1dfa43f716
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/binaryParser_test.go
@@ -0,0 +1,105 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package bundler
+
+import (
+ "testing"
+ "time"
+
+ "github.com/luci/luci-go/common/logdog/protocol"
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestBinaryParser(t *testing.T) {
+ Convey(`A binaryParser with a threshold of 2.`, t, func() {
+ s := &parserTestStream{
+ now: time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC),
+ prefixIndex: 1337,
+ }
+ p := &binaryParser{
+ baseParser: s.base(),
+ threshold: 2,
+ }
+ c := &constraints{
+ limit: 32,
+ }
+
+ Convey(`Loaded with data below the threshold`, func() {
+ p.Append(data(s.now, 1))
+ Convey(`Returns nil when reading data smaller than the thresold.`, func() {
+ le, err := p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, ShouldBeNil)
+ })
+
+ Convey(`Returns a LogEntry when truncating.`, func() {
+ c.truncate = true
+ le, err := p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, shouldMatchLogEntry, s.le(0, protocol.Binary{
+ Data: []byte{1},
+ }))
+
+ le, err = p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, ShouldBeNil)
+ })
+ })
+
+ Convey(`Loaded with 10 bytes of data`, func() {
+ p.Append(data(s.now, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
+
+ Convey(`Should yield all data with a limit of 32.`, func() {
+ le, err := p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, shouldMatchLogEntry, s.le(0, protocol.Binary{
+ Data: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
+ }))
+
+ le, err = p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, ShouldBeNil)
+ })
+
+ Convey(`Should yield [0..5], [6..9] with a limit of 6.`, func() {
+ c.limit = 6
+ le, err := p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, shouldMatchLogEntry, s.le(0, protocol.Binary{
+ Data: []byte{0, 1, 2, 3, 4, 5},
+ }))
+
+ le, err = p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, shouldMatchLogEntry, s.le(6, protocol.Binary{
+ Offset: 6,
+ Data: []byte{6, 7, 8, 9},
+ }))
+
+ le, err = p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, ShouldBeNil)
+ })
+ })
+
+ Convey(`Loaded with 8 bytes of data from different times.`, func() {
+ for i := 0; i < 8; i++ {
+ p.Append(data(s.now.Add(time.Duration(i)*time.Second), byte(i)))
+ }
+
+ Convey(`Ignores the time boundary and returns all 8 bytes.`, func() {
+ le, err := p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, shouldMatchLogEntry, s.le(0, protocol.Binary{
+ Data: []byte{0, 1, 2, 3, 4, 5, 6, 7},
+ }))
+
+ le, err = p.nextEntry(c)
+ So(err, ShouldBeNil)
+ So(le, ShouldBeNil)
+ })
+ })
+ })
+}

Powered by Google App Engine
This is Rietveld 408576698