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

Unified Diff: common/chunkstream/chunk_test.go

Issue 1413923013: Add `chunk` segmented data library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Use errors in pacnic. 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 | « common/chunkstream/chunkNode.go ('k') | common/chunkstream/view.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/chunkstream/chunk_test.go
diff --git a/common/chunkstream/chunk_test.go b/common/chunkstream/chunk_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..a0e2cacc548c96fe44ca7e4ac0837b8e6bf84b89
--- /dev/null
+++ b/common/chunkstream/chunk_test.go
@@ -0,0 +1,69 @@
+// 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 chunkstream
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+type testChunk struct {
+ data []byte
+ released bool
+}
+
+var _ Chunk = (*testChunk)(nil)
+
+func tc(d ...byte) *testChunk {
+ return &testChunk{
+ data: d,
+ }
+}
+
+func (c *testChunk) String() string {
+ pieces := make([]string, len(c.data))
+ for i, d := range c.data {
+ pieces[i] = fmt.Sprintf("0x%02x", d)
+ }
+ return fmt.Sprintf("{%s}", strings.Join(pieces, ", "))
+}
+
+func (c *testChunk) Bytes() []byte {
+ return c.data
+}
+
+func (c *testChunk) Len() int {
+ return len(c.data)
+}
+
+func (c *testChunk) Release() {
+ if c.released {
+ panic("double-free")
+ }
+ c.released = true
+}
+
+func TestChunkNode(t *testing.T) {
+ Convey(`A chunkNode wrapping a testing Chunk implementation`, t, func() {
+ c := tc(0, 1, 2)
+ n := newChunkNode(c)
+
+ Convey(`Should call Chunk methods.`, func() {
+ So(n.Bytes(), ShouldResemble, []byte{0, 1, 2})
+ })
+
+ Convey(`When released, releases the wrapped Chunk.`, func() {
+ n.release()
+ So(c.released, ShouldBeTrue)
+
+ Convey(`If released again, panics.`, func() {
+ So(func() { n.release() }, ShouldPanic)
+ })
+ })
+ })
+}
« no previous file with comments | « common/chunkstream/chunkNode.go ('k') | common/chunkstream/view.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698