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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package streamclient
6
7 import (
8 "bytes"
9 "io"
10 "testing"
11
12 "github.com/luci/luci-go/client/logdog/butlerlib/streamproto"
13 "github.com/luci/luci-go/common/logdog/protocol"
14 "github.com/luci/luci-go/common/recordio"
15 . "github.com/smartystreets/goconvey/convey"
16 )
17
18 func TestStreamImpl(t *testing.T) {
19 Convey(`A stream writing to a buffer`, t, func() {
20 buf := bytes.Buffer{}
21 si := &streamImpl{
22 Properties: &streamproto.Properties{},
23 WriteCloser: &nopWriteCloser{Writer: &buf},
24 }
25 Convey(`TEXT`, func() {
26 si.Properties.StreamType = protocol.LogStreamDescriptor_ TEXT
27
28 Convey(`Will error if WriteDatagram is called.`, func() {
29 So(si.WriteDatagram([]byte(nil)), ShouldNotBeNil )
30 })
31
32 Convey(`Can invoke Write.`, func() {
33 amt, err := si.Write([]byte{0xd0, 0x65})
34 So(err, ShouldBeNil)
35 So(amt, ShouldEqual, 2)
36 So(buf.Bytes(), ShouldResemble, []byte{0xd0, 0x6 5})
37 })
38 })
39
40 Convey(`DATAGRAM`, func() {
41 si.Properties.StreamType = protocol.LogStreamDescriptor_ DATAGRAM
42
43 Convey(`Will error if Write is called.`, func() {
44 _, err := si.Write([]byte(nil))
45 So(err, ShouldNotBeNil)
46 })
47
48 Convey(`Can invoke WriteDatagram.`, func() {
49 fbuf := bytes.Buffer{}
50 recordio.WriteFrame(&fbuf, []byte{0xd0, 0x65})
51
52 So(si.WriteDatagram([]byte{0xd0, 0x65}), ShouldB eNil)
53 So(buf.Bytes(), ShouldResemble, fbuf.Bytes())
54 })
55 })
56 })
57 }
58
59 type nopWriteCloser struct {
60 io.Writer
61 }
62
63 func (nwc *nopWriteCloser) Close() error { return nil }
OLDNEW
« 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