Update dependencies

- uses newer version of go-ethereum required for go1.11
This commit is contained in:
Rob Mulholand
2018-09-13 16:14:35 -05:00
parent 939ead0c82
commit 560305f601
2356 changed files with 331656 additions and 128304 deletions
+17 -4
View File
@@ -3,12 +3,14 @@ package gexec
import (
"errors"
"fmt"
"go/build"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"sync"
)
@@ -21,17 +23,18 @@ var (
Build uses go build to compile the package at packagePath. The resulting binary is saved off in a temporary directory.
A path pointing to this binary is returned.
Build uses the $GOPATH set in your environment. It passes the variadic args on to `go build`.
Build uses the $GOPATH set in your environment. If $GOPATH is not set and you are using Go 1.8+,
it will use the default GOPATH instead. It passes the variadic args on to `go build`.
*/
func Build(packagePath string, args ...string) (compiledPath string, err error) {
return doBuild(os.Getenv("GOPATH"), packagePath, nil, args...)
return doBuild(build.Default.GOPATH, packagePath, nil, args...)
}
/*
BuildWithEnvironment is identical to Build but allows you to specify env vars to be set at build time.
*/
func BuildWithEnvironment(packagePath string, env []string, args ...string) (compiledPath string, err error) {
return doBuild(os.Getenv("GOPATH"), packagePath, env, args...)
return doBuild(build.Default.GOPATH, packagePath, env, args...)
}
/*
@@ -41,6 +44,16 @@ func BuildIn(gopath string, packagePath string, args ...string) (compiledPath st
return doBuild(gopath, packagePath, nil, args...)
}
func replaceGoPath(environ []string, newGoPath string) []string {
newEnviron := []string{}
for _, v := range environ {
if !strings.HasPrefix(v, "GOPATH=") {
newEnviron = append(newEnviron, v)
}
}
return append(newEnviron, "GOPATH="+newGoPath)
}
func doBuild(gopath, packagePath string, env []string, args ...string) (compiledPath string, err error) {
tmpDir, err := temporaryDirectory()
if err != nil {
@@ -60,7 +73,7 @@ func doBuild(gopath, packagePath string, env []string, args ...string) (compiled
cmdArgs = append(cmdArgs, "-o", executable, packagePath)
build := exec.Command("go", cmdArgs...)
build.Env = append([]string{"GOPATH=" + gopath}, os.Environ()...)
build.Env = replaceGoPath(os.Environ(), gopath)
build.Env = append(build.Env, env...)
output, err := build.CombinedOutput()
+62 -9
View File
@@ -1,7 +1,10 @@
package gexec_test
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -14,13 +17,13 @@ var _ = Describe(".Build", func() {
Context("when there have been previous calls to Build", func() {
BeforeEach(func() {
_, err := gexec.Build(packagePath)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
})
It("compiles the specified package", func() {
compiledPath, err := gexec.Build(packagePath)
Ω(err).ShouldNot(HaveOccurred())
Ω(compiledPath).Should(BeAnExistingFile())
Expect(err).ShouldNot(HaveOccurred())
Expect(compiledPath).Should(BeAnExistingFile())
})
Context("and CleanupBuildArtifacts has been called", func() {
@@ -31,8 +34,8 @@ var _ = Describe(".Build", func() {
It("compiles the specified package", func() {
var err error
fireflyPath, err = gexec.Build(packagePath)
Ω(err).ShouldNot(HaveOccurred())
Ω(fireflyPath).Should(BeAnExistingFile())
Expect(err).ShouldNot(HaveOccurred())
Expect(fireflyPath).Should(BeAnExistingFile())
})
})
})
@@ -47,13 +50,63 @@ var _ = Describe(".BuildWithEnvironment", func() {
It("compiles the specified package with the specified env vars", func() {
compiledPath, err := gexec.BuildWithEnvironment(packagePath, env)
Ω(err).ShouldNot(HaveOccurred())
Ω(compiledPath).Should(BeAnExistingFile())
Expect(err).ShouldNot(HaveOccurred())
Expect(compiledPath).Should(BeAnExistingFile())
})
It("returns the environment to a good state", func() {
_, err = gexec.BuildWithEnvironment(packagePath, env)
Ω(err).ShouldNot(HaveOccurred())
Ω(os.Environ()).ShouldNot(ContainElement("GOOS=linux"))
Expect(err).ShouldNot(HaveOccurred())
Expect(os.Environ()).ShouldNot(ContainElement("GOOS=linux"))
})
})
var _ = Describe(".BuildIn", func() {
const (
target = "github.com/onsi/gomega/gexec/_fixture/firefly/"
)
var (
original string
gopath string
)
BeforeEach(func() {
var err error
original = os.Getenv("GOPATH")
gopath, err = ioutil.TempDir("", "")
Expect(err).NotTo(HaveOccurred())
copyFile(filepath.Join("_fixture", "firefly", "main.go"), filepath.Join(gopath, "src", target), "main.go")
Expect(os.Setenv("GOPATH", filepath.Join(os.TempDir(), "emptyFakeGopath"))).To(Succeed())
Expect(os.Environ()).To(ContainElement(fmt.Sprintf("GOPATH=%s", filepath.Join(os.TempDir(), "emptyFakeGopath"))))
})
AfterEach(func() {
if original == "" {
Expect(os.Unsetenv("GOPATH")).To(Succeed())
} else {
Expect(os.Setenv("GOPATH", original)).To(Succeed())
}
if gopath != "" {
os.RemoveAll(gopath)
}
})
It("appends the gopath env var", func() {
_, err := gexec.BuildIn(gopath, target)
Expect(err).NotTo(HaveOccurred())
})
It("resets GOPATH to its original value", func() {
_, err := gexec.BuildIn(gopath, target)
Expect(err).NotTo(HaveOccurred())
Expect(os.Getenv("GOPATH")).To(Equal(filepath.Join(os.TempDir(), "emptyFakeGopath")))
})
})
func copyFile(source, directory, basename string) {
Expect(os.MkdirAll(directory, 0755)).To(Succeed())
content, err := ioutil.ReadFile(source)
Expect(err).NotTo(HaveOccurred())
Expect(ioutil.WriteFile(filepath.Join(directory, basename), content, 0644)).To(Succeed())
}
+1 -1
View File
@@ -9,7 +9,7 @@ import (
/*
The Exit matcher operates on a session:
Ω(session).Should(Exit(<optional status code>))
Expect(session).Should(Exit(<optional status code>))
Exit passes if the session has already exited.
+25 -24
View File
@@ -1,10 +1,11 @@
package gexec_test
import (
. "github.com/onsi/gomega/gexec"
"os/exec"
"time"
. "github.com/onsi/gomega/gexec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@@ -23,79 +24,79 @@ var _ = Describe("ExitMatcher", func() {
var err error
command = exec.Command(fireflyPath, "0")
session, err = Start(command, nil, nil)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
})
Describe("when passed something that is an Exiter", func() {
It("should act normally", func() {
failures := InterceptGomegaFailures(func() {
Ω(NeverExits{}).Should(Exit())
Expect(NeverExits{}).Should(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Expect(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
})
})
Describe("when passed something that is not an Exiter", func() {
It("should error", func() {
failures := InterceptGomegaFailures(func() {
Ω("aardvark").Should(Exit())
Expect("aardvark").Should(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Exit must be passed a gexec.Exiter"))
Expect(failures[0]).Should(ContainSubstring("Exit must be passed a gexec.Exiter"))
})
})
Context("with no exit code", func() {
It("should say the right things when it fails", func() {
Ω(session).ShouldNot(Exit())
Expect(session).ShouldNot(Exit())
failures := InterceptGomegaFailures(func() {
Ω(session).Should(Exit())
Expect(session).Should(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Expect(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Eventually(session).Should(Exit())
Ω(session).Should(Exit())
Expect(session).Should(Exit())
failures = InterceptGomegaFailures(func() {
Ω(session).ShouldNot(Exit())
Expect(session).ShouldNot(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Expected process not to exit. It did."))
Expect(failures[0]).Should(ContainSubstring("Expected process not to exit. It did."))
})
})
Context("with an exit code", func() {
It("should say the right things when it fails", func() {
Ω(session).ShouldNot(Exit(0))
Ω(session).ShouldNot(Exit(1))
Expect(session).ShouldNot(Exit(0))
Expect(session).ShouldNot(Exit(1))
failures := InterceptGomegaFailures(func() {
Ω(session).Should(Exit(0))
Expect(session).Should(Exit(0))
})
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Expect(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Eventually(session).Should(Exit(0))
Ω(session).Should(Exit(0))
Expect(session).Should(Exit(0))
failures = InterceptGomegaFailures(func() {
Ω(session).Should(Exit(1))
Expect(session).Should(Exit(1))
})
Ω(failures[0]).Should(ContainSubstring("to match exit code:"))
Expect(failures[0]).Should(ContainSubstring("to match exit code:"))
Ω(session).ShouldNot(Exit(1))
Expect(session).ShouldNot(Exit(1))
failures = InterceptGomegaFailures(func() {
Ω(session).ShouldNot(Exit(0))
Expect(session).ShouldNot(Exit(0))
})
Ω(failures[0]).Should(ContainSubstring("not to match exit code:"))
Expect(failures[0]).Should(ContainSubstring("not to match exit code:"))
})
})
@@ -106,8 +107,8 @@ var _ = Describe("ExitMatcher", func() {
failures := InterceptGomegaFailures(func() {
Eventually(session).Should(Exit(1))
})
Ω(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))
Ω(failures).Should(HaveLen(1))
Expect(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))
Expect(failures).Should(HaveLen(1))
})
})
})
+1 -1
View File
@@ -14,7 +14,7 @@ func TestGexec(t *testing.T) {
BeforeSuite(func() {
var err error
fireflyPath, err = gexec.Build("./_fixture/firefly")
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
})
AfterSuite(func() {
+1 -1
View File
@@ -28,7 +28,7 @@ var _ = Describe("PrefixedWriter", func() {
writer.Write([]byte("\ntuv\nwx"))
writer.Write([]byte("yz\n\n"))
Ω(buffer.String()).Should(Equal(`[p]abcdef
Expect(buffer.String()).Should(Equal(`[p]abcdef
[p]hij
[p]
[p]
+13 -15
View File
@@ -7,7 +7,6 @@ import (
"io"
"os"
"os/exec"
"reflect"
"sync"
"syscall"
@@ -40,12 +39,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,7 +56,7 @@ 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 for the buffers to Say something.
@@ -78,11 +77,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)
}
@@ -152,11 +151,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)
}
/*
@@ -189,10 +184,9 @@ 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
}
@@ -216,6 +210,10 @@ 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{}
+80 -95
View File
@@ -1,6 +1,8 @@
package gexec_test
import (
"io"
"io/ioutil"
"os/exec"
"syscall"
"time"
@@ -16,7 +18,7 @@ var _ = Describe("Session", func() {
var command *exec.Cmd
var session *Session
var outWriter, errWriter *Buffer
var outWriter, errWriter io.Writer
BeforeEach(func() {
outWriter = nil
@@ -27,12 +29,12 @@ var _ = Describe("Session", func() {
command = exec.Command(fireflyPath)
var err error
session, err = Start(command, outWriter, errWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
})
Context("running a command", func() {
It("should start the process", func() {
Ω(command.Process).ShouldNot(BeNil())
Expect(command.Process).ShouldNot(BeNil())
})
It("should wrap the process's stdout and stderr with gbytes buffers", func(done Done) {
@@ -60,36 +62,35 @@ var _ = Describe("Session", func() {
Describe("providing the exit code", func() {
It("should provide the app's exit code", func() {
Ω(session.ExitCode()).Should(Equal(-1))
Expect(session.ExitCode()).Should(Equal(-1))
Eventually(session).Should(Exit())
Ω(session.ExitCode()).Should(BeNumerically(">=", 0))
Ω(session.ExitCode()).Should(BeNumerically("<", 3))
Expect(session.ExitCode()).Should(BeNumerically(">=", 0))
Expect(session.ExitCode()).Should(BeNumerically("<", 3))
})
})
Describe("wait", func() {
It("should wait till the command exits", func() {
Ω(session.ExitCode()).Should(Equal(-1))
Ω(session.Wait().ExitCode()).Should(BeNumerically(">=", 0))
Ω(session.Wait().ExitCode()).Should(BeNumerically("<", 3))
Expect(session.ExitCode()).Should(Equal(-1))
Expect(session.Wait().ExitCode()).Should(BeNumerically(">=", 0))
Expect(session.Wait().ExitCode()).Should(BeNumerically("<", 3))
})
})
Describe("exited", func() {
It("should close when the command exits", func() {
Eventually(session.Exited).Should(BeClosed())
Ω(session.ExitCode()).ShouldNot(Equal(-1))
Expect(session.ExitCode()).ShouldNot(Equal(-1))
})
})
Describe("kill", func() {
It("should kill the command and don't wait for it to exit", func() {
It("should kill the command", func() {
session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session.Kill()
Ω(session).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session).Should(Exit(128 + 9))
})
})
@@ -97,10 +98,9 @@ var _ = Describe("Session", func() {
Describe("interrupt", func() {
It("should interrupt the command", func() {
session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session.Interrupt()
Ω(session).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session).Should(Exit(128 + 2))
})
})
@@ -108,10 +108,9 @@ var _ = Describe("Session", func() {
Describe("terminate", func() {
It("should terminate the command", func() {
session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session.Terminate()
Ω(session).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session).Should(Exit(128 + 15))
})
})
@@ -119,12 +118,18 @@ var _ = Describe("Session", func() {
Describe("signal", func() {
It("should send the signal to the command", func() {
session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session.Signal(syscall.SIGABRT)
Ω(session).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session).Should(Exit(128 + 6))
})
It("should ignore sending a signal if the command did not start", func() {
session, err := Start(exec.Command("notexisting"), GinkgoWriter, GinkgoWriter)
Expect(err).To(HaveOccurred())
Expect(func() { session.Signal(syscall.SIGUSR1) }).NotTo(Panic())
})
})
Context("tracking sessions", func() {
@@ -135,13 +140,13 @@ var _ = Describe("Session", func() {
Describe("kill", func() {
It("should kill all the started sessions", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
Kill()
@@ -150,25 +155,15 @@ var _ = Describe("Session", func() {
Eventually(session3).Should(Exit(128 + 9))
})
It("should not wait for exit", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Kill()
Ω(session1).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session1).Should(Exit(128 + 9))
})
It("should not track unstarted sessions", func() {
_, err := Start(exec.Command("does not exist", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).Should(HaveOccurred())
Expect(err).Should(HaveOccurred())
session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
Kill()
@@ -181,31 +176,31 @@ var _ = Describe("Session", func() {
Describe("killAndWait", func() {
It("should kill all the started sessions and wait for them to finish", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
KillAndWait()
Ω(session1).Should(Exit(128+9), "Should have exited")
Ω(session2).Should(Exit(128+9), "Should have exited")
Ω(session3).Should(Exit(128+9), "Should have exited")
Expect(session1).Should(Exit(128+9), "Should have exited")
Expect(session2).Should(Exit(128+9), "Should have exited")
Expect(session3).Should(Exit(128+9), "Should have exited")
})
})
Describe("terminate", func() {
It("should terminate all the started sessions", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
Terminate()
@@ -213,46 +208,37 @@ var _ = Describe("Session", func() {
Eventually(session2).Should(Exit(128 + 15))
Eventually(session3).Should(Exit(128 + 15))
})
It("should not wait for exit", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Terminate()
Ω(session1).ShouldNot(Exit(), "Should not exit immediately...")
})
})
Describe("terminateAndWait", func() {
It("should terminate all the started sessions, and wait for them to exit", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
TerminateAndWait()
Ω(session1).Should(Exit(128+15), "Should have exited")
Ω(session2).Should(Exit(128+15), "Should have exited")
Ω(session3).Should(Exit(128+15), "Should have exited")
Expect(session1).Should(Exit(128+15), "Should have exited")
Expect(session2).Should(Exit(128+15), "Should have exited")
Expect(session3).Should(Exit(128+15), "Should have exited")
})
})
Describe("signal", func() {
It("should signal all the started sessions", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
Signal(syscall.SIGABRT)
@@ -260,27 +246,18 @@ var _ = Describe("Session", func() {
Eventually(session2).Should(Exit(128 + 6))
Eventually(session3).Should(Exit(128 + 6))
})
It("should not wait", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Signal(syscall.SIGABRT)
Ω(session1).ShouldNot(Exit(), "Should not exit immediately...")
})
})
Describe("interrupt", func() {
It("should interrupt all the started sessions, and not wait", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session2, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
session3, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).ShouldNot(HaveOccurred())
Interrupt()
@@ -288,15 +265,6 @@ var _ = Describe("Session", func() {
Eventually(session2).Should(Exit(128 + 2))
Eventually(session3).Should(Exit(128 + 2))
})
It("should not wait", func() {
session1, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
Interrupt()
Ω(session1).ShouldNot(Exit(), "Should not exit immediately...")
})
})
})
@@ -304,10 +272,10 @@ var _ = Describe("Session", func() {
It("should close the buffers", func() {
Eventually(session).Should(Exit())
Ω(session.Out.Closed()).Should(BeTrue())
Ω(session.Err.Closed()).Should(BeTrue())
Expect(session.Out.Closed()).Should(BeTrue())
Expect(session.Err.Closed()).Should(BeTrue())
Ω(session.Out).Should(Say("We've done the impossible, and that makes us mighty"))
Expect(session.Out).Should(Say("We've done the impossible, and that makes us mighty"))
})
var So = It
@@ -317,35 +285,52 @@ var _ = Describe("Session", func() {
failures := InterceptGomegaFailures(func() {
Eventually(session).Should(Say("blah blah blah blah blah"))
})
Ω(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))
Ω(failures).Should(HaveLen(1))
Expect(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))
Expect(failures).Should(HaveLen(1))
})
})
Context("when wrapping out and err", func() {
var (
outWriterBuffer, errWriterBuffer *Buffer
)
BeforeEach(func() {
outWriter = NewBuffer()
errWriter = NewBuffer()
outWriterBuffer = NewBuffer()
outWriter = outWriterBuffer
errWriterBuffer = NewBuffer()
errWriter = errWriterBuffer
})
It("should route to both the provided writers and the gbytes buffers", func() {
Eventually(session.Out).Should(Say("We've done the impossible, and that makes us mighty"))
Eventually(session.Err).Should(Say("Ah, curse your sudden but inevitable betrayal!"))
Ω(outWriter.Contents()).Should(ContainSubstring("We've done the impossible, and that makes us mighty"))
Ω(errWriter.Contents()).Should(ContainSubstring("Ah, curse your sudden but inevitable betrayal!"))
Expect(outWriterBuffer.Contents()).Should(ContainSubstring("We've done the impossible, and that makes us mighty"))
Expect(errWriterBuffer.Contents()).Should(ContainSubstring("Ah, curse your sudden but inevitable betrayal!"))
Eventually(session).Should(Exit())
Ω(outWriter.Contents()).Should(Equal(session.Out.Contents()))
Ω(errWriter.Contents()).Should(Equal(session.Err.Contents()))
Expect(outWriterBuffer.Contents()).Should(Equal(session.Out.Contents()))
Expect(errWriterBuffer.Contents()).Should(Equal(session.Err.Contents()))
})
Context("when discarding the output of the command", func() {
BeforeEach(func() {
outWriter = ioutil.Discard
errWriter = ioutil.Discard
})
It("executes succesfuly", func() {
Eventually(session).Should(Exit())
})
})
})
Describe("when the command fails to start", func() {
It("should return an error", func() {
_, err := Start(exec.Command("agklsjdfas"), nil, nil)
Ω(err).Should(HaveOccurred())
Expect(err).Should(HaveOccurred())
})
})
})