forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_parser_test.go
81 lines (68 loc) · 2.39 KB
/
command_parser_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package command_parser_test
import (
"io/ioutil"
"code.cloudfoundry.org/cli/command/commandfakes"
"code.cloudfoundry.org/cli/command/common"
"code.cloudfoundry.org/cli/util/command_parser"
"code.cloudfoundry.org/cli/util/configv3"
"code.cloudfoundry.org/cli/util/ui"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Command 'Parser'", func() {
var (
pluginUI *ui.UI
)
BeforeEach(func() {
var err error
fakeConfig := new(commandfakes.FakeConfig)
pluginUI, err = ui.NewPluginUI(fakeConfig, ioutil.Discard, ioutil.Discard)
Expect(err).ToNot(HaveOccurred())
})
Describe("unknown command handling", func() {
var (
exitCode int
err error
)
BeforeEach(func() {
parser, newErr := command_parser.NewCommandParser()
Expect(newErr).ToNot(HaveOccurred())
exitCode, err = parser.ParseCommandFromArgs(pluginUI, []string{"howdy"})
})
It("returns an unknown command error with the command name", func() {
unknownCommandErr := err.(command_parser.UnknownCommandError)
Expect(unknownCommandErr.CommandName).To(Equal("howdy"))
Expect(exitCode).To(Equal(0))
})
})
Describe("the verbose flag", func() {
var parser command_parser.CommandParser
BeforeEach(func() {
// Needed because the command-table is a singleton
// and the absence of -v relies on the default value of
// common.Commands.VerboseOrVersion to be false
common.Commands.VerboseOrVersion = false
var err error
parser, err = command_parser.NewCommandParser()
Expect(err).ToNot(HaveOccurred())
})
It("sets the verbose/version flag", func() {
exitCode, err := parser.ParseCommandFromArgs(pluginUI, []string{"-v", "help"})
Expect(exitCode).To(Equal(0))
Expect(err).ToNot(HaveOccurred())
Expect(parser.Config.Flags).To(Equal(configv3.FlagOverride{Verbose: true}))
})
It("sets the verbose/version flag after the command-name", func() {
exitCode, err := parser.ParseCommandFromArgs(pluginUI, []string{"help", "-v"})
Expect(exitCode).To(Equal(0))
Expect(err).ToNot(HaveOccurred())
Expect(parser.Config.Flags).To(Equal(configv3.FlagOverride{Verbose: true}))
})
It("doesn't turn verbose on by default", func() {
exitCode, err := parser.ParseCommandFromArgs(pluginUI, []string{"help"})
Expect(exitCode).To(Equal(0))
Expect(err).ToNot(HaveOccurred())
Expect(parser.Config.Flags).To(Equal(configv3.FlagOverride{Verbose: false}))
})
})
})