syncthing/vendor/github.com/onsi/gomega/gexec/exit_matcher_test.go
Jakob Borg 65aaa607ab Use Go 1.5 vendoring instead of Godeps
Change made by:

- running "gvt fetch" on each of the packages mentioned in
  Godeps/Godeps.json
- `rm -rf Godeps`
- tweaking the build scripts to not mention Godeps
- tweaking the build scripts to test `./lib/...`, `./cmd/...` explicitly
  (to avoid testing vendor)
- tweaking the build scripts to not juggle GOPATH for Godeps and instead
  set GO15VENDOREXPERIMENT.

This also results in some updated packages at the same time I bet.

Building with Go 1.3 and 1.4 still *works* but won't use our vendored
dependencies - the user needs to have the actual packages in their
GOPATH then, which they'll get with a normal "go get". Building with Go
1.6+ will get our vendored dependencies by default even when not using
our build script, which is nice.

By doing this we gain some freedom in that we can pick and choose
manually what to include in vendor, as it's not based on just dependency
analysis of our own code. This is also a risk as we might pick up
dependencies we are unaware of, as the build may work locally with those
packages present in GOPATH. On the other hand the build server will
detect this as it has no packages in it's GOPATH beyond what is included
in the repo.

Recommended tool to manage dependencies is github.com/FiloSottile/gvt.
2016-03-05 21:21:24 +01:00

114 lines
2.6 KiB
Go

package gexec_test
import (
. "github.com/onsi/gomega/gexec"
"os/exec"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type NeverExits struct{}
func (e NeverExits) ExitCode() int {
return -1
}
var _ = Describe("ExitMatcher", func() {
var command *exec.Cmd
var session *Session
BeforeEach(func() {
var err error
command = exec.Command(fireflyPath, "0")
session, err = Start(command, nil, nil)
Ω(err).ShouldNot(HaveOccurred())
})
Describe("when passed something that is an Exiter", func() {
It("should act normally", func() {
failures := InterceptGomegaFailures(func() {
Ω(NeverExits{}).Should(Exit())
})
Ω(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())
})
Ω(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())
failures := InterceptGomegaFailures(func() {
Ω(session).Should(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Eventually(session).Should(Exit())
Ω(session).Should(Exit())
failures = InterceptGomegaFailures(func() {
Ω(session).ShouldNot(Exit())
})
Ω(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))
failures := InterceptGomegaFailures(func() {
Ω(session).Should(Exit(0))
})
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Eventually(session).Should(Exit(0))
Ω(session).Should(Exit(0))
failures = InterceptGomegaFailures(func() {
Ω(session).Should(Exit(1))
})
Ω(failures[0]).Should(ContainSubstring("to match exit code:"))
Ω(session).ShouldNot(Exit(1))
failures = InterceptGomegaFailures(func() {
Ω(session).ShouldNot(Exit(0))
})
Ω(failures[0]).Should(ContainSubstring("not to match exit code:"))
})
})
Describe("bailing out early", func() {
It("should bail out early once the process exits", func() {
t := time.Now()
failures := InterceptGomegaFailures(func() {
Eventually(session).Should(Exit(1))
})
Ω(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))
Ω(failures).Should(HaveLen(1))
})
})
})