-
Notifications
You must be signed in to change notification settings - Fork 4
/
have_backgrounded.go
48 lines (38 loc) · 1.29 KB
/
have_backgrounded.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
package fake_command_runner_matchers // import "code.cloudfoundry.org/commandrunner/fake_command_runner/matchers"
import (
"fmt"
"os/exec"
"code.cloudfoundry.org/commandrunner/fake_command_runner"
)
func HaveBackgrounded(spec fake_command_runner.CommandSpec) *HaveBackgroundedMatcher {
return &HaveBackgroundedMatcher{Spec: spec}
}
type HaveBackgroundedMatcher struct {
Spec fake_command_runner.CommandSpec
backgrounded []*exec.Cmd
}
func (m *HaveBackgroundedMatcher) Match(actual interface{}) (bool, error) {
runner, ok := actual.(*fake_command_runner.FakeCommandRunner)
if !ok {
return false, fmt.Errorf("Not a fake command runner: %#v.", actual)
}
m.backgrounded = runner.BackgroundedCommands()
matched := false
for _, cmd := range m.backgrounded {
if m.Spec.Matches(cmd) {
matched = true
break
}
}
if matched {
return true, nil
} else {
return false, nil
}
}
func (m *HaveBackgroundedMatcher) FailureMessage(actual interface{}) (message string) {
return fmt.Sprintf("Expected to background:%s\n\nActually backgrounded:%s", prettySpec(m.Spec), prettyCommands(m.backgrounded))
}
func (m *HaveBackgroundedMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return fmt.Sprintf("Expected to not background the following commands:%s", prettySpec(m.Spec))
}