vendor: Mega update all dependencies

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
Jakob Borg
2017-04-05 14:34:41 +00:00
parent 49c1527724
commit a1bcc15458
1354 changed files with 55066 additions and 797850 deletions

View File

@@ -1,36 +0,0 @@
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
)
var outQuote = "We've done the impossible, and that makes us mighty."
var errQuote = "Ah, curse your sudden but inevitable betrayal!"
var randomQuotes = []string{
"Can we maybe vote on the whole murdering people issue?",
"I swear by my pretty floral bonnet, I will end you.",
"My work's illegal, but at least it's honest.",
}
func main() {
fmt.Fprintln(os.Stdout, outQuote)
fmt.Fprintln(os.Stderr, errQuote)
randomIndex := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(randomQuotes))
time.Sleep(100 * time.Millisecond)
fmt.Fprintln(os.Stdout, randomQuotes[randomIndex])
if len(os.Args) == 2 {
exitCode, _ := strconv.Atoi(os.Args[1])
os.Exit(exitCode)
} else {
os.Exit(randomIndex)
}
}

View File

@@ -9,9 +9,13 @@ import (
"path"
"path/filepath"
"runtime"
"sync"
)
var tmpDir string
var (
mu sync.Mutex
tmpDir string
)
/*
Build uses go build to compile the package at packagePath. The resulting binary is saved off in a temporary directory.
@@ -20,13 +24,24 @@ 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`.
*/
func Build(packagePath string, args ...string) (compiledPath string, err error) {
return BuildIn(os.Getenv("GOPATH"), packagePath, args...)
return doBuild(os.Getenv("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...)
}
/*
BuildIn is identical to Build but allows you to specify a custom $GOPATH (the first argument).
*/
func BuildIn(gopath string, packagePath string, args ...string) (compiledPath string, err error) {
return doBuild(gopath, packagePath, nil, args...)
}
func doBuild(gopath, packagePath string, env []string, args ...string) (compiledPath string, err error) {
tmpDir, err := temporaryDirectory()
if err != nil {
return "", err
@@ -46,6 +61,7 @@ func BuildIn(gopath string, packagePath string, args ...string) (compiledPath st
build := exec.Command("go", cmdArgs...)
build.Env = append([]string{"GOPATH=" + gopath}, os.Environ()...)
build.Env = append(build.Env, env...)
output, err := build.CombinedOutput()
if err != nil {
@@ -60,13 +76,18 @@ You should call CleanupBuildArtifacts before your test ends to clean up any temp
gexec. In Ginkgo this is typically done in an AfterSuite callback.
*/
func CleanupBuildArtifacts() {
mu.Lock()
defer mu.Unlock()
if tmpDir != "" {
os.RemoveAll(tmpDir)
tmpDir = ""
}
}
func temporaryDirectory() (string, error) {
var err error
mu.Lock()
defer mu.Unlock()
if tmpDir == "" {
tmpDir, err = ioutil.TempDir("", "gexec_artifacts")
if err != nil {

View File

@@ -1,113 +0,0 @@
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))
})
})
})

View File

@@ -1,26 +0,0 @@
package gexec_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"testing"
)
var fireflyPath string
func TestGexec(t *testing.T) {
BeforeSuite(func() {
var err error
fireflyPath, err = gexec.Build("./_fixture/firefly")
Ω(err).ShouldNot(HaveOccurred())
})
AfterSuite(func() {
gexec.CleanupBuildArtifacts()
})
RegisterFailHandler(Fail)
RunSpecs(t, "Gexec Suite")
}

View File

@@ -1,43 +0,0 @@
package gexec_test
import (
"bytes"
. "github.com/onsi/gomega/gexec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("PrefixedWriter", func() {
var buffer *bytes.Buffer
var writer *PrefixedWriter
BeforeEach(func() {
buffer = &bytes.Buffer{}
writer = NewPrefixedWriter("[p]", buffer)
})
It("should emit the prefix on newlines", func() {
writer.Write([]byte("abc"))
writer.Write([]byte("def\n"))
writer.Write([]byte("hij\n"))
writer.Write([]byte("\n\n"))
writer.Write([]byte("klm\n\nnop"))
writer.Write([]byte(""))
writer.Write([]byte("qrs"))
writer.Write([]byte("\ntuv\nwx"))
writer.Write([]byte("yz\n\n"))
Ω(buffer.String()).Should(Equal(`[p]abcdef
[p]hij
[p]
[p]
[p]klm
[p]
[p]nopqrs
[p]tuv
[p]wxyz
[p]
`))
})
})

