Skip to content

Instantly share code, notes, and snippets.

@williammartin
Last active February 13, 2019 19:13
Show Gist options
  • Save williammartin/47d38d76bdfbcbbffcf8caeb42f33e13 to your computer and use it in GitHub Desktop.
Save williammartin/47d38d76bdfbcbbffcf8caeb42f33e13 to your computer and use it in GitHub Desktop.
func BeARunningProcess() types.GomegaMatcher {
return &BeARunningProcessMatcher{}
}
type BeARunningProcessMatcher struct {
actualPid int
}
func (matcher *BeARunningProcessMatcher) Match(actual interface{}) (bool, error) {
pid, ok := actual.(int)
if !ok {
return false, fmt.Errorf("BeARunningProcess must be passed an integer pid. Got\n%s", format.Object(actual, 1))
}
matcher.actualPid = pid
return unix.Kill(pid, unix.Signal(0)) == nil, nil
}
func (matcher *BeARunningProcessMatcher) FailureMessage(actual interface{}) string {
return fmt.Sprintf("Expected pid %d to be a running process", matcher.actualPid)
}
func (matcher *BeARunningProcessMatcher) NegatedFailureMessage(actual interface{}) string {
return fmt.Sprintf("Expected pid %d not to be a running process", matcher.actualPid)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment