forked from cloudfoundry/credhub-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
52 lines (45 loc) · 1.7 KB
/
main_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
package main_test
import (
"fmt"
"os/exec"
"runtime"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("main", func() {
Context("when no command is provided", func() {
It("prints help and exits", func() {
cmd := exec.Command(commandPath)
session, err := Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(Exit(1))
// The command name is printed the same as the credhub cli binary file name
Expect(session.Err).To(Say(fmt.Sprintf("%s \\[OPTIONS\\] \\[command\\]", commandName)))
})
})
Context("when extra arguments are provided", func() {
It("prints help and exits", func() {
cmd := exec.Command(commandPath, "version", "this")
session, err := Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(Exit(1))
Expect(session.Err).To(Say("Usage:"))
})
})
Context("when a prepended / is used in the argument", func() {
BeforeEach(func() {
if runtime.GOOS != "windows" {
Skip("only run test on windows")
}
})
It("raises expected error for windows, otherwise does not raise an error", func() {
cmd := exec.Command(commandPath, "get", "--name", "/foo/bar")
session, err := Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(Exit(1))
Expect(session.Err).To(Say("Flag parsing in windows will interpret any argument with a '/' prefix as an option. Please remove any prepended '/' from flag arguments as it may be causing the following error: expected argument for flag `/n, /name', but got option `/foo/bar'"))
})
})
})