forked from vmware-archive/jhanda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_set_test.go
More file actions
130 lines (100 loc) · 3.53 KB
/
Copy pathcommand_set_test.go
File metadata and controls
130 lines (100 loc) · 3.53 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package jhanda_test
import (
"errors"
"github.com/pivotal-cf/jhanda"
"github.com/pivotal-cf/jhanda/internal/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Set", func() {
It("executes the given command", func() {
command := &fakes.Command{}
commandSet := jhanda.CommandSet{
"my-command": command,
}
err := commandSet.Execute("my-command", []string{"--arg-1", "--arg-2"})
Expect(err).NotTo(HaveOccurred())
Expect(command.ExecuteArgsForCall(0)).To(Equal([]string{"--arg-1", "--arg-2"}))
})
Context("when the given command does not exist", func() {
It("returns an error", func() {
commandSet := jhanda.CommandSet{}
err := commandSet.Execute("missing-command", []string{})
Expect(err).To(MatchError("unknown command: missing-command"))
})
})
Context("failure cases", func() {
Context("when the command execution errors", func() {
It("returns an error", func() {
command := &fakes.Command{}
command.ExecuteReturns(errors.New("failed to execute"))
commandSet := jhanda.CommandSet{
"erroring-command": command,
}
err := commandSet.Execute("erroring-command", []string{})
Expect(err).To(MatchError("could not execute \"erroring-command\": failed to execute"))
})
})
})
Describe("when --help is passed as an argument", func() {
It("executes the help for the command", func() {
command := &fakes.Command{}
helpCommand := &fakes.Command{}
commandSet := jhanda.CommandSet{
"my-command": command,
"help": helpCommand,
}
err := commandSet.Execute("my-command", []string{"--arg-1", "--help", "--arg-2"})
Expect(err).NotTo(HaveOccurred())
Expect(command.ExecuteCallCount()).To(Equal(0))
Expect(helpCommand.ExecuteArgsForCall(0)).To(Equal([]string{"my-command"}))
})
})
Describe("when -h is passed as an argument", func() {
It("executes the help for the command", func() {
command := &fakes.Command{}
helpCommand := &fakes.Command{}
commandSet := jhanda.CommandSet{
"my-command": command,
"help": helpCommand,
}
err := commandSet.Execute("my-command", []string{"--arg-1", "-h", "--arg-2"})
Expect(err).NotTo(HaveOccurred())
Expect(command.ExecuteCallCount()).To(Equal(0))
Expect(helpCommand.ExecuteArgsForCall(0)).To(Equal([]string{"my-command"}))
})
})
Describe("when -help is passed as an argument", func() {
It("executes the help for the command", func() {
command := &fakes.Command{}
helpCommand := &fakes.Command{}
commandSet := jhanda.CommandSet{
"my-command": command,
"help": helpCommand,
}
err := commandSet.Execute("my-command", []string{"--arg-1", "-help", "--arg-2"})
Expect(err).NotTo(HaveOccurred())
Expect(command.ExecuteCallCount()).To(Equal(0))
Expect(helpCommand.ExecuteArgsForCall(0)).To(Equal([]string{"my-command"}))
})
})
Describe("Usage", func() {
It("returns the usage information for the given command", func() {
command := &fakes.Command{}
command.UsageReturns(jhanda.Usage{Description: "my-command description"})
commandSet := jhanda.CommandSet{
"my-command": command,
}
usage, err := commandSet.Usage("my-command")
Expect(err).NotTo(HaveOccurred())
Expect(usage).To(Equal(jhanda.Usage{Description: "my-command description"}))
})
Context("when the given command does not exist", func() {
It("returns an error", func() {
commandSet := jhanda.CommandSet{}
_, err := commandSet.Usage("missing-command")
Expect(err).To(MatchError("unknown command: missing-command"))
})
})
})
})