forked from heroku/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
35 lines (29 loc) · 1.2 KB
/
command_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main_test
import (
"fmt"
"runtime"
cli "github.com/heroku/cli"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Command", func() {
BeforeEach(func() {
cli.Start("heroku", "version")
})
Describe("parsing", func() {
testcase := func(title string, command *cli.Command, expected string) {
It(title, func() {
Expect(cli.CommandUsage(command)).To(Equal(expected))
})
}
testcase("basic", &cli.Command{Topic: "apps", Command: "info"}, "apps:info")
testcase("topic root command", &cli.Command{Topic: "apps", Command: ""}, "apps")
testcase("with required argument", &cli.Command{Topic: "apps", Command: "info", Args: []cli.Arg{{Name: "foo"}}}, "apps:info FOO")
testcase("with optional argument", &cli.Command{Topic: "apps", Command: "info", Args: []cli.Arg{{Name: "foo", Optional: true}}}, "apps:info [FOO]")
testcase("with multiple arguments", &cli.Command{Topic: "apps", Command: "info", Args: []cli.Arg{{Name: "foo"}, {Name: "bar"}}}, "apps:info FOO BAR")
})
It("shows the version", func() {
version := fmt.Sprintf("heroku-cli/%s (%s-%s) %s ?\n", cli.Version, runtime.GOOS, runtime.GOARCH, runtime.Version())
Expect(stdout()).To(Equal(version))
})
})