Skip to content

Commit 59d29f8

Browse files
committed
[FAB-10335] InstallChaincode installs and verifies
Change-Id: I7aede95bf931940154c591009e7866bee5eca061 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent aa9150a commit 59d29f8

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

integration/helpers/gexec.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright IBM Corp All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package helpers
8+
9+
import (
10+
"fmt"
11+
"os/exec"
12+
13+
"github.com/onsi/ginkgo"
14+
"github.com/onsi/gomega/gexec"
15+
)
16+
17+
func StartSession(cmd *exec.Cmd, name, ansiColorCode string) (*gexec.Session, error) {
18+
return gexec.Start(
19+
cmd,
20+
gexec.NewPrefixedWriter(fmt.Sprintf("\x1b[32m[o]\x1b[%s[%s]\x1b[0m ", ansiColorCode, name), ginkgo.GinkgoWriter),
21+
gexec.NewPrefixedWriter(fmt.Sprintf("\x1b[91m[e]\x1b[%s[%s]\x1b[0m ", ansiColorCode, name), ginkgo.GinkgoWriter),
22+
)
23+
}

integration/runner/peer.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import (
1010
"fmt"
1111
"os"
1212
"os/exec"
13+
"time"
1314

15+
"github.com/hyperledger/fabric/integration/helpers"
16+
. "github.com/onsi/gomega"
17+
"github.com/onsi/gomega/gbytes"
18+
"github.com/onsi/gomega/gexec"
1419
"github.com/tedsuo/ifrit/ginkgomon"
1520
)
1621

@@ -154,17 +159,21 @@ func (p *Peer) UpdateChannel(transactionFile string, channel string, orderer str
154159
return r
155160
}
156161

157-
func (p *Peer) InstallChaincode(name string, version string, path string) *ginkgomon.Runner {
162+
func (p *Peer) InstallChaincode(name, version, path string) {
158163
cmd := exec.Command(p.Path, "chaincode", "install", "-n", name, "-v", version, "-p", path)
159164
p.setupEnvironment(cmd)
160165

161-
r := ginkgomon.New(ginkgomon.Config{
162-
Name: "install",
163-
AnsiColorCode: "4;34m",
164-
Command: cmd,
165-
})
166+
sess, err := helpers.StartSession(cmd, "install", "4;34m")
167+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
168+
EventuallyWithOffset(1, sess, time.Minute).Should(gexec.Exit(0))
166169

167-
return r
170+
cmd = exec.Command(p.Path, "chaincode", "list", "--installed")
171+
p.setupEnvironment(cmd)
172+
173+
sess, err = helpers.StartSession(cmd, "list", "4;33m")
174+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
175+
EventuallyWithOffset(1, sess, time.Minute).Should(gexec.Exit(0))
176+
Expect(sess).To(gbytes.Say(fmt.Sprintf("Name: %s, Version: %s,", name, version)))
168177
}
169178

170179
func (p *Peer) InstantiateChaincode(name string, version string, orderer string, channel string, args string, policy string) *ginkgomon.Runner {

integration/runner/peer_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ var _ = Describe("Peer", func() {
180180
installCC.ConfigDir = tempDir
181181
installCC.LogLevel = "debug"
182182
installCC.MSPConfigPath = filepath.Join(cryptoDir, "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
183-
installCC.ExecPath = os.Getenv("PATH")
184-
iRunner := installCC.InstallChaincode("mytest", "1.0", "github.com/hyperledger/fabric/integration/chaincode/simple/cmd")
185-
err = execute(iRunner)
186-
Expect(err).NotTo(HaveOccurred())
187-
Expect(iRunner.Err()).To(gbytes.Say(`\QInstalled remotely response:<status:200 payload:"OK" >\E`))
183+
installCC.InstallChaincode("mytest", "1.0", "github.com/hyperledger/fabric/integration/chaincode/simple/cmd")
188184
Expect(peerRunner.Err()).To(gbytes.Say(`\QInstalled Chaincode [mytest] Version [1.0] to peer\E`))
189185

190186
By("list installed chaincode")

integration/world/config.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,7 @@ func (w *World) SetupChannel(d Deployment, peers []string) error {
418418

419419
p.ExecPath = d.Chaincode.ExecPath
420420
p.GoPath = d.Chaincode.GoPath
421-
adminRunner = p.InstallChaincode(d.Chaincode.Name, d.Chaincode.Version, d.Chaincode.Path)
422-
execute(adminRunner)
423-
Expect(adminRunner.Err()).To(gbytes.Say(`\QInstalled remotely response:<status:200 payload:"OK" >\E`))
421+
p.InstallChaincode(d.Chaincode.Name, d.Chaincode.Version, d.Chaincode.Path)
424422
}
425423

426424
p = w.Components.Peer()

0 commit comments

Comments
 (0)