github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/peer/common/mockclient.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     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 common
    18  
    19  import (
    20  	cb "github.com/hyperledger/fabric/protos/common"
    21  	pb "github.com/hyperledger/fabric/protos/peer"
    22  	context "golang.org/x/net/context"
    23  	grpc "google.golang.org/grpc"
    24  )
    25  
    26  // GetMockEndorserClient return a endorser client return specified ProposalResponse and err(nil or error)
    27  func GetMockEndorserClient(response *pb.ProposalResponse, err error) pb.EndorserClient {
    28  	return &mockEndorserClient{
    29  		response: response,
    30  		err:      err,
    31  	}
    32  }
    33  
    34  type mockEndorserClient struct {
    35  	response *pb.ProposalResponse
    36  	err      error
    37  }
    38  
    39  func (m *mockEndorserClient) ProcessProposal(ctx context.Context, in *pb.SignedProposal, opts ...grpc.CallOption) (*pb.ProposalResponse, error) {
    40  	return m.response, m.err
    41  }
    42  
    43  func GetMockBroadcastClient(err error) BroadcastClient {
    44  	return &mockBroadcastClient{err: err}
    45  }
    46  
    47  // mockBroadcastClient return success immediately
    48  type mockBroadcastClient struct {
    49  	err error
    50  }
    51  
    52  func (m *mockBroadcastClient) Send(env *cb.Envelope) error {
    53  	return m.err
    54  }
    55  
    56  func (m *mockBroadcastClient) Close() error {
    57  	return nil
    58  }