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

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

Issue 1412063008: logdog: Add bundler library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Updated from comments. 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
« no previous file with comments | « client/internal/logdog/butler/bundler/parser.go ('k') | client/internal/logdog/butler/bundler/sizer.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/internal/logdog/butler/bundler/parser_test.go
diff --git a/client/internal/logdog/butler/bundler/parser_test.go b/client/internal/logdog/butler/bundler/parser_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..bf63ee39482dbef5bbae50189c574264b170b5cf
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/parser_test.go
@@ -0,0 +1,102 @@
+// 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 (
+ "fmt"
+ "time"
+
+ "github.com/luci/luci-go/common/logdog/protocol"
+ "github.com/luci/luci-go/common/proto/google"
+ "github.com/luci/luci-go/common/testing/assertions"
+)
+
+type testData struct {
+ Data
+ released bool
+}
+
+func (d *testData) Release() {
+ d.released = true
+}
+
+func data(ts time.Time, b ...byte) *testData {
+ return &testData{
+ Data: &streamData{
+ buffer: b,
+ bufferBase: b,
+ ts: ts,
+ },
+ }
+}
+
+func dstr(ts time.Time, s string) *testData {
+ return data(ts, []byte(s)...)
+}
+
+func shouldMatchLogEntry(actual interface{}, expected ...interface{}) string {
+ if actual == (*protocol.LogEntry)(nil) {
+ return fmt.Sprintf("actual should not be nil")
+ }
+ if len(expected) != 1 || expected[0] == (*protocol.LogEntry)(nil) {
+ return fmt.Sprintf("expected should not be nil")
+ }
+
+ return assertions.ShouldResembleV(actual, expected[0])
+}
+
+type parserTestStream struct {
+ now time.Time
+ prefixIndex int64
+ streamIndex int64
+ offset time.Duration
+ sequence int64
+}
+
+func (s *parserTestStream) base() baseParser {
+ return baseParser{
+ counter: &counter{
+ current: s.prefixIndex,
+ },
+ timeBase: s.now,
+ }
+}
+
+func (s *parserTestStream) next(d interface{}) *protocol.LogEntry {
+ le := &protocol.LogEntry{
+ TimeOffset: google.NewDuration(s.offset),
+ PrefixIndex: uint64(s.prefixIndex),
+ StreamIndex: uint64(s.streamIndex),
+ }
+
+ switch t := d.(type) {
+ case protocol.Text:
+ le.Content = &protocol.LogEntry_Text{Text: &t}
+
+ case protocol.Binary:
+ le.Content = &protocol.LogEntry_Binary{Binary: &t}
+
+ case protocol.Datagram:
+ le.Content = &protocol.LogEntry_Datagram{Datagram: &t}
+
+ default:
+ panic(fmt.Errorf("unknown content type: %T", t))
+ }
+
+ s.prefixIndex++
+ s.streamIndex++
+ return le
+}
+
+func (s *parserTestStream) add(d time.Duration) *parserTestStream {
+ s.offset += d
+ return s
+}
+
+func (s *parserTestStream) le(seq int64, d interface{}) *protocol.LogEntry {
+ le := s.next(d)
+ le.Sequence = uint64(seq)
+ return le
+}
« no previous file with comments | « client/internal/logdog/butler/bundler/parser.go ('k') | client/internal/logdog/butler/bundler/sizer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698