forked from cloudfoundry/libbuildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_test.go
67 lines (54 loc) · 1.41 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
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
package libbuildpack_test
import (
"bytes"
"os/exec"
bp "github.com/cloudfoundry/libbuildpack"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Command", func() {
var (
buffer *bytes.Buffer
exe string
args []string
cmd bp.Command
)
BeforeEach(func() {
buffer = new(bytes.Buffer)
})
Context("valid command", func() {
BeforeEach(func() {
exe = "ls"
args = []string{"-l", "fixtures"}
})
It("runs the command with the output in the right location", func() {
err := cmd.Execute("", buffer, buffer, exe, args...)
Expect(err).To(BeNil())
Expect(buffer.String()).To(ContainSubstring("thing.tgz"))
})
})
Context("changing directory", func() {
BeforeEach(func() {
exe = "pwd"
args = []string{}
})
It("runs the command with the output in the right location", func() {
err := cmd.Execute("fixtures", buffer, buffer, exe, args...)
Expect(err).To(BeNil())
Expect(buffer.String()).To(ContainSubstring("libbuildpack/fixtures"))
})
})
Context("invalid command", func() {
BeforeEach(func() {
exe = "ls"
args = []string{"-l", "not/a/dir"}
})
It("runs the command and returns an eror", func() {
err := cmd.Execute("", buffer, buffer, exe, args...)
Expect(err).NotTo(BeNil())
_, ok := err.(*exec.ExitError)
Expect(ok).To(BeTrue())
Expect(buffer.String()).To(ContainSubstring("No such file or directory"))
})
})
})