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

Unified Diff: client/logdog/butlerlib/streamclient/stream_test.go

Issue 1429993002: LogDog: Add Butler stream server package. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-butlerproto
Patch Set: Bind POSIX test to POSIX domains. 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/logdog/butlerlib/streamclient/stream.go ('k') | client/logdog/butlerlib/streamproto/magic.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/logdog/butlerlib/streamclient/stream_test.go
diff --git a/client/logdog/butlerlib/streamclient/stream_test.go b/client/logdog/butlerlib/streamclient/stream_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..1d174fc50b78a92143ad4693caa77a8a7ff9e734
--- /dev/null
+++ b/client/logdog/butlerlib/streamclient/stream_test.go
@@ -0,0 +1,63 @@
+// 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 streamclient
+
+import (
+ "bytes"
+ "io"
+ "testing"
+
+ "github.com/luci/luci-go/client/logdog/butlerlib/streamproto"
+ "github.com/luci/luci-go/common/logdog/protocol"
+ "github.com/luci/luci-go/common/recordio"
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestStreamImpl(t *testing.T) {
+ Convey(`A stream writing to a buffer`, t, func() {
+ buf := bytes.Buffer{}
+ si := &streamImpl{
+ Properties: &streamproto.Properties{},
+ WriteCloser: &nopWriteCloser{Writer: &buf},
+ }
+ Convey(`TEXT`, func() {
+ si.Properties.StreamType = protocol.LogStreamDescriptor_TEXT
+
+ Convey(`Will error if WriteDatagram is called.`, func() {
+ So(si.WriteDatagram([]byte(nil)), ShouldNotBeNil)
+ })
+
+ Convey(`Can invoke Write.`, func() {
+ amt, err := si.Write([]byte{0xd0, 0x65})
+ So(err, ShouldBeNil)
+ So(amt, ShouldEqual, 2)
+ So(buf.Bytes(), ShouldResemble, []byte{0xd0, 0x65})
+ })
+ })
+
+ Convey(`DATAGRAM`, func() {
+ si.Properties.StreamType = protocol.LogStreamDescriptor_DATAGRAM
+
+ Convey(`Will error if Write is called.`, func() {
+ _, err := si.Write([]byte(nil))
+ So(err, ShouldNotBeNil)
+ })
+
+ Convey(`Can invoke WriteDatagram.`, func() {
+ fbuf := bytes.Buffer{}
+ recordio.WriteFrame(&fbuf, []byte{0xd0, 0x65})
+
+ So(si.WriteDatagram([]byte{0xd0, 0x65}), ShouldBeNil)
+ So(buf.Bytes(), ShouldResemble, fbuf.Bytes())
+ })
+ })
+ })
+}
+
+type nopWriteCloser struct {
+ io.Writer
+}
+
+func (nwc *nopWriteCloser) Close() error { return nil }
« no previous file with comments | « client/logdog/butlerlib/streamclient/stream.go ('k') | client/logdog/butlerlib/streamproto/magic.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698