Skip to content

Commit

Permalink
Add basic CLI test using Ginkgo/Gomega
Browse files Browse the repository at this point in the history
Test that we can call our CLI binary with the `--help` flag and make
some basic assertions about its output.

I'll commit the new dependencies to `vendor/` in a separate commit to
make the diff easier to read.
  • Loading branch information
dcarley committed Jun 4, 2018
1 parent d7e1768 commit 1db77d6
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 1 deletion.
72 changes: 71 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions circleci_cli_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)

var pathCLI string

var _ = BeforeSuite(func() {
var err error
pathCLI, err = gexec.Build("github.com/circleci/circleci-cli")
Ω(err).ShouldNot(HaveOccurred())
})

var _ = AfterSuite(func() {
gexec.CleanupBuildArtifacts()
})

func TestCircleciCli(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "CircleciCli Suite")
}
23 changes: 23 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main_test

import (
"os/exec"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)

var _ = Describe("Main", func() {
Describe("when run with --help", func() {
It("return exit code 0 with help message", func() {
command := exec.Command(pathCLI, "--help")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Eventually(session.Out).Should(gbytes.Say("Usage:"))
Eventually(session.Err.Contents()).Should(BeEmpty())
})
})
})

0 comments on commit 1db77d6

Please sign in to comment.