Skip to content

Commit

Permalink
[FAB-10232] Setup and teardown in Before/AfterEach
Browse files Browse the repository at this point in the history
Change-Id: I9487d30e8d961dd114f4fb1b76d30c5f36c0283b
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm committed May 20, 2018
1 parent 29e4b65 commit 9d3f15b
Showing 1 changed file with 48 additions and 36 deletions.
84 changes: 48 additions & 36 deletions integration/runner/idemixgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ import (
. "github.com/onsi/gomega"

"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/ginkgomon"
)

var _ = Describe("Idemixgen", func() {
var idemixgen *runner.Idemixgen
var tempDir string
var err error
tempDir, err = ioutil.TempDir("", "idemix")
if err != nil {
Fail("Failed to create test directory")
}
var (
idemixgen *runner.Idemixgen
tempDir string
)

BeforeEach(func() {
var err error
tempDir, err = ioutil.TempDir("", "idemix")
Expect(err).NotTo(HaveOccurred())

idemixgen = &runner.Idemixgen{
Path: components.Paths["idemixgen"],
EnrollID: "IdeMixUser1",
Expand All @@ -36,43 +38,53 @@ var _ = Describe("Idemixgen", func() {
}
})

It("creates a runner that calls idemixgen ca-keygen", func() {
igRunner := idemixgen.CAKeyGen()
process := ifrit.Invoke(igRunner)
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Wait()).Should(Receive(BeNil()))
Expect(igRunner.ExitCode()).To(Equal(0))

Expect(filepath.Join(tempDir, "ca")).To(BeADirectory())
Expect(filepath.Join(tempDir, "msp")).To(BeADirectory())
AfterEach(func() {
os.RemoveAll(tempDir)
})

Context("when idemixgen ca-keygen fails", func() {
It("returns an error", func() {
igRunner := idemixgen.CAKeyGen("bogus")
Describe("CAKeyGen", func() {
It("creates a runner that calls idemixgen ca-keygen", func() {
igRunner := idemixgen.CAKeyGen()
process := ifrit.Invoke(igRunner)
Eventually(process.Wait()).Should(Receive(HaveOccurred()))
})
})
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Wait()).Should(Receive(BeNil()))
Expect(igRunner.ExitCode()).To(Equal(0))

It("creates a runner that calls idemixgen signerconfig", func() {
igRunner := idemixgen.SignerConfig()
process := ifrit.Invoke(igRunner)
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Wait()).Should(Receive(BeNil()))
Expect(igRunner.ExitCode()).To(Equal(0))
Expect(filepath.Join(tempDir, "ca")).To(BeADirectory())
Expect(filepath.Join(tempDir, "msp")).To(BeADirectory())
})

Expect(filepath.Join(tempDir, "user")).To(BeADirectory())
Context("when idemixgen ca-keygen fails", func() {
It("returns an error", func() {
igRunner := idemixgen.CAKeyGen("bogus")
process := ifrit.Invoke(igRunner)
Eventually(process.Wait()).Should(Receive(HaveOccurred()))
})
})
})

Context("when idemixgen signerconfig fails", func() {
It("returns an error", func() {
igRunner := idemixgen.SignerConfig("bogus")
Describe("SignerConfig", func() {
BeforeEach(func() {
keygen := ginkgomon.Invoke(idemixgen.CAKeyGen())
Eventually(keygen.Wait()).Should(Receive(BeNil()))
})

It("creates a runner that calls idemixgen signerconfig", func() {
igRunner := idemixgen.SignerConfig()
process := ifrit.Invoke(igRunner)
Eventually(process.Wait()).Should(Receive(HaveOccurred()))
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Wait()).Should(Receive(BeNil()))
Expect(igRunner.ExitCode()).To(Equal(0))

Expect(filepath.Join(tempDir, "user")).To(BeADirectory())
})
})

// cleanup
os.RemoveAll(tempDir)
Context("when idemixgen signerconfig fails", func() {
It("returns an error", func() {
igRunner := idemixgen.SignerConfig("bogus")
process := ifrit.Invoke(igRunner)
Eventually(process.Wait()).Should(Receive(HaveOccurred()))
})
})
})
})

0 comments on commit 9d3f15b

Please sign in to comment.