View File

@@ -60,7 +60,7 @@ Instead, to assert that the command has exited you can use the gexec.Exit matche
Ω(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{})
@@ -92,6 +92,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
@@ -179,7 +182,7 @@ 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.
@@ -212,3 +215,91 @@ func (s *Session) monitorForExit(exited chan<- struct{}) {
close(exited)
}
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()
}
}

View File

@@ -1,178 +0,0 @@
package gexec_test
import (
"os/exec"
"syscall"
"time"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Session", func() {
var command *exec.Cmd
var session *Session
var outWriter, errWriter *Buffer
BeforeEach(func() {
outWriter = nil
errWriter = nil
})
JustBeforeEach(func() {
command = exec.Command(fireflyPath)
var err error
session, err = Start(command, outWriter, errWriter)
Ω(err).ShouldNot(HaveOccurred())
})
Context("running a command", func() {
It("should start the process", func() {
Ω(command.Process).ShouldNot(BeNil())
})
It("should wrap the process's stdout and stderr with gbytes buffers", func(done Done) {
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!"))
defer session.Out.CancelDetects()
select {
case <-session.Out.Detect("Can we maybe vote on the whole murdering people issue"):
Eventually(session).Should(Exit(0))
case <-session.Out.Detect("I swear by my pretty floral bonnet, I will end you."):
Eventually(session).Should(Exit(1))
case <-session.Out.Detect("My work's illegal, but at least it's honest."):
Eventually(session).Should(Exit(2))
}
close(done)
})
It("should satisfy the gbytes.BufferProvider interface, passing Stdout", func() {
Eventually(session).Should(Say("We've done the impossible, and that makes us mighty"))
Eventually(session).Should(Exit())
})
})
Describe("providing the exit code", func() {
It("should provide the app's exit code", func() {
Ω(session.ExitCode()).Should(Equal(-1))
Eventually(session).Should(Exit())
Ω(session.ExitCode()).Should(BeNumerically(">=", 0))
Ω(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))
})
})
Describe("exited", func() {
It("should close when the command exits", func() {
Eventually(session.Exited).Should(BeClosed())
Ω(session.ExitCode()).ShouldNot(Equal(-1))
})
})
Describe("kill", func() {
It("should kill the command and wait for it to exit", func() {
session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
session.Kill()
Ω(session).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session).Should(Exit(128 + 9))
})
})
Describe("interrupt", func() {
It("should interrupt the command", func() {
session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
session.Interrupt()
Ω(session).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session).Should(Exit(128 + 2))
})
})
Describe("terminate", func() {
It("should terminate the command", func() {
session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
session.Terminate()
Ω(session).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session).Should(Exit(128 + 15))
})
})
Describe("signal", func() {
It("should send the signal to the command", func() {
session, err := Start(exec.Command("sleep", "10000000"), GinkgoWriter, GinkgoWriter)
Ω(err).ShouldNot(HaveOccurred())
session.Signal(syscall.SIGABRT)
Ω(session).ShouldNot(Exit(), "Should not exit immediately...")
Eventually(session).Should(Exit(128 + 6))
})
})
Context("when the command exits", func() {
It("should close the buffers", func() {
Eventually(session).Should(Exit())
Ω(session.Out.Closed()).Should(BeTrue())
Ω(session.Err.Closed()).Should(BeTrue())
Ω(session.Out).Should(Say("We've done the impossible, and that makes us mighty"))
})
var So = It
So("this means that eventually should short circuit", func() {
t := time.Now()
failures := InterceptGomegaFailures(func() {
Eventually(session).Should(Say("blah blah blah blah blah"))
})
Ω(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))
Ω(failures).Should(HaveLen(1))
})
})
Context("when wrapping out and err", func() {
BeforeEach(func() {
outWriter = NewBuffer()
errWriter = NewBuffer()
})
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!"))
Eventually(session).Should(Exit())
Ω(outWriter.Contents()).Should(Equal(session.Out.Contents()))
Ω(errWriter.Contents()).Should(Equal(session.Err.Contents()))
})
})
Describe("when the command fails to start", func() {
It("should return an error", func() {
_, err := Start(exec.Command("agklsjdfas"), nil, nil)
Ω(err).Should(HaveOccurred())
})
})
})