| OLD | NEW |
| (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 } |
| OLD | NEW |