go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/client/butlerlib/streamclient/client_test.go (about) 1 // Copyright 2015 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package streamclient 16 17 import ( 18 "context" 19 "testing" 20 21 "go.chromium.org/luci/common/errors" 22 23 . "github.com/smartystreets/goconvey/convey" 24 . "go.chromium.org/luci/common/testing/assertions" 25 ) 26 27 func TestClientGeneral(t *testing.T) { 28 t.Parallel() 29 30 Convey(`General Client checks`, t, func() { 31 ctx := context.Background() 32 33 Convey(`fails to instantiate a Client with an invalid protocol.`, func() { 34 _, err := New("notreal:foo", "") 35 So(err, ShouldErrLike, "no protocol registered for [notreal]") 36 }) 37 38 scFake := NewFake() 39 defer scFake.Unregister() 40 41 Convey(`ForProcess used with datagram stream`, func() { 42 client, err := New(scFake.StreamServerPath(), "") 43 So(err, ShouldBeNil) 44 45 _, err = client.NewDatagramStream(ctx, "test", ForProcess()) 46 So(err, ShouldErrLike, "cannot specify ForProcess on a datagram stream") 47 }) 48 49 Convey(`bad options`, func() { 50 client, err := New(scFake.StreamServerPath(), "") 51 So(err, ShouldBeNil) 52 53 _, err = client.NewStream(ctx, "test", WithTags("bad+@!tag", "value")) 54 So(err, ShouldErrLike, `invalid tag "bad+@!tag"`) 55 56 // for coverage, whee. 57 _, err = client.NewStream(ctx, "test", WithTags("bad+@!tag", "value"), Binary()) 58 So(err, ShouldErrLike, `invalid tag "bad+@!tag"`) 59 60 _, err = client.NewDatagramStream(ctx, "test", WithTags("bad+@!tag", "value")) 61 So(err, ShouldErrLike, `invalid tag "bad+@!tag"`) 62 }) 63 64 Convey(`simulated stream errors`, func() { 65 Convey(`connection error`, func() { 66 client, err := New(scFake.StreamServerPath(), "") 67 So(err, ShouldBeNil) 68 scFake.SetError(errors.New("bad juju")) 69 70 _, err = client.NewStream(ctx, "test") 71 So(err, ShouldErrLike, `stream "test": bad juju`) 72 }) 73 }) 74 }) 75 }