Skip to content

Commit 90ff463

Browse files
committed
[FAB-9232] Add Cryptogen for Integration Test
Adds the cryptogen component for integration tests using ginkgo. Change-Id: Ia4e102f51f4d62621d834a5607450addf4ca2b59 Signed-off-by: Latitia M Haskins <latitia.haskins@gmail.com>
1 parent d5e9f9b commit 90ff463

File tree

9 files changed

+415
-4
lines changed

9 files changed

+415
-4
lines changed

Gopkg.lock

+7-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/runner/cryptogen.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright IBM Corp All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package runner
8+
9+
import (
10+
"os/exec"
11+
"github.com/tedsuo/ifrit/ginkgomon"
12+
)
13+
14+
// Cryptogen creates runners that call cryptogen functions.
15+
type Cryptogen struct {
16+
// The location of the cryptogen executable
17+
Path string
18+
// The location of the config file
19+
Config string
20+
// The output directory
21+
Output string
22+
}
23+
24+
// Generate uses cryptogen to generate cryptographic material for fabric.
25+
func (c *Cryptogen) Generate(extraArgs ...string) *ginkgomon.Runner {
26+
return ginkgomon.New(ginkgomon.Config{
27+
Command: exec.Command(
28+
c.Path,
29+
append([]string{
30+
"generate",
31+
"--config", c.Config,
32+
"--output", c.Output,
33+
}, extraArgs...)...,
34+
),
35+
})
36+
}

integration/runner/cryptogen_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright IBM Corp All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package runner_test
8+
9+
import (
10+
"io/ioutil"
11+
"os"
12+
"path/filepath"
13+
14+
"github.com/hyperledger/fabric/integration/runner"
15+
. "github.com/onsi/ginkgo"
16+
. "github.com/onsi/gomega"
17+
18+
"github.com/tedsuo/ifrit"
19+
)
20+
21+
var _ = Describe("CryptoGen", func() {
22+
var cryptogen *runner.Cryptogen
23+
var tempDir string
24+
25+
BeforeEach(func() {
26+
var err error
27+
tempDir, err = ioutil.TempDir("", "crypto")
28+
Expect(err).NotTo(HaveOccurred())
29+
30+
cryptogen = &runner.Cryptogen{
31+
Path: components.Paths["cryptogen"],
32+
Config: filepath.Join("testdata", "cryptogen-config.yaml"),
33+
Output: tempDir,
34+
}
35+
})
36+
37+
AfterEach(func() {
38+
os.RemoveAll(tempDir)
39+
})
40+
41+
Describe("Generate", func() {
42+
It("creates a runner that calls cryptogen", func() {
43+
cgRunner := cryptogen.Generate()
44+
process := ifrit.Invoke(cgRunner)
45+
Eventually(process.Ready()).Should(BeClosed())
46+
Eventually(process.Wait()).Should(Receive(BeNil()))
47+
Expect(cgRunner.ExitCode()).To(Equal(0))
48+
49+
Expect(filepath.Join(tempDir, "ordererOrganizations")).To(BeADirectory())
50+
Expect(filepath.Join(tempDir, "peerOrganizations")).To(BeADirectory())
51+
})
52+
53+
Context("when cryptogen fails", func() {
54+
It("returns an error", func() {
55+
cgRunner := cryptogen.Generate("bogus")
56+
process := ifrit.Invoke(cgRunner)
57+
Eventually(process.Wait()).Should(Receive(HaveOccurred()))
58+
})
59+
})
60+
})
61+
62+
})

integration/runner/runner_suite_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ SPDX-License-Identifier: Apache-2.0
77
package runner_test
88

99
import (
10+
"encoding/json"
11+
12+
"github.com/hyperledger/fabric/integration/world"
1013
. "github.com/onsi/ginkgo"
1114
. "github.com/onsi/gomega"
1215

@@ -17,3 +20,25 @@ func TestRunner(t *testing.T) {
1720
RegisterFailHandler(Fail)
1821
RunSpecs(t, "Runner Suite")
1922
}
23+
24+
var (
25+
components *world.Components
26+
)
27+
28+
var _ = SynchronizedBeforeSuite(func() []byte {
29+
components = &world.Components{}
30+
components.Build()
31+
32+
payload, err := json.Marshal(components)
33+
Expect(err).NotTo(HaveOccurred())
34+
35+
return payload
36+
}, func(payload []byte) {
37+
err := json.Unmarshal(payload, &components)
38+
Expect(err).NotTo(HaveOccurred())
39+
})
40+
41+
var _ = SynchronizedAfterSuite(func() {
42+
}, func() {
43+
components.Cleanup()
44+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright IBM Corp. All Rights Reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
OrdererOrgs:
6+
- Name: Orderer
7+
Domain: example.com
8+
CA:
9+
Country: US
10+
Province: California
11+
Locality: San Francisco
12+
Specs:
13+
- Hostname: orderer
14+
PeerOrgs:
15+
- Name: Org1
16+
Domain: org1.example.com
17+
EnableNodeOUs: true
18+
CA:
19+
Country: US
20+
Province: California
21+
Locality: San Francisco
22+
Template:
23+
Count: 2
24+
Users:
25+
Count: 1
26+
- Name: Org2
27+
Domain: org2.example.com
28+
EnableNodeOUs: true
29+
CA:
30+
Country: US
31+
Province: California
32+
Locality: San Francisco
33+
Template:
34+
Count: 2
35+
Users:
36+
Count: 1

integration/world/components.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright IBM Corp All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package world
8+
9+
import (
10+
"os"
11+
12+
"github.com/hyperledger/fabric/integration/runner"
13+
. "github.com/onsi/gomega"
14+
"github.com/onsi/gomega/gexec"
15+
)
16+
17+
type Components struct {
18+
Paths map[string]string
19+
}
20+
21+
func (c *Components) Build() {
22+
if c.Paths == nil {
23+
c.Paths = map[string]string{}
24+
}
25+
cryptogen, err := gexec.Build("github.com/hyperledger/fabric/common/tools/cryptogen")
26+
Expect(err).NotTo(HaveOccurred())
27+
c.Paths["cryptogen"] = cryptogen
28+
}
29+
30+
func (c *Components) Cleanup() {
31+
for _, path := range c.Paths {
32+
err := os.Remove(path)
33+
Expect(err).NotTo(HaveOccurred())
34+
}
35+
}
36+
37+
func (c *Components) Cryptogen() *runner.Cryptogen {
38+
return &runner.Cryptogen{
39+
Path: c.Paths["cryptogen"],
40+
}
41+
}

vendor/github.com/tedsuo/ifrit/LICENSE

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)