| OLD | NEW |
| 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 "errors" | 9 "errors" |
| 10 "io" | 10 "io" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 }) | 72 }) |
| 73 | 73 |
| 74 Convey(`Can instantiate a new client.`, func() { | 74 Convey(`Can instantiate a new client.`, func() { |
| 75 client, err := reg.NewClient("test:foo") | 75 client, err := reg.NewClient("test:foo") |
| 76 So(err, ShouldBeNil) | 76 So(err, ShouldBeNil) |
| 77 So(client, ShouldHaveSameTypeAs, &clientImpl{}) | 77 So(client, ShouldHaveSameTypeAs, &clientImpl{}) |
| 78 | 78 |
| 79 Convey(`That can instantiate new Streams.`, func() { | 79 Convey(`That can instantiate new Streams.`, func() { |
| 80 stream, err := client.NewStream(flags) | 80 stream, err := client.NewStream(flags) |
| 81 So(err, ShouldBeNil) | 81 So(err, ShouldBeNil) |
| 82 » » » » So(stream, ShouldHaveSameTypeAs, &streamImpl{}) | 82 » » » » So(stream, ShouldHaveSameTypeAs, &BaseStream{}) |
| 83 | 83 |
| 84 » » » » si := stream.(*streamImpl) | 84 » » » » si := stream.(*BaseStream) |
| 85 So(si.WriteCloser, ShouldHaveSameTypeAs, &testSt
reamWriteCloser{}) | 85 So(si.WriteCloser, ShouldHaveSameTypeAs, &testSt
reamWriteCloser{}) |
| 86 | 86 |
| 87 tswc := si.WriteCloser.(*testStreamWriteCloser) | 87 tswc := si.WriteCloser.(*testStreamWriteCloser) |
| 88 So(tswc.addr, ShouldEqual, "foo") | 88 So(tswc.addr, ShouldEqual, "foo") |
| 89 | 89 |
| 90 Convey(`The stream should have the stream header
written to it.`, func() { | 90 Convey(`The stream should have the stream header
written to it.`, func() { |
| 91 So(tswc.Next(len(streamproto.ProtocolFra
meHeaderMagic)), ShouldResemble, | 91 So(tswc.Next(len(streamproto.ProtocolFra
meHeaderMagic)), ShouldResemble, |
| 92 streamproto.ProtocolFrameHeaderM
agic) | 92 streamproto.ProtocolFrameHeaderM
agic) |
| 93 | 93 |
| 94 r := recordio.NewReader(tswc, -1) | 94 r := recordio.NewReader(tswc, -1) |
| 95 f, err := r.ReadFrameAll() | 95 f, err := r.ReadFrameAll() |
| 96 So(err, ShouldBeNil) | 96 So(err, ShouldBeNil) |
| 97 So(string(f), ShouldResemble, `{"name":"
test","timestamp":"0001-02-03T04:05:06.000000007Z"}`) | 97 So(string(f), ShouldResemble, `{"name":"
test","timestamp":"0001-02-03T04:05:06.000000007Z"}`) |
| 98 }) | 98 }) |
| 99 }) | 99 }) |
| 100 | 100 |
| 101 Convey(`If the stream fails to write the handshake, it w
ill be closed.`, func() { | 101 Convey(`If the stream fails to write the handshake, it w
ill be closed.`, func() { |
| 102 tswcErr = errors.New("test error") | 102 tswcErr = errors.New("test error") |
| 103 _, err := client.NewStream(flags) | 103 _, err := client.NewStream(flags) |
| 104 So(err, ShouldNotBeNil) | 104 So(err, ShouldNotBeNil) |
| 105 | 105 |
| 106 So(tswc, ShouldNotBeNil) | 106 So(tswc, ShouldNotBeNil) |
| 107 So(tswc.closed, ShouldBeTrue) | 107 So(tswc.closed, ShouldBeTrue) |
| 108 }) | 108 }) |
| 109 }) | 109 }) |
| 110 }) | 110 }) |
| 111 } | 111 } |
| OLD | NEW |