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

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

Issue 2456953003: LogDog: Update client/bootstrap to generate URLs. (Closed)
Patch Set: Winders Created 4 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
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 := streamImpl{
22 » » » Properties: &streamproto.Properties{},
23 WriteCloser: &nopWriteCloser{Writer: &buf}, 22 WriteCloser: &nopWriteCloser{Writer: &buf},
23 props: (&streamproto.Flags{}).Properties(),
24 } 24 }
25
25 Convey(`TEXT`, func() { 26 Convey(`TEXT`, func() {
26 » » » si.Properties.StreamType = logpb.StreamType_TEXT 27 » » » si.props.StreamType = logpb.StreamType_TEXT
27 28
28 Convey(`Will error if WriteDatagram is called.`, func() { 29 Convey(`Will error if WriteDatagram is called.`, func() {
29 So(si.WriteDatagram([]byte(nil)), ShouldNotBeNil ) 30 So(si.WriteDatagram([]byte(nil)), ShouldNotBeNil )
30 }) 31 })
31 32
32 Convey(`Can invoke Write.`, func() { 33 Convey(`Can invoke Write.`, func() {
33 amt, err := si.Write([]byte{0xd0, 0x65}) 34 amt, err := si.Write([]byte{0xd0, 0x65})
34 So(err, ShouldBeNil) 35 So(err, ShouldBeNil)
35 So(amt, ShouldEqual, 2) 36 So(amt, ShouldEqual, 2)
36 So(buf.Bytes(), ShouldResemble, []byte{0xd0, 0x6 5}) 37 So(buf.Bytes(), ShouldResemble, []byte{0xd0, 0x6 5})
37 }) 38 })
38 }) 39 })
39 40
40 Convey(`DATAGRAM`, func() { 41 Convey(`DATAGRAM`, func() {
41 » » » si.Properties.StreamType = logpb.StreamType_DATAGRAM 42 » » » si.props.StreamType = logpb.StreamType_DATAGRAM
42 43
43 Convey(`Will error if Write is called.`, func() { 44 Convey(`Will error if Write is called.`, func() {
44 _, err := si.Write([]byte(nil)) 45 _, err := si.Write([]byte(nil))
45 So(err, ShouldNotBeNil) 46 So(err, ShouldNotBeNil)
46 }) 47 })
47 48
48 Convey(`Can invoke WriteDatagram.`, func() { 49 Convey(`Can invoke WriteDatagram.`, func() {
49 fbuf := bytes.Buffer{} 50 fbuf := bytes.Buffer{}
50 recordio.WriteFrame(&fbuf, []byte{0xd0, 0x65}) 51 recordio.WriteFrame(&fbuf, []byte{0xd0, 0x65})
51 52
52 So(si.WriteDatagram([]byte{0xd0, 0x65}), ShouldB eNil) 53 So(si.WriteDatagram([]byte{0xd0, 0x65}), ShouldB eNil)
53 So(buf.Bytes(), ShouldResemble, fbuf.Bytes()) 54 So(buf.Bytes(), ShouldResemble, fbuf.Bytes())
54 }) 55 })
55 }) 56 })
56 }) 57 })
57 } 58 }
58 59
59 type nopWriteCloser struct { 60 type nopWriteCloser struct {
60 io.Writer 61 io.Writer
61 } 62 }
62 63
63 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/butlerlib/streamproto/properties.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698