github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/core/scc/scc_test.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package scc_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/hechain20/hechain/core/chaincode/lifecycle"
    13  	"github.com/hechain20/hechain/core/scc"
    14  	"github.com/hechain20/hechain/core/scc/mock"
    15  	. "github.com/onsi/gomega"
    16  )
    17  
    18  //go:generate counterfeiter -o mock/chaincode_stream_handler.go --fake-name ChaincodeStreamHandler . chaincodeStreamHandler
    19  type chaincodeStreamHandler interface {
    20  	scc.ChaincodeStreamHandler
    21  }
    22  
    23  func TestDeploy(t *testing.T) {
    24  	gt := NewGomegaWithT(t)
    25  
    26  	doneC := make(chan struct{})
    27  	csh := &mock.ChaincodeStreamHandler{}
    28  	csh.LaunchInProcReturns(doneC)
    29  
    30  	deployC := make(chan struct{})
    31  	go func() { scc.DeploySysCC(&lifecycle.SCC{}, csh); close(deployC) }()
    32  
    33  	// Consume the register message to enable cleanup
    34  	gt.Eventually(csh.HandleChaincodeStreamCallCount).Should(Equal(1))
    35  	stream := csh.HandleChaincodeStreamArgsForCall(0)
    36  	stream.Recv()
    37  
    38  	close(doneC)
    39  	gt.Eventually(deployC).Should(BeClosed())
    40  
    41  	gt.Expect(csh.LaunchInProcCallCount()).To(Equal(1))
    42  	gt.Expect(csh.LaunchInProcArgsForCall(0)).To(Equal("_lifecycle.syscc"))
    43  	gt.Eventually(csh.HandleChaincodeStreamCallCount).Should(Equal(1))
    44  }