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

Side by Side Diff: logdog/client/butlerlib/streamclient/stream_test.go

Issue 2737603003: Butler stream servers can generate client address. (Closed)
Patch Set: better comment Created 3 years, 9 months 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
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package streamclient 5 package streamclient
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "io" 9 "io"
10 "testing" 10 "testing"
11 11
12 "github.com/luci/luci-go/common/data/recordio" 12 "github.com/luci/luci-go/common/data/recordio"
13 "github.com/luci/luci-go/logdog/api/logpb" 13 "github.com/luci/luci-go/logdog/api/logpb"
14 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" 14 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto"
15 . "github.com/smartystreets/goconvey/convey" 15 . "github.com/smartystreets/goconvey/convey"
16 ) 16 )
17 17
18 func TestStreamImpl(t *testing.T) { 18 func TestStreamImpl(t *testing.T) {
19 Convey(`A stream writing to a buffer`, t, func() { 19 Convey(`A stream writing to a buffer`, t, func() {
20 buf := bytes.Buffer{} 20 buf := bytes.Buffer{}
21 » » si := streamImpl{ 21 » » si := BaseStream{
22 WriteCloser: &nopWriteCloser{Writer: &buf}, 22 WriteCloser: &nopWriteCloser{Writer: &buf},
23 » » » props: (&streamproto.Flags{}).Properties(), 23 » » » P: (&streamproto.Flags{}).Properties(),
24 } 24 }
25 25
26 Convey(`TEXT`, func() { 26 Convey(`TEXT`, func() {
27 » » » si.props.StreamType = logpb.StreamType_TEXT 27 » » » si.P.StreamType = logpb.StreamType_TEXT
28 28
29 Convey(`Will error if WriteDatagram is called.`, func() { 29 Convey(`Will error if WriteDatagram is called.`, func() {
30 So(si.WriteDatagram([]byte(nil)), ShouldNotBeNil ) 30 So(si.WriteDatagram([]byte(nil)), ShouldNotBeNil )
31 }) 31 })
32 32
33 Convey(`Can invoke Write.`, func() { 33 Convey(`Can invoke Write.`, func() {
34 amt, err := si.Write([]byte{0xd0, 0x65}) 34 amt, err := si.Write([]byte{0xd0, 0x65})
35 So(err, ShouldBeNil) 35 So(err, ShouldBeNil)
36 So(amt, ShouldEqual, 2) 36 So(amt, ShouldEqual, 2)
37 So(buf.Bytes(), ShouldResemble, []byte{0xd0, 0x6 5}) 37 So(buf.Bytes(), ShouldResemble, []byte{0xd0, 0x6 5})
38 }) 38 })
39 }) 39 })
40 40
41 Convey(`DATAGRAM`, func() { 41 Convey(`DATAGRAM`, func() {
42 » » » si.props.StreamType = logpb.StreamType_DATAGRAM 42 » » » si.P.StreamType = logpb.StreamType_DATAGRAM
43 43
44 Convey(`Will error if Write is called.`, func() { 44 Convey(`Will error if Write is called.`, func() {
45 _, err := si.Write([]byte(nil)) 45 _, err := si.Write([]byte(nil))
46 So(err, ShouldNotBeNil) 46 So(err, ShouldNotBeNil)
47 }) 47 })
48 48
49 Convey(`Can invoke WriteDatagram.`, func() { 49 Convey(`Can invoke WriteDatagram.`, func() {
50 fbuf := bytes.Buffer{} 50 fbuf := bytes.Buffer{}
51 recordio.WriteFrame(&fbuf, []byte{0xd0, 0x65}) 51 recordio.WriteFrame(&fbuf, []byte{0xd0, 0x65})
52 52
53 So(si.WriteDatagram([]byte{0xd0, 0x65}), ShouldB eNil) 53 So(si.WriteDatagram([]byte{0xd0, 0x65}), ShouldB eNil)
54 So(buf.Bytes(), ShouldResemble, fbuf.Bytes()) 54 So(buf.Bytes(), ShouldResemble, fbuf.Bytes())
55 }) 55 })
56 }) 56 })
57 }) 57 })
58 } 58 }
59 59
60 type nopWriteCloser struct { 60 type nopWriteCloser struct {
61 io.Writer 61 io.Writer
62 } 62 }
63 63
64 func (nwc *nopWriteCloser) Close() error { return nil } 64 func (nwc *nopWriteCloser) Close() error { return nil }
OLDNEW
« no previous file with comments | « logdog/client/butlerlib/streamclient/stream.go ('k') | logdog/client/cmd/logdog_butler/main_posix.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698