go.uber.org/yarpc@v1.72.1/encoding/thrift/fakes_test.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 thrift
    22  
    23  import (
    24  	"io"
    25  
    26  	"go.uber.org/thriftrw/protocol/stream"
    27  	"go.uber.org/thriftrw/wire"
    28  )
    29  
    30  const _irrelevant = "irrelevant"
    31  
    32  type fakeBodyReader struct {
    33  	body string
    34  }
    35  
    36  func (f *fakeBodyReader) Decode(sr stream.Reader) error {
    37  	s, err := sr.ReadString()
    38  	f.body = s
    39  	return err
    40  }
    41  
    42  // TODO(witriew): fakeEnveloper should be created with a constructor, allowing
    43  // its uses to dictate the returned values for MethodName and encoded string.
    44  type fakeEnveloper wire.EnvelopeType
    45  
    46  func (fakeEnveloper) MethodName() string {
    47  	return "someMethod"
    48  }
    49  
    50  func (e fakeEnveloper) EnvelopeType() wire.EnvelopeType {
    51  	return wire.EnvelopeType(e)
    52  }
    53  
    54  func (fakeEnveloper) ToWire() (wire.Value, error) {
    55  	return wire.NewValueStruct(wire.Struct{}), nil
    56  }
    57  
    58  func (fakeEnveloper) Encode(sw stream.Writer) error {
    59  	return sw.WriteString(_irrelevant)
    60  }
    61  
    62  type errorEnveloper struct {
    63  	envelopeType wire.EnvelopeType
    64  	err          error
    65  }
    66  
    67  func (errorEnveloper) MethodName() string {
    68  	return "someMethod"
    69  }
    70  
    71  func (e errorEnveloper) EnvelopeType() wire.EnvelopeType {
    72  	return e.envelopeType
    73  }
    74  
    75  func (e errorEnveloper) ToWire() (wire.Value, error) {
    76  	return wire.Value{}, e.err
    77  }
    78  
    79  func (e errorEnveloper) Encode(stream.Writer) error {
    80  	return e.err
    81  }
    82  
    83  type errorResponder struct {
    84  	err error
    85  }
    86  
    87  func (e errorResponder) EncodeResponse(v wire.Value, et wire.EnvelopeType, w io.Writer) error {
    88  	return e.err
    89  }
    90  
    91  func (e errorResponder) WriteResponse(wire.EnvelopeType, io.Writer, stream.Enveloper) error {
    92  	return e.err
    93  }