gexec.Exit() takes a gexec.Exiter
Signed-off-by: Eric Malm <emalm@pivotallabs.com>
Ted Young authored 9 years ago
Eric Malm committed 9 years ago
36 | 36 |
actualExitCode int
|
37 | 37 |
}
|
38 | 38 |
|
|
39 |
type Exiter interface {
|
|
40 |
ExitCode() int
|
|
41 |
}
|
|
42 |
|
39 | 43 |
func (m *exitMatcher) Match(actual interface{}) (success bool, err error) {
|
40 | |
session, ok := actual.(*Session)
|
|
44 |
exiter, ok := actual.(Exiter)
|
41 | 45 |
if !ok {
|
42 | |
return false, fmt.Errorf("Exit must be passed a gexit session. Got:\n%s", format.Object(actual, 1))
|
|
46 |
return false, fmt.Errorf("Exit must be passed a gexec.Exiter (Missing method ExitCode() int) Got:\n%s", format.Object(actual, 1))
|
43 | 47 |
}
|
44 | 48 |
|
45 | |
m.actualExitCode = session.ExitCode()
|
|
49 |
m.actualExitCode = exiter.ExitCode()
|
46 | 50 |
|
47 | 51 |
if m.actualExitCode == -1 {
|
48 | 52 |
return false, nil
|
7 | 7 |
. "github.com/onsi/ginkgo"
|
8 | 8 |
. "github.com/onsi/gomega"
|
9 | 9 |
)
|
|
10 |
|
|
11 |
type NeverExits struct{}
|
|
12 |
|
|
13 |
func (e NeverExits) ExitCode() int {
|
|
14 |
return -1
|
|
15 |
}
|
10 | 16 |
|
11 | 17 |
var _ = Describe("ExitMatcher", func() {
|
12 | 18 |
var command *exec.Cmd
|
|
19 | 25 |
Ω(err).ShouldNot(HaveOccurred())
|
20 | 26 |
})
|
21 | 27 |
|
22 | |
Describe("when passed something that is not a session", func() {
|
|
28 |
Describe("when passed something that is an Exiter", func() {
|
|
29 |
It("should act normally", func() {
|
|
30 |
failures := interceptFailures(func() {
|
|
31 |
Ω(NeverExits{}).Should(Exit())
|
|
32 |
})
|
|
33 |
|
|
34 |
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
|
|
35 |
})
|
|
36 |
})
|
|
37 |
|
|
38 |
Describe("when passed something that is not an Exiter", func() {
|
23 | 39 |
It("should error", func() {
|
24 | 40 |
failures := interceptFailures(func() {
|
25 | 41 |
Ω("aardvark").Should(Exit())
|
26 | 42 |
})
|
27 | 43 |
|
28 | |
Ω(failures[0]).Should(ContainSubstring("Exit must be passed a gexit session"))
|
|
44 |
Ω(failures[0]).Should(ContainSubstring("Exit must be passed a gexec.Exiter"))
|
29 | 45 |
})
|
30 | 46 |
})
|
31 | 47 |
|