Last active
February 13, 2019 19:13
-
-
Save williammartin/47d38d76bdfbcbbffcf8caeb42f33e13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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