github.com/s7techlab/cckit@v0.10.5/testing/mocked_peer_test.go (about)

     1  package testing_test
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/golang/protobuf/ptypes/empty"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  
    10  	"github.com/s7techlab/cckit/examples/cpaper_asservice"
    11  	cpservice "github.com/s7techlab/cckit/examples/cpaper_asservice"
    12  	"github.com/s7techlab/cckit/gateway"
    13  	idtestdata "github.com/s7techlab/cckit/identity/testdata"
    14  	testcc "github.com/s7techlab/cckit/testing"
    15  )
    16  
    17  var _ = Describe(`Service`, func() {
    18  
    19  	const (
    20  		ChaincodeName = `commercial_paper`
    21  	)
    22  
    23  	var (
    24  		peer          *testcc.MockedPeerDecorator
    25  		cPaperGateway *cpservice.CPaperServiceGateway
    26  
    27  		ctx = gateway.ContextWithSigner(
    28  			context.Background(),
    29  			idtestdata.Certificates[0].MustIdentity(idtestdata.DefaultMSP),
    30  		)
    31  	)
    32  
    33  	It("Init", func() {
    34  		ccImpl, err := cpaper_asservice.NewCC()
    35  		Expect(err).NotTo(HaveOccurred())
    36  
    37  		// peer imitation
    38  		peer = testcc.NewPeerDecorator(testcc.NewPeer().WithChannel(Channel, testcc.NewMockStub(ChaincodeName, ccImpl)))
    39  
    40  		// "sdk" for deal with cpaper chaincode
    41  		cPaperGateway = cpservice.NewCPaperServiceGateway(peer, Channel, ChaincodeName)
    42  	})
    43  
    44  	It("Default invoker", func() {
    45  		_, err := cPaperGateway.List(ctx, &empty.Empty{})
    46  		Expect(err).NotTo(HaveOccurred())
    47  	})
    48  
    49  	It("Allow to imitate error while access to peer", func() {
    50  		peer.FailChaincode(ChaincodeName)
    51  
    52  		_, err := cPaperGateway.List(ctx, &empty.Empty{})
    53  		Expect(err).To(HaveOccurred())
    54  	})
    55  })