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

Unified Diff: client/internal/logdog/butler/bundler/data_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
Index: client/internal/logdog/butler/bundler/data_test.go
diff --git a/client/internal/logdog/butler/bundler/data_test.go b/client/internal/logdog/butler/bundler/data_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..3e7686553c6211dd8110447742848a5e88b42311
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/data_test.go
@@ -0,0 +1,56 @@
+// 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/smartystreets/goconvey/convey"
+)
+
+func TestDataPool(t *testing.T) {
+ Convey(`A data pool registry`, t, func() {
+ reg := dataPoolRegistry{}
+
+ Convey(`Can retrieve a 1024-byte data pool.`, func() {
+ pool := reg.getPool(1024)
+ So(pool.size, ShouldEqual, 1024)
+
+ Convey(`Subsequent requests return the same pool.`, func() {
+ So(reg.getPool(1024), ShouldEqual, pool)
+ })
+ })
+ })
+}
+
+func TestData(t *testing.T) {
+ Convey(`A 512-byte data pool`, t, func() {
+ pool := (&dataPoolRegistry{}).getPool(512)
+
+ Convey(`Will allocate a clean 512-byte Data`, func() {
+ d := pool.getData().(*streamData)
+ defer d.Release()
+
+ So(d, ShouldNotBeNil)
+ So(len(d.Bytes()), ShouldEqual, 512)
+ So(cap(d.Bytes()), ShouldEqual, 512)
+
+ Convey(`When bound, adjusts its byte size and retains a timestamp.`, func() {
+ now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC)
+ data := [64]byte{}
+ for i := range data {
+ data[i] = byte(i)
+ }
+
+ copy(d.Bytes(), data[:])
+ So(d.Bind(len(data), now), ShouldEqual, d)
+ So(d.Bytes(), ShouldResemble, data[:])
+ So(d.Len(), ShouldEqual, len(data))
+ So(d.Timestamp().Equal(now), ShouldBeTrue)
+ })
+ })
+ })
+}
« no previous file with comments | « client/internal/logdog/butler/bundler/data.go ('k') | client/internal/logdog/butler/bundler/datagramParser.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698