vendor: bump ginkgo, gover
Signed-off-by: Casey Callendrello <cdc@redhat.com>
This commit is contained in:
126
vendor/github.com/onsi/gomega/gexec/session.go
generated
vendored
126
vendor/github.com/onsi/gomega/gexec/session.go
generated
vendored
@ -1,13 +1,15 @@
|
||||
/*
|
||||
Package gexec provides support for testing external processes.
|
||||
*/
|
||||
|
||||
// untested sections: 1
|
||||
|
||||
package gexec
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
@ -40,12 +42,12 @@ Start starts the passed-in *exec.Cmd command. It wraps the command in a *gexec.
|
||||
The session pipes the command's stdout and stderr to two *gbytes.Buffers available as properties on the session: session.Out and session.Err.
|
||||
These buffers can be used with the gbytes.Say matcher to match against unread output:
|
||||
|
||||
Ω(session.Out).Should(gbytes.Say("foo-out"))
|
||||
Ω(session.Err).Should(gbytes.Say("foo-err"))
|
||||
Expect(session.Out).Should(gbytes.Say("foo-out"))
|
||||
Expect(session.Err).Should(gbytes.Say("foo-err"))
|
||||
|
||||
In addition, Session satisfies the gbytes.BufferProvider interface and provides the stdout *gbytes.Buffer. This allows you to replace the first line, above, with:
|
||||
|
||||
Ω(session).Should(gbytes.Say("foo-out"))
|
||||
Expect(session).Should(gbytes.Say("foo-out"))
|
||||
|
||||
When outWriter and/or errWriter are non-nil, the session will pipe stdout and/or stderr output both into the session *gybtes.Buffers and to the passed-in outWriter/errWriter.
|
||||
This is useful for capturing the process's output or logging it to screen. In particular, when using Ginkgo it can be convenient to direct output to the GinkgoWriter:
|
||||
@ -57,10 +59,10 @@ This will log output when running tests in verbose mode, but - otherwise - will
|
||||
The session wrapper is responsible for waiting on the *exec.Cmd command. You *should not* call command.Wait() yourself.
|
||||
Instead, to assert that the command has exited you can use the gexec.Exit matcher:
|
||||
|
||||
Ω(session).Should(gexec.Exit())
|
||||
Expect(session).Should(gexec.Exit())
|
||||
|
||||
When the session exits it closes the stdout and stderr gbytes buffers. This will short circuit any
|
||||
Eventuallys waiting fo the buffers to Say something.
|
||||
Eventuallys waiting for the buffers to Say something.
|
||||
*/
|
||||
func Start(command *exec.Cmd, outWriter io.Writer, errWriter io.Writer) (*Session, error) {
|
||||
exited := make(chan struct{})
|
||||
@ -78,11 +80,11 @@ func Start(command *exec.Cmd, outWriter io.Writer, errWriter io.Writer) (*Sessio
|
||||
|
||||
commandOut, commandErr = session.Out, session.Err
|
||||
|
||||
if outWriter != nil && !reflect.ValueOf(outWriter).IsNil() {
|
||||
if outWriter != nil {
|
||||
commandOut = io.MultiWriter(commandOut, outWriter)
|
||||
}
|
||||
|
||||
if errWriter != nil && !reflect.ValueOf(errWriter).IsNil() {
|
||||
if errWriter != nil {
|
||||
commandErr = io.MultiWriter(commandErr, errWriter)
|
||||
}
|
||||
|
||||
@ -92,6 +94,9 @@ func Start(command *exec.Cmd, outWriter io.Writer, errWriter io.Writer) (*Sessio
|
||||
err := command.Start()
|
||||
if err == nil {
|
||||
go session.monitorForExit(exited)
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
trackedSessions = append(trackedSessions, session)
|
||||
}
|
||||
|
||||
return session, err
|
||||
@ -149,11 +154,7 @@ If the command has already exited, Kill returns silently.
|
||||
The session is returned to enable chaining.
|
||||
*/
|
||||
func (s *Session) Kill() *Session {
|
||||
if s.ExitCode() != -1 {
|
||||
return s
|
||||
}
|
||||
s.Command.Process.Kill()
|
||||
return s
|
||||
return s.Signal(syscall.SIGKILL)
|
||||
}
|
||||
|
||||
/*
|
||||
@ -179,17 +180,16 @@ func (s *Session) Terminate() *Session {
|
||||
}
|
||||
|
||||
/*
|
||||
Terminate sends the running command the passed in signal. It does not wait for the process to exit.
|
||||
Signal sends the running command the passed in signal. It does not wait for the process to exit.
|
||||
|
||||
If the command has already exited, Signal returns silently.
|
||||
|
||||
The session is returned to enable chaining.
|
||||
*/
|
||||
func (s *Session) Signal(signal os.Signal) *Session {
|
||||
if s.ExitCode() != -1 {
|
||||
return s
|
||||
if s.processIsAlive() {
|
||||
s.Command.Process.Signal(signal)
|
||||
}
|
||||
s.Command.Process.Signal(signal)
|
||||
return s
|
||||
}
|
||||
|
||||
@ -212,3 +212,95 @@ func (s *Session) monitorForExit(exited chan<- struct{}) {
|
||||
|
||||
close(exited)
|
||||
}
|
||||
|
||||
func (s *Session) processIsAlive() bool {
|
||||
return s.ExitCode() == -1 && s.Command.Process != nil
|
||||
}
|
||||
|
||||
var trackedSessions = []*Session{}
|
||||
var trackedSessionsMutex = &sync.Mutex{}
|
||||
|
||||
/*
|
||||
Kill sends a SIGKILL signal to all the processes started by Run, and waits for them to exit.
|
||||
The timeout specified is applied to each process killed.
|
||||
|
||||
If any of the processes already exited, KillAndWait returns silently.
|
||||
*/
|
||||
func KillAndWait(timeout ...interface{}) {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Kill().Wait(timeout...)
|
||||
}
|
||||
trackedSessions = []*Session{}
|
||||
}
|
||||
|
||||
/*
|
||||
Kill sends a SIGTERM signal to all the processes started by Run, and waits for them to exit.
|
||||
The timeout specified is applied to each process killed.
|
||||
|
||||
If any of the processes already exited, TerminateAndWait returns silently.
|
||||
*/
|
||||
func TerminateAndWait(timeout ...interface{}) {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Terminate().Wait(timeout...)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Kill sends a SIGKILL signal to all the processes started by Run.
|
||||
It does not wait for the processes to exit.
|
||||
|
||||
If any of the processes already exited, Kill returns silently.
|
||||
*/
|
||||
func Kill() {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Kill()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Terminate sends a SIGTERM signal to all the processes started by Run.
|
||||
It does not wait for the processes to exit.
|
||||
|
||||
If any of the processes already exited, Terminate returns silently.
|
||||
*/
|
||||
func Terminate() {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Terminate()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Signal sends the passed in signal to all the processes started by Run.
|
||||
It does not wait for the processes to exit.
|
||||
|
||||
If any of the processes already exited, Signal returns silently.
|
||||
*/
|
||||
func Signal(signal os.Signal) {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Signal(signal)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Interrupt sends the SIGINT signal to all the processes started by Run.
|
||||
It does not wait for the processes to exit.
|
||||
|
||||
If any of the processes already exited, Interrupt returns silently.
|
||||
*/
|
||||
func Interrupt() {
|
||||
trackedSessionsMutex.Lock()
|
||||
defer trackedSessionsMutex.Unlock()
|
||||
for _, session := range trackedSessions {
|
||||
session.Interrupt()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user