Skip to content

Commit 6860586

Browse files
author
Srinivasan Muralidharan
committed
[FAB-4208] proper UT for chaincode framework
Replaces the heavyweight chaincode framework tests that need a full fledged peer and container env for testing with a lightweight UT tests using a mock environment. The CC side and some of the ledger interfaces are mocked. Also disables other tests in the framework so the community can get a feel for the coverage and speedup . renamed cc_test.go to chaincode_support_test.go . add some minor tests . added some error refactoring in handler.go Change-Id: I462f05f7a78b7b2cfbb20138a20c5c0ee45a9be4 Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent 3079333 commit 6860586

7 files changed

+801
-116
lines changed

common/mocks/peer/mockccstream.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type MockResponseSet struct {
4444
//and response to send (optional)
4545
type MockResponse struct {
4646
RecvMsg *pb.ChaincodeMessage
47-
RespMsg *pb.ChaincodeMessage
47+
RespMsg interface{}
4848
}
4949

5050
// MockCCComm implements the mock communication between chaincode and peer
@@ -60,6 +60,10 @@ type MockCCComm struct {
6060
respSet *MockResponseSet
6161
}
6262

63+
func (s *MockCCComm) SetName(newname string) {
64+
s.name = newname
65+
}
66+
6367
//Send sends a message
6468
func (s *MockCCComm) Send(msg *pb.ChaincodeMessage) error {
6569
s.sendStream <- msg
@@ -143,7 +147,17 @@ func (s *MockCCComm) respond(msg *pb.ChaincodeMessage) error {
143147
}
144148

145149
if mockResp.RespMsg != nil {
146-
err = s.Send(mockResp.RespMsg)
150+
var ccMsg *pb.ChaincodeMessage
151+
if ccMsg, _ = mockResp.RespMsg.(*pb.ChaincodeMessage); ccMsg == nil {
152+
if ccMsgFunc, ok := mockResp.RespMsg.(func(*pb.ChaincodeMessage) *pb.ChaincodeMessage); ok && ccMsgFunc != nil {
153+
ccMsg = ccMsgFunc(msg)
154+
}
155+
}
156+
157+
if ccMsg == nil {
158+
panic("----no pb.ChaincodeMessage---")
159+
}
160+
err = s.Send(ccMsg)
147161
}
148162

149163
s.respIndex = s.respIndex + 1

0 commit comments

Comments
 (0)