github.com/cloudwego/kitex@v0.9.0/pkg/rpcinfo/mocks_test.go (about) 1 /* 2 * Copyright 2021 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package rpcinfo_test 18 19 import ( 20 "context" 21 "time" 22 23 "github.com/cloudwego/kitex/pkg/rpcinfo" 24 "github.com/cloudwego/kitex/pkg/serviceinfo" 25 "github.com/cloudwego/kitex/pkg/stats" 26 "github.com/cloudwego/kitex/transport" 27 ) 28 29 var _ rpcinfo.RPCConfig = &MockRPCConfig{} 30 31 // MockRPCConfig implements the rpcinfo.RPCConfig interface. 32 type MockRPCConfig struct { 33 RPCTimeoutFunc func() (r time.Duration) 34 ConnectTimeoutFunc func() (r time.Duration) 35 ReadWriteTimeoutFunc func() (r time.Duration) 36 IOBufferSizeFunc func() (r int) 37 TransportProtocolFunc func() transport.Protocol 38 InteractionModeFunc func() (r rpcinfo.InteractionMode) 39 } 40 41 func (m *MockRPCConfig) PayloadCodec() serviceinfo.PayloadCodec { 42 // TODO implement me 43 panic("implement me") 44 } 45 46 func (m *MockRPCConfig) InteractionMode() (r rpcinfo.InteractionMode) { 47 if m.InteractionModeFunc != nil { 48 return m.InteractionModeFunc() 49 } 50 return 51 } 52 53 // RPCTimeout implements the rpcinfo.RPCConfig interface. 54 func (m *MockRPCConfig) RPCTimeout() (r time.Duration) { 55 if m.RPCTimeoutFunc != nil { 56 return m.RPCTimeoutFunc() 57 } 58 return 59 } 60 61 // ConnectTimeout implements the rpcinfo.RPCConfig interface. 62 func (m *MockRPCConfig) ConnectTimeout() (r time.Duration) { 63 if m.ConnectTimeoutFunc != nil { 64 return m.ConnectTimeoutFunc() 65 } 66 return 67 } 68 69 // ReadWriteTimeout implements the rpcinfo.RPCConfig interface. 70 func (m *MockRPCConfig) ReadWriteTimeout() (r time.Duration) { 71 if m.ReadWriteTimeoutFunc != nil { 72 return m.ReadWriteTimeoutFunc() 73 } 74 return 75 } 76 77 // IOBufferSize implements the rpcinfo.RPCConfig interface. 78 func (m *MockRPCConfig) IOBufferSize() (r int) { 79 if m.IOBufferSizeFunc != nil { 80 return m.IOBufferSizeFunc() 81 } 82 return 83 } 84 85 // TransportProtocol implements the rpcinfo.RPCConfig interface. 86 func (m *MockRPCConfig) TransportProtocol() (r transport.Protocol) { 87 if m.TransportProtocolFunc != nil { 88 return m.TransportProtocolFunc() 89 } 90 return 91 } 92 93 type MockRPCStats struct{} 94 95 func (m *MockRPCStats) Record(context.Context, stats.Event, stats.Status, string) {} 96 func (m *MockRPCStats) SendSize() uint64 { return 0 } 97 func (m *MockRPCStats) RecvSize() uint64 { return 0 } 98 func (m *MockRPCStats) Error() error { return nil } 99 func (m *MockRPCStats) Panicked() (yes bool, val interface{}) { return } 100 func (m *MockRPCStats) GetEvent(event stats.Event) (e rpcinfo.Event) { return } 101 func (m *MockRPCStats) Level() (lv stats.Level) { return } 102 func (m *MockRPCStats) CopyForRetry() rpcinfo.RPCStats { return nil } 103 func (m *MockRPCStats) LastSendSize() uint64 { return 0 } 104 func (m *MockRPCStats) LastRecvSize() uint64 { return 0 }