go.uber.org/yarpc@v1.72.1/x/yarpctest/api/request_stream.go (about) 1 // Copyright (c) 2022 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package api 22 23 import ( 24 "testing" 25 26 "go.uber.org/yarpc/api/peer" 27 "go.uber.org/yarpc/api/transport" 28 peerchooser "go.uber.org/yarpc/peer" 29 ) 30 31 // ClientStreamRequestOpts are configuration options for a yarpc stream request. 32 type ClientStreamRequestOpts struct { 33 Port uint16 34 GiveRequest *transport.StreamRequest 35 StreamActions []ClientStreamAction 36 WantErrMsgs []string 37 NewChooser func(peer.Identifier, peer.Transport) (peer.Chooser, error) 38 } 39 40 // NewClientStreamRequestOpts initializes a ClientStreamRequestOpts struct. 41 func NewClientStreamRequestOpts() ClientStreamRequestOpts { 42 return ClientStreamRequestOpts{ 43 GiveRequest: &transport.StreamRequest{ 44 Meta: &transport.RequestMeta{ 45 Caller: "unknown", 46 Encoding: transport.Encoding("raw"), 47 }, 48 }, 49 NewChooser: func(id peer.Identifier, transport peer.Transport) (peer.Chooser, error) { 50 return peerchooser.NewSingle(id, transport), nil 51 }, 52 } 53 } 54 55 // ClientStreamRequestOption can be used to configure a request. 56 type ClientStreamRequestOption interface { 57 ApplyClientStreamRequest(*ClientStreamRequestOpts) 58 } 59 60 // ClientStreamRequestOptionFunc converts a function into a ClientStreamRequestOption. 61 type ClientStreamRequestOptionFunc func(*ClientStreamRequestOpts) 62 63 // ApplyClientStreamRequest implements ClientStreamRequestOption. 64 func (f ClientStreamRequestOptionFunc) ApplyClientStreamRequest(opts *ClientStreamRequestOpts) { 65 f(opts) 66 } 67 68 // ClientStreamAction is an action applied to a ClientStream. 69 type ClientStreamAction interface { 70 ApplyClientStream(testing.TB, *transport.ClientStream) 71 } 72 73 // ClientStreamActionFunc converts a function into a StreamAction. 74 type ClientStreamActionFunc func(testing.TB, *transport.ClientStream) 75 76 // ApplyClientStream implements ClientStreamAction. 77 func (f ClientStreamActionFunc) ApplyClientStream(t testing.TB, c *transport.ClientStream) { f(t, c) }