Skip to content

Commit

Permalink
Add tests of command creation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomorain committed Jul 4, 2018
1 parent d16bd3b commit 5d55e9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var configPath = ".circleci/config.yml"
// by main.main(). It only needs to happen once to
// the RootCmd.
func Execute() {
command := makeCommands()
command := MakeCommands()
if err := command.Execute(); err != nil {
os.Exit(-1)
}
Expand All @@ -31,7 +31,8 @@ func Execute() {
// This allows us to print to the log at anytime from within the `cmd` package.
var Logger *logger.Logger

func makeCommands() *cobra.Command {
// MakeCommands creates the top level commands
func MakeCommands() *cobra.Command {

rootCmd := &cobra.Command{
Use: "cli",
Expand Down
11 changes: 11 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ package cmd_test
import (
"os/exec"

"github.com/CircleCI-Public/circleci-cli/cmd"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)

var _ = Describe("Root", func() {

Describe("subcommands", func() {

It("can create commands", func() {
commands := cmd.MakeCommands()
Expect(len(commands.Commands())).To(Equal(7))
})

})

Describe("when run with --help", func() {
It("return exit code 0 with help message", func() {
command := exec.Command(pathCLI, "--help")
Expand Down

0 comments on commit 5d55e9c

Please sign in to comment.