github.com/lzy4123/fabric@v2.1.1+incompatible/integration/lifecycle/install_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package lifecycle 8 9 import ( 10 "io/ioutil" 11 "os" 12 "path/filepath" 13 "syscall" 14 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 18 docker "github.com/fsouza/go-dockerclient" 19 "github.com/hyperledger/fabric/integration/nwo" 20 "github.com/hyperledger/fabric/integration/nwo/commands" 21 "github.com/hyperledger/fabric/integration/nwo/fabricconfig" 22 "github.com/onsi/gomega/gbytes" 23 "github.com/onsi/gomega/gexec" 24 "github.com/tedsuo/ifrit" 25 ) 26 27 var _ = Describe("chaincode install", func() { 28 var ( 29 client *docker.Client 30 testDir string 31 32 network *nwo.Network 33 process ifrit.Process 34 ) 35 36 BeforeEach(func() { 37 var err error 38 testDir, err = ioutil.TempDir("", "lifecycle") 39 Expect(err).NotTo(HaveOccurred()) 40 41 client, err = docker.NewClientFromEnv() 42 Expect(err).NotTo(HaveOccurred()) 43 44 cwd, err := os.Getwd() 45 Expect(err).NotTo(HaveOccurred()) 46 47 network = nwo.New(nwo.BasicSolo(), testDir, client, StartPort(), components) 48 network.ExternalBuilders = append(network.ExternalBuilders, fabricconfig.ExternalBuilder{ 49 Path: filepath.Join(cwd, "..", "externalbuilders", "golang"), 50 Name: "external-golang", 51 EnvironmentWhitelist: []string{"GOPATH", "GOCACHE", "GOPROXY", "HOME", "PATH"}, 52 }) 53 network.GenerateConfigTree() 54 network.Bootstrap() 55 56 networkRunner := network.NetworkGroupRunner() 57 process = ifrit.Invoke(networkRunner) 58 Eventually(process.Ready(), network.EventuallyTimeout).Should(BeClosed()) 59 }) 60 61 AfterEach(func() { 62 process.Signal(syscall.SIGTERM) 63 Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive()) 64 network.Cleanup() 65 os.RemoveAll(testDir) 66 }) 67 68 Describe("external builder failures", func() { 69 var ( 70 orderer *nwo.Orderer 71 org1Peer *nwo.Peer 72 org2Peer *nwo.Peer 73 chaincode nwo.Chaincode 74 ) 75 76 BeforeEach(func() { 77 packageTempDir, err := ioutil.TempDir(network.RootDir, "chaincode-package") 78 Expect(err).NotTo(HaveOccurred()) 79 80 orderer = network.Orderer("orderer") 81 org1Peer = network.Peer("Org1", "peer0") 82 org2Peer = network.Peer("Org2", "peer0") 83 network.CreateAndJoinChannels(orderer) 84 85 chaincode = nwo.Chaincode{ 86 Name: "failure-external", 87 Version: "0.0", 88 Lang: "golang", 89 Path: "github.com/hyperledger/fabric/integration/chaincode/simple/cmd", 90 Ctor: `{"Args":["init","a","100","b","200"]}`, 91 Policy: `OR ('Org1MSP.member','Org2MSP.member')`, 92 SignaturePolicy: `OR ('Org1MSP.member','Org2MSP.member')`, 93 Sequence: "1", 94 InitRequired: false, 95 Label: "failure-external", 96 PackageFile: filepath.Join(packageTempDir, "chaincode-package"), 97 } 98 }) 99 100 It("legacy does not fallback to internal platforms", func() { 101 By("packaging the chaincode using the legacy lifecycle") 102 nwo.PackageChaincodeLegacy(network, chaincode, org1Peer) 103 104 By("installing the chaincode using the legacy lifecycle") 105 sess, err := network.PeerAdminSession(org1Peer, commands.ChaincodeInstallLegacy{ 106 Name: chaincode.Name, 107 Version: chaincode.Version, 108 Path: chaincode.Path, 109 Lang: chaincode.Lang, 110 PackageFile: chaincode.PackageFile, 111 ClientAuth: network.ClientAuthRequired, 112 }) 113 Expect(err).NotTo(HaveOccurred()) 114 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(1)) 115 116 Expect(sess.Err).To(gbytes.Say(`\Qexternal builder 'external-golang' failed: exit status 1\E`)) 117 }) 118 119 It("_lifecycle does not fallback to internal platforms when an external builder fails", func() { 120 By("enabling V2_0 application capabilities") 121 nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, org1Peer, org2Peer) 122 123 By("packaging the chaincode") 124 nwo.PackageChaincode(network, chaincode, org1Peer) 125 126 By("installing the chaincode using _lifecycle") 127 sess, err := network.PeerAdminSession(org1Peer, commands.ChaincodeInstall{ 128 PackageFile: chaincode.PackageFile, 129 ClientAuth: network.ClientAuthRequired, 130 }) 131 Expect(err).NotTo(HaveOccurred()) 132 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(1)) 133 134 Expect(sess.Err).To(gbytes.Say(`\Qexternal builder 'external-golang' failed: exit status 1\E`)) 135 }) 136 }) 137 })