github.com/braveheart12/insolar-09-08-19@v0.8.7/pulsar/pulsartestutils/customrpcwrappermock.go (about)

     1  /*
     2   *    Copyright 2019 Insolar Technologies
     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 pulsartestutil - test utils for pulsar package
    18  package pulsartestutils
    19  
    20  import (
    21  	"net/rpc"
    22  
    23  	"github.com/insolar/insolar/configuration"
    24  )
    25  
    26  // CustomRPCWrapperMock is a mock of RPCClientWrapper interface
    27  // It uses hand-created mocks
    28  type CustomRPCWrapperMock struct {
    29  	Done                 *rpc.Call
    30  	IsInitFunc           func() bool
    31  	CreateConnectionFunc func() error
    32  }
    33  
    34  func (*CustomRPCWrapperMock) Lock() {
    35  }
    36  
    37  func (*CustomRPCWrapperMock) Unlock() {
    38  }
    39  
    40  func (impl *CustomRPCWrapperMock) IsInitialised() bool {
    41  	if impl.IsInitFunc == nil {
    42  		return false
    43  	}
    44  	return impl.IsInitFunc()
    45  }
    46  
    47  func (*CustomRPCWrapperMock) SetRPCClient(client *rpc.Client) {
    48  }
    49  
    50  func (impl *CustomRPCWrapperMock) CreateConnection(connectionType configuration.ConnectionType, connectionAddress string) error {
    51  	if impl.CreateConnectionFunc == nil {
    52  		return nil
    53  	}
    54  	return impl.CreateConnectionFunc()
    55  }
    56  
    57  func (*CustomRPCWrapperMock) Close() error {
    58  	return nil
    59  }
    60  
    61  func (impl *CustomRPCWrapperMock) Go(serviceMethod string, args interface{}, reply interface{}, done chan *rpc.Call) *rpc.Call {
    62  	return impl.Done
    63  }
    64  
    65  func (impl *CustomRPCWrapperMock) ResetClient() {
    66  }