summaryrefslogtreecommitdiff
path: root/vendor
diff options
context:
space:
mode:
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/onsi/gomega/CHANGELOG.md9
-rw-r--r--vendor/github.com/onsi/gomega/env.go40
-rw-r--r--vendor/github.com/onsi/gomega/gomega_dsl.go536
-rw-r--r--vendor/github.com/onsi/gomega/internal/assertion.go (renamed from vendor/github.com/onsi/gomega/internal/assertion/assertion.go)28
-rw-r--r--vendor/github.com/onsi/gomega/internal/async_assertion.go (renamed from vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go)171
-rw-r--r--vendor/github.com/onsi/gomega/internal/defaults/env.go22
-rw-r--r--vendor/github.com/onsi/gomega/internal/duration_bundle.go71
-rw-r--r--vendor/github.com/onsi/gomega/internal/gomega.go102
-rw-r--r--vendor/github.com/onsi/gomega/internal/oraclematcher/oracle_matcher.go25
-rw-r--r--vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go60
-rw-r--r--vendor/github.com/onsi/gomega/matchers/and.go5
-rw-r--r--vendor/github.com/onsi/gomega/matchers/not.go3
-rw-r--r--vendor/github.com/onsi/gomega/matchers/or.go5
-rw-r--r--vendor/github.com/onsi/gomega/matchers/with_transform.go3
-rw-r--r--vendor/github.com/onsi/gomega/types/types.go69
-rw-r--r--vendor/modules.txt8
16 files changed, 546 insertions, 611 deletions
diff --git a/vendor/github.com/onsi/gomega/CHANGELOG.md b/vendor/github.com/onsi/gomega/CHANGELOG.md
index f2181a8cc..3486f3582 100644
--- a/vendor/github.com/onsi/gomega/CHANGELOG.md
+++ b/vendor/github.com/onsi/gomega/CHANGELOG.md
@@ -1,3 +1,12 @@
+## 1.15.0
+
+### Fixes
+The previous version (1.14.0) introduced a change to allow `Eventually` and `Consistently` to support functions that make assertions. This was accomplished by overriding the global fail handler when running the callbacks passed to `Eventually/Consistently` in order to capture any resulting errors. Issue #457 uncovered a flaw with this approach: when multiple `Eventually`s are running concurrently they race when overriding the singleton global fail handler.
+
+1.15.0 resolves this by requiring users who want to make assertions in `Eventually/Consistently` call backs to explicitly pass in a function that takes a `Gomega` as an argument. The passed-in `Gomega` instance can be used to make assertions. Any failures will cause `Eventually` to retry the callback. This cleaner interface avoids the issue of swapping out globals but comes at the cost of changing the contract introduced in v1.14.0. As such 1.15.0 introduces a breaking change with respect to 1.14.0 - however we expect that adoption of this feature in 1.14.0 remains limited.
+
+In addition, 1.15.0 cleans up some of Gomega's internals. Most users shouldn't notice any differences stemming from the refactoring that was made.
+
## 1.14.0
### Features
diff --git a/vendor/github.com/onsi/gomega/env.go b/vendor/github.com/onsi/gomega/env.go
deleted file mode 100644
index 62fd885a9..000000000
--- a/vendor/github.com/onsi/gomega/env.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package gomega
-
-import (
- "os"
-
- "github.com/onsi/gomega/internal/defaults"
-)
-
-const (
- ConsistentlyDurationEnvVarName = "GOMEGA_DEFAULT_CONSISTENTLY_DURATION"
- ConsistentlyPollingIntervalEnvVarName = "GOMEGA_DEFAULT_CONSISTENTLY_POLLING_INTERVAL"
- EventuallyTimeoutEnvVarName = "GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT"
- EventuallyPollingIntervalEnvVarName = "GOMEGA_DEFAULT_EVENTUALLY_POLLING_INTERVAL"
-)
-
-func init() {
- defaults.SetDurationFromEnv(
- os.Getenv,
- SetDefaultConsistentlyDuration,
- ConsistentlyDurationEnvVarName,
- )
-
- defaults.SetDurationFromEnv(
- os.Getenv,
- SetDefaultConsistentlyPollingInterval,
- ConsistentlyPollingIntervalEnvVarName,
- )
-
- defaults.SetDurationFromEnv(
- os.Getenv,
- SetDefaultEventuallyTimeout,
- EventuallyTimeoutEnvVarName,
- )
-
- defaults.SetDurationFromEnv(
- os.Getenv,
- SetDefaultEventuallyPollingInterval,
- EventuallyPollingIntervalEnvVarName,
- )
-}
diff --git a/vendor/github.com/onsi/gomega/gomega_dsl.go b/vendor/github.com/onsi/gomega/gomega_dsl.go
index 67f6e45c1..6c7f1d9b7 100644
--- a/vendor/github.com/onsi/gomega/gomega_dsl.go
+++ b/vendor/github.com/onsi/gomega/gomega_dsl.go
@@ -16,78 +16,92 @@ package gomega
import (
"errors"
"fmt"
- "reflect"
"time"
- "github.com/onsi/gomega/internal/assertion"
- "github.com/onsi/gomega/internal/asyncassertion"
- "github.com/onsi/gomega/internal/testingtsupport"
+ "github.com/onsi/gomega/internal"
"github.com/onsi/gomega/types"
)
-const GOMEGA_VERSION = "1.14.0"
+const GOMEGA_VERSION = "1.15.0"
-const nilFailHandlerPanic = `You are trying to make an assertion, but Gomega's fail handler is nil.
+const nilGomegaPanic = `You are trying to make an assertion, but haven't registered Gomega's fail handler.
If you're using Ginkgo then you probably forgot to put your assertion in an It().
Alternatively, you may have forgotten to register a fail handler with RegisterFailHandler() or RegisterTestingT().
Depending on your vendoring solution you may be inadvertently importing gomega and subpackages (e.g. ghhtp, gexec,...) from different locations.
`
-var globalFailWrapper *types.GomegaFailWrapper
-
-var defaultEventuallyTimeout = time.Second
-var defaultEventuallyPollingInterval = 10 * time.Millisecond
-var defaultConsistentlyDuration = 100 * time.Millisecond
-var defaultConsistentlyPollingInterval = 10 * time.Millisecond
-
-// RegisterFailHandler connects Ginkgo to Gomega. When a matcher fails
-// the fail handler passed into RegisterFailHandler is called.
-func RegisterFailHandler(handler types.GomegaFailHandler) {
- RegisterFailHandlerWithT(testingtsupport.EmptyTWithHelper{}, handler)
-}
+// Gomega describes the essential Gomega DSL. This interface allows libraries
+// to abstract between the standard package-level function implementations
+// and alternatives like *WithT.
+//
+// The types in the top-level DSL have gotten a bit messy due to earlier depracations that avoid stuttering
+// and due to an accidental use of a concrete type (*WithT) in an earlier release.
+//
+// As of 1.15 both the WithT and Ginkgo variants of Gomega are implemented by the same underlying object
+// however one (the Ginkgo variant) is exported as an interface (types.Gomega) whereas the other (the withT variant)
+// is shared as a concrete type (*WithT, which is aliased to *internal.Gomega). 1.15 did not clean this mess up to ensure
+// that declarations of *WithT in existing code are not broken by the upgrade to 1.15.
+type Gomega = types.Gomega
-// RegisterFailHandlerWithT ensures that the given types.TWithHelper and fail handler
-// are used globally.
-func RegisterFailHandlerWithT(t types.TWithHelper, handler types.GomegaFailHandler) {
- if handler == nil {
- globalFailWrapper = nil
- return
- }
+// DefaultGomega supplies the standard package-level implementation
+var Default = Gomega(internal.NewGomega(internal.FetchDefaultDurationBundle()))
- globalFailWrapper = &types.GomegaFailWrapper{
- Fail: handler,
- TWithHelper: t,
- }
+// NewGomega returns an instance of Gomega wired into the passed-in fail handler.
+// You generally don't need to use this when using Ginkgo - RegisterFailHandler will wire up the global gomega
+// However creating a NewGomega with a custom fail handler can be useful in contexts where you want to use Gomega's
+// rich ecosystem of matchers without causing a test to fail. For example, to aggregate a series of potential failures
+// or for use in a non-test setting.
+func NewGomega(fail types.GomegaFailHandler) Gomega {
+ return internal.NewGomega(Default.(*internal.Gomega).DurationBundle).ConfigureWithFailHandler(fail)
}
-// RegisterTestingT connects Gomega to Golang's XUnit style
-// Testing.T tests. It is now deprecated and you should use NewWithT() instead.
+// WithT wraps a *testing.T and provides `Expect`, `Eventually`, and `Consistently` methods. This allows you to leverage
+// Gomega's rich ecosystem of matchers in standard `testing` test suites.
//
-// Legacy Documentation:
+// Use `NewWithT` to instantiate a `WithT`
//
-// You'll need to call this at the top of each XUnit style test:
+// As of 1.15 both the WithT and Ginkgo variants of Gomega are implemented by the same underlying object
+// however one (the Ginkgo variant) is exported as an interface (types.Gomega) whereas the other (the withT variant)
+// is shared as a concrete type (*WithT, which is aliased to *internal.Gomega). 1.15 did not clean this mess up to ensure
+// that declarations of *WithT in existing code are not broken by the upgrade to 1.15.
+type WithT = internal.Gomega
+
+// GomegaWithT is deprecated in favor of gomega.WithT, which does not stutter.
+type GomegaWithT = WithT
+
+// NewWithT takes a *testing.T and returngs a `gomega.WithT` allowing you to use `Expect`, `Eventually`, and `Consistently` along with
+// Gomega's rich ecosystem of matchers in standard `testing` test suits.
//
// func TestFarmHasCow(t *testing.T) {
-// RegisterTestingT(t)
+// g := gomega.NewWithT(t)
//
// f := farm.New([]string{"Cow", "Horse"})
-// Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
-// }
-//
-// Note that this *testing.T is registered *globally* by Gomega (this is why you don't have to
-// pass `t` down to the matcher itself). This means that you cannot run the XUnit style tests
-// in parallel as the global fail handler cannot point to more than one testing.T at a time.
-//
-// NewWithT() does not have this limitation
-//
-// (As an aside: Ginkgo gets around this limitation by running parallel tests in different *processes*).
+// g.Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
+// }
+func NewWithT(t types.GomegaTestingT) *WithT {
+ return internal.NewGomega(Default.(*internal.Gomega).DurationBundle).ConfigureWithT(t)
+}
+
+// NewGomegaWithT is deprecated in favor of gomega.NewWithT, which does not stutter.
+var NewGomegaWithT = NewWithT
+
+// RegisterFailHandler connects Ginkgo to Gomega. When a matcher fails
+// the fail handler passed into RegisterFailHandler is called.
+func RegisterFailHandler(fail types.GomegaFailHandler) {
+ Default.(*internal.Gomega).ConfigureWithFailHandler(fail)
+}
+
+// RegisterFailHandlerWithT is deprecated and will be removed in a future release.
+// users should use RegisterFailHandler, or RegisterTestingT
+func RegisterFailHandlerWithT(_ types.GomegaTestingT, fail types.GomegaFailHandler) {
+ fmt.Println("RegisterFailHandlerWithT is deprecated. Please use RegisterFailHandler or RegisterTestingT instead.")
+ Default.(*internal.Gomega).ConfigureWithFailHandler(fail)
+}
+
+// RegisterTestingT connects Gomega to Golang's XUnit style
+// Testing.T tests. It is now deprecated and you should use NewWithT() instead to get a fresh instance of Gomega for each test.
func RegisterTestingT(t types.GomegaTestingT) {
- tWithHelper, hasHelper := t.(types.TWithHelper)
- if !hasHelper {
- RegisterFailHandler(testingtsupport.BuildTestingTGomegaFailWrapper(t).Fail)
- return
- }
- RegisterFailHandlerWithT(tWithHelper, testingtsupport.BuildTestingTGomegaFailWrapper(t).Fail)
+ Default.(*internal.Gomega).ConfigureWithT(t)
}
// InterceptGomegaFailures runs a given callback and returns an array of
@@ -98,13 +112,13 @@ func RegisterTestingT(t types.GomegaTestingT) {
// This is most useful when testing custom matchers, but can also be used to check
// on a value using a Gomega assertion without causing a test failure.
func InterceptGomegaFailures(f func()) []string {
- originalHandler := globalFailWrapper.Fail
+ originalHandler := Default.(*internal.Gomega).Fail
failures := []string{}
- RegisterFailHandler(func(message string, callerSkip ...int) {
+ Default.(*internal.Gomega).Fail = func(message string, callerSkip ...int) {
failures = append(failures, message)
- })
+ }
defer func() {
- RegisterFailHandler(originalHandler)
+ Default.(*internal.Gomega).Fail = originalHandler
}()
f()
return failures
@@ -117,14 +131,14 @@ func InterceptGomegaFailures(f func()) []string {
// does not register a failure with the FailHandler registered via RegisterFailHandler - it is up
// to the user to decide what to do with the returned error
func InterceptGomegaFailure(f func()) (err error) {
- originalHandler := globalFailWrapper.Fail
- RegisterFailHandler(func(message string, callerSkip ...int) {
+ originalHandler := Default.(*internal.Gomega).Fail
+ Default.(*internal.Gomega).Fail = func(message string, callerSkip ...int) {
err = errors.New(message)
panic("stop execution")
- })
+ }
defer func() {
- RegisterFailHandler(originalHandler)
+ Default.(*internal.Gomega).Fail = originalHandler
if e := recover(); e != nil {
if err == nil {
panic(e)
@@ -136,6 +150,12 @@ func InterceptGomegaFailure(f func()) (err error) {
return err
}
+func ensureDefaultGomegaIsConfigured() {
+ if !Default.(*internal.Gomega).IsConfigured() {
+ panic(nilGomegaPanic)
+ }
+}
+
// Ω wraps an actual value allowing assertions to be made on it:
// Ω("foo").Should(Equal("foo"))
//
@@ -154,7 +174,8 @@ func InterceptGomegaFailure(f func()) (err error) {
//
// Ω and Expect are identical
func Ω(actual interface{}, extra ...interface{}) Assertion {
- return ExpectWithOffset(0, actual, extra...)
+ ensureDefaultGomegaIsConfigured()
+ return Default.Ω(actual, extra...)
}
// Expect wraps an actual value allowing assertions to be made on it:
@@ -175,7 +196,8 @@ func Ω(actual interface{}, extra ...interface{}) Assertion {
//
// Expect and Ω are identical
func Expect(actual interface{}, extra ...interface{}) Assertion {
- return ExpectWithOffset(0, actual, extra...)
+ ensureDefaultGomegaIsConfigured()
+ return Default.Expect(actual, extra...)
}
// ExpectWithOffset wraps an actual value allowing assertions to be made on it:
@@ -188,166 +210,156 @@ func Expect(actual interface{}, extra ...interface{}) Assertion {
// error message to refer to the calling line in the test (as opposed to the line in the helper function)
// set the first argument of `ExpectWithOffset` appropriately.
func ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Assertion {
- if globalFailWrapper == nil {
- panic(nilFailHandlerPanic)
- }
- return assertion.New(actual, globalFailWrapper, offset, extra...)
+ ensureDefaultGomegaIsConfigured()
+ return Default.ExpectWithOffset(offset, actual, extra...)
}
-// Eventually wraps an actual value allowing assertions to be made on it.
-// The assertion is tried periodically until it passes or a timeout occurs.
-//
-// Both the timeout and polling interval are configurable as optional arguments:
-// The first optional argument is the timeout
-// The second optional argument is the polling interval
-//
-// Both intervals can either be specified as time.Duration, parsable duration strings or as floats/integers. In the
-// last case they are interpreted as seconds.
-//
-// If Eventually is passed an actual that is a function taking no arguments,
-// then Eventually will call the function periodically and try the matcher against the function's first return value.
-//
-// Example:
-//
-// Eventually(func() int {
-// return thingImPolling.Count()
-// }).Should(BeNumerically(">=", 17))
-//
-// Note that this example could be rewritten:
-//
-// Eventually(thingImPolling.Count).Should(BeNumerically(">=", 17))
-//
-// If the function returns more than one value, then Eventually will pass the first value to the matcher and
-// assert that all other values are nil/zero.
-// This allows you to pass Eventually a function that returns a value and an error - a common pattern in Go.
-//
-// For example, consider a method that returns a value and an error:
-// func FetchFromDB() (string, error)
-//
-// Then
-// Eventually(FetchFromDB).Should(Equal("hasselhoff"))
-//
-// Will pass only if the the returned error is nil and the returned string passes the matcher.
-//
-// Eventually allows you to make assertions in the pased-in function. The function is assumed to have failed and will be retried if any assertion in the function fails.
-// For example:
-//
-// Eventually(func() Widget {
-// resp, err := http.Get(url)
-// Expect(err).NotTo(HaveOccurred())
-// defer resp.Body.Close()
-// Expect(resp.SatusCode).To(Equal(http.StatusOK))
-// var widget Widget
-// Expect(json.NewDecoder(resp.Body).Decode(&widget)).To(Succeed())
-// return widget
-// }).Should(Equal(expectedWidget))
-//
-// will keep trying the passed-in function until all its assertsions pass (i.e. the http request succeeds) _and_ the returned object satisfies the passed-in matcher.
-//
-// Functions passed to Eventually typically have a return value. However you are allowed to pass in a function with no return value. Eventually assumes such a function
-// is making assertions and will turn it into a function that returns an error if any assertion fails, or nil if no assertion fails. This allows you to use the Succeed() matcher
-// to express that a complex operation should eventually succeed. For example:
-//
-// Eventually(func() {
-// model, err := db.Find("foo")
-// Expect(err).NotTo(HaveOccurred())
-// Expect(model.Reticulated()).To(BeTrue())
-// Expect(model.Save()).To(Succeed())
-// }).Should(Succeed())
-//
-// will rerun the function until all its assertions pass.
-//
-// Eventually's default timeout is 1 second, and its default polling interval is 10ms
+/*
+Eventually enables making assertions on asynchronous behavior.
+
+Eventually checks that an assertion *eventually* passes. Eventually blocks when called and attempts an assertion periodically until it passes or a timeout occurs. Both the timeout and polling interval are configurable as optional arguments.
+The first optional argument is the timeout (which defaults to 1s), the second is the polling interval (which defaults to 10ms). Both intervals can be specified as time.Duration, parsable duration strings or floats/integers (in which case they are interpreted as seconds).
+
+Eventually works with any Gomega compatible matcher and supports making assertions against three categories of actual value:
+
+**Category 1: Making Eventually assertions on values**
+
+There are several examples of values that can change over time. These can be passed in to Eventually and will be passed to the matcher repeatedly until a match occurs. For example:
+
+ c := make(chan bool)
+ go DoStuff(c)
+ Eventually(c, "50ms").Should(BeClosed())
+
+will poll the channel repeatedly until it is closed. In this example `Eventually` will block until either the specified timeout of 50ms has elapsed or the channel is closed, whichever comes first.
+
+Several Gomega libraries allow you to use Eventually in this way. For example, the gomega/gexec package allows you to block until a *gexec.Session exits successfuly via:
+
+ Eventually(session).Should(gexec.Exit(0))
+
+And the gomega/gbytes package allows you to monitor a streaming *gbytes.Buffer until a given string is seen:
+
+ Eventually(buffer).Should(gbytes.Say("hello there"))
+
+In these examples, both `session` and `buffer` are designed to be thread-safe when polled by the `Exit` and `Say` matchers. This is not true in general of most raw values, so while it is tempting to do something like:
+
+ // THIS IS NOT THREAD-SAFE
+ var s *string
+ go mutateStringEventually(s)
+ Eventually(s).Should(Equal("I've changed"))
+
+this will trigger Go's race detector as the goroutine polling via Eventually will race over the value of s with the goroutine mutating the string. For cases like this you can use channels or introduce your own locking around s by passing Eventually a function.
+
+**Category 2: Make Eventually assertions on functions**
+
+Eventually can be passed functions that **take no arguments** and **return at least one value**. When configured this way, Eventually will poll the function repeatedly and pass the first returned value to the matcher.
+
+For example:
+
+ Eventually(func() int {
+ return client.FetchCount()
+ }).Should(BeNumerically(">=", 17))
+
+ will repeatedly poll client.FetchCount until the BeNumerically matcher is satisfied. (Note that this example could have been written as Eventually(client.FetchCount).Should(BeNumerically(">=", 17)))
+
+If multple values are returned by the function, Eventually will pass the first value to the matcher and require that all others are zero-valued. This allows you to pass Eventually a function that returns a value and an error - a common patternin Go.
+
+For example, consider a method that returns a value and an error:
+ func FetchFromDB() (string, error)
+
+Then
+ Eventually(FetchFromDB).Should(Equal("got it"))
+
+will pass only if and when the returned error is nil *and* the returned string satisfies the matcher.
+
+It is important to note that the function passed into Eventually is invoked *synchronously* when polled. Eventually does not (in fact, it cannot) kill the function if it takes longer to return than Eventually's configured timeout. You should design your functions with this in mind.
+
+**Category 3: Making assertions _in_ the function passed into Eventually**
+
+When testing complex systems it can be valuable to assert that a _set_ of assertions passes Eventually. Eventually supports this by accepting functions that take a single Gomega argument and return zero or more values.
+
+Here's an example that makes some asssertions and returns a value and error:
+
+ Eventually(func(g Gomega) (Widget, error) {
+ ids, err := client.FetchIDs()
+ g.Expect(err).NotTo(HaveOccurred())
+ g.Expect(ids).To(ContainElement(1138))
+ return client.FetchWidget(1138)
+ }).Should(Equal(expectedWidget))
+
+will pass only if all the assertions in the polled function pass and the return value satisfied the matcher.
+
+Eventually also supports a special case polling function that takes a single Gomega argument and returns no values. Eventually assumes such a function is making assertions and is designed to work with the Succeed matcher to validate that all assertions have passed.
+For example:
+
+ Eventually(func(g Gomega) {
+ model, err := client.Find(1138)
+ g.Expect(err).NotTo(HaveOccurred())
+ g.Expect(model.Reticulate()).To(Succeed())
+ g.Expect(model.IsReticulated()).To(BeTrue())
+ g.Expect(model.Save()).To(Succeed())
+ }).Should(Succeed())
+
+will rerun the function until all assertions pass.
+*/
func Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion {
- return EventuallyWithOffset(0, actual, intervals...)
+ ensureDefaultGomegaIsConfigured()
+ return Default.Eventually(actual, intervals...)
}
// EventuallyWithOffset operates like Eventually but takes an additional
// initial argument to indicate an offset in the call stack. This is useful when building helper
// functions that contain matchers. To learn more, read about `ExpectWithOffset`.
func EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion {
- if globalFailWrapper == nil {
- panic(nilFailHandlerPanic)
- }
- timeoutInterval := defaultEventuallyTimeout
- pollingInterval := defaultEventuallyPollingInterval
- if len(intervals) > 0 {
- timeoutInterval = toDuration(intervals[0])
- }
- if len(intervals) > 1 {
- pollingInterval = toDuration(intervals[1])
- }
- return asyncassertion.New(asyncassertion.AsyncAssertionTypeEventually, actual, globalFailWrapper, timeoutInterval, pollingInterval, offset)
+ ensureDefaultGomegaIsConfigured()
+ return Default.EventuallyWithOffset(offset, actual, intervals...)
}
-// Consistently wraps an actual value allowing assertions to be made on it.
-// The assertion is tried periodically and is required to pass for a period of time.
-//
-// Both the total time and polling interval are configurable as optional arguments:
-// The first optional argument is the duration that Consistently will run for
-// The second optional argument is the polling interval
-//
-// Both intervals can either be specified as time.Duration, parsable duration strings or as floats/integers. In the
-// last case they are interpreted as seconds.
-//
-// If Consistently is passed an actual that is a function taking no arguments.
-//
-// If the function returns one value, then Consistently will call the function periodically and try the matcher against the function's first return value.
-//
-// If the function returns more than one value, then Consistently will pass the first value to the matcher and
-// assert that all other values are nil/zero.
-// This allows you to pass Consistently a function that returns a value and an error - a common pattern in Go.
-//
-// Like Eventually, Consistently allows you to make assertions in the function. If any assertion fails Consistently will fail. In addition,
-// Consistently also allows you to pass in a function with no return value. In this case Consistently can be paired with the Succeed() matcher to assert
-// that no assertions in the function fail.
-//
-// Consistently is useful in cases where you want to assert that something *does not happen* over a period of time.
-// For example, you want to assert that a goroutine does *not* send data down a channel. In this case, you could:
-//
-// Consistently(channel).ShouldNot(Receive())
-//
-// Consistently's default duration is 100ms, and its default polling interval is 10ms
+/*
+Consistently, like Eventually, enables making assertions on asynchronous behavior.
+
+Consistently blocks when called for a specified duration. During that duration Consistently repeatedly polls its matcher and ensures that it is satisfied. If the matcher is consistently satisfied, then Consistently will pass. Otherwise Consistently will fail.
+
+Both the total waiting duration and the polling interval are configurable as optional arguments. The first optional arugment is the duration that Consistently will run for (defaults to 100ms), and the second argument is the polling interval (defaults to 10ms). As with Eventually, these intervals can be passed in as time.Duration, parsable duration strings or an integer or float number of seconds.
+
+Consistently accepts the same three categories of actual as Eventually, check the Eventually docs to learn more.
+
+Consistently is useful in cases where you want to assert that something *does not happen* for a period of time. For example, you may want to assert that a goroutine does *not* send data down a channel. In this case you could write:
+
+ Consistently(channel, "200ms").ShouldNot(Receive())
+
+This will block for 200 milliseconds and repeatedly check the channel and ensure nothing has been received.
+*/
func Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion {
- return ConsistentlyWithOffset(0, actual, intervals...)
+ ensureDefaultGomegaIsConfigured()
+ return Default.Consistently(actual, intervals...)
}
// ConsistentlyWithOffset operates like Consistently but takes an additional
// initial argument to indicate an offset in the call stack. This is useful when building helper
// functions that contain matchers. To learn more, read about `ExpectWithOffset`.
func ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion {
- if globalFailWrapper == nil {
- panic(nilFailHandlerPanic)
- }
- timeoutInterval := defaultConsistentlyDuration
- pollingInterval := defaultConsistentlyPollingInterval
- if len(intervals) > 0 {
- timeoutInterval = toDuration(intervals[0])
- }
- if len(intervals) > 1 {
- pollingInterval = toDuration(intervals[1])
- }
- return asyncassertion.New(asyncassertion.AsyncAssertionTypeConsistently, actual, globalFailWrapper, timeoutInterval, pollingInterval, offset)
+ ensureDefaultGomegaIsConfigured()
+ return Default.ConsistentlyWithOffset(offset, actual, intervals...)
}
// SetDefaultEventuallyTimeout sets the default timeout duration for Eventually. Eventually will repeatedly poll your condition until it succeeds, or until this timeout elapses.
func SetDefaultEventuallyTimeout(t time.Duration) {
- defaultEventuallyTimeout = t
+ Default.SetDefaultEventuallyTimeout(t)
}
// SetDefaultEventuallyPollingInterval sets the default polling interval for Eventually.
func SetDefaultEventuallyPollingInterval(t time.Duration) {
- defaultEventuallyPollingInterval = t
+ Default.SetDefaultEventuallyPollingInterval(t)
}
// SetDefaultConsistentlyDuration sets the default duration for Consistently. Consistently will verify that your condition is satisfied for this long.
func SetDefaultConsistentlyDuration(t time.Duration) {
- defaultConsistentlyDuration = t
+ Default.SetDefaultConsistentlyDuration(t)
}
// SetDefaultConsistentlyPollingInterval sets the default polling interval for Consistently.
func SetDefaultConsistentlyPollingInterval(t time.Duration) {
- defaultConsistentlyPollingInterval = t
+ Default.SetDefaultConsistentlyPollingInterval(t)
}
// AsyncAssertion is returned by Eventually and Consistently and polls the actual value passed into Eventually against
@@ -365,13 +377,10 @@ func SetDefaultConsistentlyPollingInterval(t time.Duration) {
//
// Eventually(myChannel).Should(Receive(), "Something should have come down the pipe.")
// Consistently(myChannel).ShouldNot(Receive(), func() string { return "Nothing should have come down the pipe." })
-type AsyncAssertion interface {
- Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
-}
+type AsyncAssertion = types.AsyncAssertion
// GomegaAsyncAssertion is deprecated in favor of AsyncAssertion, which does not stutter.
-type GomegaAsyncAssertion = AsyncAssertion
+type GomegaAsyncAssertion = types.AsyncAssertion
// Assertion is returned by Ω and Expect and compares the actual value to the matcher
// passed to the Should/ShouldNot and To/ToNot/NotTo methods.
@@ -390,149 +399,10 @@ type GomegaAsyncAssertion = AsyncAssertion
// Example:
//
// Ω(farm.HasCow()).Should(BeTrue(), "Farm %v should have a cow", farm)
-type Assertion interface {
- Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
-
- To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
-}
+type Assertion = types.Assertion
// GomegaAssertion is deprecated in favor of Assertion, which does not stutter.
-type GomegaAssertion = Assertion
+type GomegaAssertion = types.Assertion
// OmegaMatcher is deprecated in favor of the better-named and better-organized types.GomegaMatcher but sticks around to support existing code that uses it
-type OmegaMatcher types.GomegaMatcher
-
-// WithT wraps a *testing.T and provides `Expect`, `Eventually`, and `Consistently` methods. This allows you to leverage
-// Gomega's rich ecosystem of matchers in standard `testing` test suites.
-//
-// Use `NewWithT` to instantiate a `WithT`
-type WithT struct {
- failWrapper *types.GomegaFailWrapper
-}
-
-// GomegaWithT is deprecated in favor of gomega.WithT, which does not stutter.
-type GomegaWithT = WithT
-
-// NewWithT takes a *testing.T and returngs a `gomega.WithT` allowing you to use `Expect`, `Eventually`, and `Consistently` along with
-// Gomega's rich ecosystem of matchers in standard `testing` test suits.
-//
-// func TestFarmHasCow(t *testing.T) {
-// g := gomega.NewWithT(t)
-//
-// f := farm.New([]string{"Cow", "Horse"})
-// g.Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
-// }
-func NewWithT(t types.GomegaTestingT) *WithT {
- return &WithT{
- failWrapper: testingtsupport.BuildTestingTGomegaFailWrapper(t),
- }
-}
-
-// NewGomegaWithT is deprecated in favor of gomega.NewWithT, which does not stutter.
-func NewGomegaWithT(t types.GomegaTestingT) *GomegaWithT {
- return NewWithT(t)
-}
-
-// ExpectWithOffset is used to make assertions. See documentation for ExpectWithOffset.
-func (g *WithT) ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Assertion {
- return assertion.New(actual, g.failWrapper, offset, extra...)
-}
-
-// EventuallyWithOffset is used to make asynchronous assertions. See documentation for EventuallyWithOffset.
-func (g *WithT) EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion {
- timeoutInterval := defaultEventuallyTimeout
- pollingInterval := defaultEventuallyPollingInterval
- if len(intervals) > 0 {
- timeoutInterval = toDuration(intervals[0])
- }
- if len(intervals) > 1 {
- pollingInterval = toDuration(intervals[1])
- }
- return asyncassertion.New(asyncassertion.AsyncAssertionTypeEventually, actual, g.failWrapper, timeoutInterval, pollingInterval, offset)
-}
-
-// ConsistentlyWithOffset is used to make asynchronous assertions. See documentation for ConsistentlyWithOffset.
-func (g *WithT) ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion {
- timeoutInterval := defaultConsistentlyDuration
- pollingInterval := defaultConsistentlyPollingInterval
- if len(intervals) > 0 {
- timeoutInterval = toDuration(intervals[0])
- }
- if len(intervals) > 1 {
- pollingInterval = toDuration(intervals[1])
- }
- return asyncassertion.New(asyncassertion.AsyncAssertionTypeConsistently, actual, g.failWrapper, timeoutInterval, pollingInterval, offset)
-}
-
-// Expect is used to make assertions. See documentation for Expect.
-func (g *WithT) Expect(actual interface{}, extra ...interface{}) Assertion {
- return g.ExpectWithOffset(0, actual, extra...)
-}
-
-// Eventually is used to make asynchronous assertions. See documentation for Eventually.
-func (g *WithT) Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion {
- return g.EventuallyWithOffset(0, actual, intervals...)
-}
-
-// Consistently is used to make asynchronous assertions. See documentation for Consistently.
-func (g *WithT) Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion {
- return g.ConsistentlyWithOffset(0, actual, intervals...)
-}
-
-func toDuration(input interface{}) time.Duration {
- duration, ok := input.(time.Duration)
- if ok {
- return duration
- }
-
- value := reflect.ValueOf(input)
- kind := reflect.TypeOf(input).Kind()
-
- if reflect.Int <= kind && kind <= reflect.Int64 {
- return time.Duration(value.Int()) * time.Second
- } else if reflect.Uint <= kind && kind <= reflect.Uint64 {
- return time.Duration(value.Uint()) * time.Second
- } else if reflect.Float32 <= kind && kind <= reflect.Float64 {
- return time.Duration(value.Float() * float64(time.Second))
- } else if reflect.String == kind {
- duration, err := time.ParseDuration(value.String())
- if err != nil {
- panic(fmt.Sprintf("%#v is not a valid parsable duration string.", input))
- }
- return duration
- }
-
- panic(fmt.Sprintf("%v is not a valid interval. Must be time.Duration, parsable duration string or a number.", input))
-}
-
-// Gomega describes the essential Gomega DSL. This interface allows libraries
-// to abstract between the standard package-level function implementations
-// and alternatives like *WithT.
-type Gomega interface {
- Expect(actual interface{}, extra ...interface{}) Assertion
- Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion
- Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion
-}
-
-type globalFailHandlerGomega struct{}
-
-// DefaultGomega supplies the standard package-level implementation
-var Default Gomega = globalFailHandlerGomega{}
-
-// Expect is used to make assertions. See documentation for Expect.
-func (globalFailHandlerGomega) Expect(actual interface{}, extra ...interface{}) Assertion {
- return Expect(actual, extra...)
-}
-
-// Eventually is used to make asynchronous assertions. See documentation for Eventually.
-func (globalFailHandlerGomega) Eventually(actual interface{}, extra ...interface{}) AsyncAssertion {
- return Eventually(actual, extra...)
-}
-
-// Consistently is used to make asynchronous assertions. See documentation for Consistently.
-func (globalFailHandlerGomega) Consistently(actual interface{}, extra ...interface{}) AsyncAssertion {
- return Consistently(actual, extra...)
-}
+type OmegaMatcher = types.GomegaMatcher
diff --git a/vendor/github.com/onsi/gomega/internal/assertion/assertion.go b/vendor/github.com/onsi/gomega/internal/assertion.go
index a248298f4..36b0e8345 100644
--- a/vendor/github.com/onsi/gomega/internal/assertion/assertion.go
+++ b/vendor/github.com/onsi/gomega/internal/assertion.go
@@ -1,4 +1,4 @@
-package assertion
+package internal
import (
"fmt"
@@ -9,42 +9,42 @@ import (
type Assertion struct {
actualInput interface{}
- failWrapper *types.GomegaFailWrapper
offset int
extra []interface{}
+ g *Gomega
}
-func New(actualInput interface{}, failWrapper *types.GomegaFailWrapper, offset int, extra ...interface{}) *Assertion {
+func NewAssertion(actualInput interface{}, g *Gomega, offset int, extra ...interface{}) *Assertion {
return &Assertion{
actualInput: actualInput,
- failWrapper: failWrapper,
offset: offset,
extra: extra,
+ g: g,
}
}
func (assertion *Assertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, true, optionalDescription...)
}
func (assertion *Assertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
}
func (assertion *Assertion) To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, true, optionalDescription...)
}
func (assertion *Assertion) ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
}
func (assertion *Assertion) NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
}
@@ -62,10 +62,10 @@ func (assertion *Assertion) buildDescription(optionalDescription ...interface{})
func (assertion *Assertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
matches, err := matcher.Match(assertion.actualInput)
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
if err != nil {
description := assertion.buildDescription(optionalDescription...)
- assertion.failWrapper.Fail(description+err.Error(), 2+assertion.offset)
+ assertion.g.Fail(description+err.Error(), 2+assertion.offset)
return false
}
if matches != desiredMatch {
@@ -76,7 +76,7 @@ func (assertion *Assertion) match(matcher types.GomegaMatcher, desiredMatch bool
message = matcher.NegatedFailureMessage(assertion.actualInput)
}
description := assertion.buildDescription(optionalDescription...)
- assertion.failWrapper.Fail(description+message, 2+assertion.offset)
+ assertion.g.Fail(description+message, 2+assertion.offset)
return false
}
@@ -90,8 +90,8 @@ func (assertion *Assertion) vetExtras(optionalDescription ...interface{}) bool {
}
description := assertion.buildDescription(optionalDescription...)
- assertion.failWrapper.TWithHelper.Helper()
- assertion.failWrapper.Fail(description+message, 2+assertion.offset)
+ assertion.g.THelper()
+ assertion.g.Fail(description+message, 2+assertion.offset)
return false
}
diff --git a/vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go b/vendor/github.com/onsi/gomega/internal/async_assertion.go
index 6aa02bc5d..ae20c14b8 100644
--- a/vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go
+++ b/vendor/github.com/onsi/gomega/internal/async_assertion.go
@@ -1,6 +1,4 @@
-// untested sections: 2
-
-package asyncassertion
+package internal
import (
"errors"
@@ -9,7 +7,6 @@ import (
"runtime"
"time"
- "github.com/onsi/gomega/internal/oraclematcher"
"github.com/onsi/gomega/types"
)
@@ -21,39 +18,82 @@ const (
)
type AsyncAssertion struct {
- asyncType AsyncAssertionType
- actualInput interface{}
+ asyncType AsyncAssertionType
+
+ actualIsFunc bool
+ actualValue interface{}
+ actualFunc func() ([]reflect.Value, error)
+
timeoutInterval time.Duration
pollingInterval time.Duration
- failWrapper *types.GomegaFailWrapper
offset int
+ g *Gomega
}
-func New(asyncType AsyncAssertionType, actualInput interface{}, failWrapper *types.GomegaFailWrapper, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
- actualType := reflect.TypeOf(actualInput)
- if actualType.Kind() == reflect.Func {
- if actualType.NumIn() != 0 {
- panic("Expected a function with no arguments and zero or more return values.")
- }
- }
-
- return &AsyncAssertion{
+func NewAsyncAssertion(asyncType AsyncAssertionType, actualInput interface{}, g *Gomega, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
+ out := &AsyncAssertion{
asyncType: asyncType,
- actualInput: actualInput,
- failWrapper: failWrapper,
timeoutInterval: timeoutInterval,
pollingInterval: pollingInterval,
offset: offset,
+ g: g,
+ }
+
+ switch actualType := reflect.TypeOf(actualInput); {
+ case actualType.Kind() != reflect.Func:
+ out.actualValue = actualInput
+ case actualType.NumIn() == 0 && actualType.NumOut() > 0:
+ out.actualIsFunc = true
+ out.actualFunc = func() ([]reflect.Value, error) {
+ return reflect.ValueOf(actualInput).Call([]reflect.Value{}), nil
+ }
+ case actualType.NumIn() == 1 && actualType.In(0).Implements(reflect.TypeOf((*types.Gomega)(nil)).Elem()):
+ out.actualIsFunc = true
+ out.actualFunc = func() (values []reflect.Value, err error) {
+ var assertionFailure error
+ assertionCapturingGomega := NewGomega(g.DurationBundle).ConfigureWithFailHandler(func(message string, callerSkip ...int) {
+ skip := 0
+ if len(callerSkip) > 0 {
+ skip = callerSkip[0]
+ }
+ _, file, line, _ := runtime.Caller(skip + 1)
+ assertionFailure = fmt.Errorf("Assertion in callback at %s:%d failed:\n%s", file, line, message)
+ panic("stop execution")
+ })
+
+ defer func() {
+ if actualType.NumOut() == 0 {
+ if assertionFailure == nil {
+ values = []reflect.Value{reflect.Zero(reflect.TypeOf((*error)(nil)).Elem())}
+ } else {
+ values = []reflect.Value{reflect.ValueOf(assertionFailure)}
+ }
+ } else {
+ err = assertionFailure
+ }
+ if e := recover(); e != nil && assertionFailure == nil {
+ panic(e)
+ }
+ }()
+
+ values = reflect.ValueOf(actualInput).Call([]reflect.Value{reflect.ValueOf(assertionCapturingGomega)})
+ return
+ }
+ default:
+ msg := fmt.Sprintf("The function passed to Gomega's async assertions should either take no arguments and return values, or take a single Gomega interface that it can use to make assertions within the body of the function. When taking a Gomega interface the function can optionally return values or return nothing. The function you passed takes %d arguments and returns %d values.", actualType.NumIn(), actualType.NumOut())
+ g.Fail(msg, offset+4)
}
+
+ return out
}
func (assertion *AsyncAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.match(matcher, true, optionalDescription...)
}
func (assertion *AsyncAssertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
return assertion.match(matcher, false, optionalDescription...)
}
@@ -69,74 +109,32 @@ func (assertion *AsyncAssertion) buildDescription(optionalDescription ...interfa
return fmt.Sprintf(optionalDescription[0].(string), optionalDescription[1:]...) + "\n"
}
-func (assertion *AsyncAssertion) actualInputIsAFunction() bool {
- actualType := reflect.TypeOf(assertion.actualInput)
- return actualType.Kind() == reflect.Func && actualType.NumIn() == 0
-}
-
func (assertion *AsyncAssertion) pollActual() (interface{}, error) {
- if !assertion.actualInputIsAFunction() {
- return assertion.actualInput, nil
+ if !assertion.actualIsFunc {
+ return assertion.actualValue, nil
}
- var capturedAssertionFailure string
- var values []reflect.Value
-
- numOut := reflect.TypeOf(assertion.actualInput).NumOut()
- func() {
- originalHandler := assertion.failWrapper.Fail
- assertion.failWrapper.Fail = func(message string, callerSkip ...int) {
- skip := 0
- if len(callerSkip) > 0 {
- skip = callerSkip[0]
- }
- _, file, line, _ := runtime.Caller(skip + 1)
- capturedAssertionFailure = fmt.Sprintf("Assertion in callback at %s:%d failed:\n%s", file, line, message)
- panic("stop execution")
- }
-
- defer func() {
- assertion.failWrapper.Fail = originalHandler
- if e := recover(); e != nil && capturedAssertionFailure == "" {
- panic(e)
- }
- }()
-
- values = reflect.ValueOf(assertion.actualInput).Call([]reflect.Value{})
- }()
-
- if capturedAssertionFailure != "" {
- if numOut == 0 {
- return errors.New(capturedAssertionFailure), nil
- } else {
- return nil, errors.New(capturedAssertionFailure)
- }
+ values, err := assertion.actualFunc()
+ if err != nil {
+ return nil, err
}
-
- if numOut > 0 {
- extras := []interface{}{}
- for _, value := range values[1:] {
- extras = append(extras, value.Interface())
- }
-
- success, message := vetExtras(extras)
-
- if !success {
- return nil, errors.New(message)
- }
-
- return values[0].Interface(), nil
+ extras := []interface{}{}
+ for _, value := range values[1:] {
+ extras = append(extras, value.Interface())
+ }
+ success, message := vetExtras(extras)
+ if !success {
+ return nil, errors.New(message)
}
- return nil, nil
+ return values[0].Interface(), nil
}
func (assertion *AsyncAssertion) matcherMayChange(matcher types.GomegaMatcher, value interface{}) bool {
- if assertion.actualInputIsAFunction() {
+ if assertion.actualIsFunc {
return true
}
-
- return oraclematcher.MatchMayChangeInTheFuture(matcher, value)
+ return types.MatchMayChangeInTheFuture(matcher, value)
}
func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
@@ -152,7 +150,7 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
matches, err = matcher.Match(value)
}
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
fail := func(preamble string) {
errMsg := ""
@@ -166,9 +164,9 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
message = matcher.NegatedFailureMessage(value)
}
}
- assertion.failWrapper.TWithHelper.Helper()
+ assertion.g.THelper()
description := assertion.buildDescription(optionalDescription...)
- assertion.failWrapper.Fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
+ assertion.g.Fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
}
if assertion.asyncType == AsyncAssertionTypeEventually {
@@ -220,16 +218,3 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
return false
}
-
-func vetExtras(extras []interface{}) (bool, string) {
- for i, extra := range extras {
- if extra != nil {
- zeroValue := reflect.Zero(reflect.TypeOf(extra)).Interface()
- if !reflect.DeepEqual(zeroValue, extra) {
- message := fmt.Sprintf("Unexpected non-nil/non-zero extra argument at index %d:\n\t<%T>: %#v", i+1, extra, extra)
- return false, message
- }
- }
- }
- return true, ""
-}
diff --git a/vendor/github.com/onsi/gomega/internal/defaults/env.go b/vendor/github.com/onsi/gomega/internal/defaults/env.go
deleted file mode 100644
index bc29c63d5..000000000
--- a/vendor/github.com/onsi/gomega/internal/defaults/env.go
+++ /dev/null
@@ -1,22 +0,0 @@
-package defaults
-
-import (
- "fmt"
- "time"
-)
-
-func SetDurationFromEnv(getDurationFromEnv func(string) string, varSetter func(time.Duration), name string) {
- durationFromEnv := getDurationFromEnv(name)
-
- if len(durationFromEnv) == 0 {
- return
- }
-
- duration, err := time.ParseDuration(durationFromEnv)
-
- if err != nil {
- panic(fmt.Sprintf("Expected a duration when using %s! Parse error %v", name, err))
- }
-
- varSetter(duration)
-}
diff --git a/vendor/github.com/onsi/gomega/internal/duration_bundle.go b/vendor/github.com/onsi/gomega/internal/duration_bundle.go
new file mode 100644
index 000000000..af8d989fa
--- /dev/null
+++ b/vendor/github.com/onsi/gomega/internal/duration_bundle.go
@@ -0,0 +1,71 @@
+package internal
+
+import (
+ "fmt"
+ "os"
+ "reflect"
+ "time"
+)
+
+type DurationBundle struct {
+ EventuallyTimeout time.Duration
+ EventuallyPollingInterval time.Duration
+ ConsistentlyDuration time.Duration
+ ConsistentlyPollingInterval time.Duration
+}
+
+const (
+ EventuallyTimeoutEnvVarName = "GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT"
+ EventuallyPollingIntervalEnvVarName = "GOMEGA_DEFAULT_EVENTUALLY_POLLING_INTERVAL"
+
+ ConsistentlyDurationEnvVarName = "GOMEGA_DEFAULT_CONSISTENTLY_DURATION"
+ ConsistentlyPollingIntervalEnvVarName = "GOMEGA_DEFAULT_CONSISTENTLY_POLLING_INTERVAL"
+)
+
+func FetchDefaultDurationBundle() DurationBundle {
+ return DurationBundle{
+ EventuallyTimeout: durationFromEnv(EventuallyTimeoutEnvVarName, time.Second),
+ EventuallyPollingInterval: durationFromEnv(EventuallyPollingIntervalEnvVarName, 10*time.Millisecond),
+
+ ConsistentlyDuration: durationFromEnv(ConsistentlyDurationEnvVarName, 100*time.Millisecond),
+ ConsistentlyPollingInterval: durationFromEnv(ConsistentlyPollingIntervalEnvVarName, 10*time.Millisecond),
+ }
+}
+
+func durationFromEnv(key string, defaultDuration time.Duration) time.Duration {
+ value := os.Getenv(key)
+ if value == "" {
+ return defaultDuration
+ }
+ duration, err := time.ParseDuration(value)
+ if err != nil {
+ panic(fmt.Sprintf("Expected a duration when using %s! Parse error %v", key, err))
+ }
+ return duration
+}
+
+func toDuration(input interface{}) time.Duration {
+ duration, ok := input.(time.Duration)
+ if ok {
+ return duration
+ }
+
+ value := reflect.ValueOf(input)
+ kind := reflect.TypeOf(input).Kind()
+
+ if reflect.Int <= kind && kind <= reflect.Int64 {
+ return time.Duration(value.Int()) * time.Second
+ } else if reflect.Uint <= kind && kind <= reflect.Uint64 {
+ return time.Duration(value.Uint()) * time.Second
+ } else if reflect.Float32 <= kind && kind <= reflect.Float64 {
+ return time.Duration(value.Float() * float64(time.Second))
+ } else if reflect.String == kind {
+ duration, err := time.ParseDuration(value.String())
+ if err != nil {
+ panic(fmt.Sprintf("%#v is not a valid parsable duration string.", input))
+ }
+ return duration
+ }
+
+ panic(fmt.Sprintf("%v is not a valid interval. Must be time.Duration, parsable duration string or a number.", input))
+}
diff --git a/vendor/github.com/onsi/gomega/internal/gomega.go b/vendor/github.com/onsi/gomega/internal/gomega.go
new file mode 100644
index 000000000..f5b5c6b7a
--- /dev/null
+++ b/vendor/github.com/onsi/gomega/internal/gomega.go
@@ -0,0 +1,102 @@
+package internal
+
+import (
+ "time"
+
+ "github.com/onsi/gomega/types"
+)
+
+type Gomega struct {
+ Fail types.GomegaFailHandler
+ THelper func()
+ DurationBundle DurationBundle
+}
+
+func NewGomega(bundle DurationBundle) *Gomega {
+ return &Gomega{
+ Fail: nil,
+ THelper: nil,
+ DurationBundle: bundle,
+ }
+}
+
+func (g *Gomega) IsConfigured() bool {
+ return g.Fail != nil && g.THelper != nil
+}
+
+func (g *Gomega) ConfigureWithFailHandler(fail types.GomegaFailHandler) *Gomega {
+ g.Fail = fail
+ g.THelper = func() {}
+ return g
+}
+
+func (g *Gomega) ConfigureWithT(t types.GomegaTestingT) *Gomega {
+ g.Fail = func(message string, _ ...int) {
+ t.Helper()
+ t.Fatalf("\n%s", message)
+ }
+ g.THelper = t.Helper
+ return g
+}
+
+func (g *Gomega) Ω(atual interface{}, extra ...interface{}) types.Assertion {
+ return g.ExpectWithOffset(0, atual, extra...)
+}
+
+func (g *Gomega) Expect(atual interface{}, extra ...interface{}) types.Assertion {
+ return g.ExpectWithOffset(0, atual, extra...)
+}
+
+func (g *Gomega) ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) types.Assertion {
+ return NewAssertion(actual, g, offset, extra...)
+}
+
+func (g *Gomega) Eventually(actual interface{}, intervals ...interface{}) types.AsyncAssertion {
+ return g.EventuallyWithOffset(0, actual, intervals...)
+}
+
+func (g *Gomega) EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) types.AsyncAssertion {
+ timeoutInterval := g.DurationBundle.EventuallyTimeout
+ pollingInterval := g.DurationBundle.EventuallyPollingInterval
+ if len(intervals) > 0 {
+ timeoutInterval = toDuration(intervals[0])
+ }
+ if len(intervals) > 1 {
+ pollingInterval = toDuration(intervals[1])
+ }
+
+ return NewAsyncAssertion(AsyncAssertionTypeEventually, actual, g, timeoutInterval, pollingInterval, offset)
+}
+
+func (g *Gomega) Consistently(actual interface{}, intervals ...interface{}) types.AsyncAssertion {
+ return g.ConsistentlyWithOffset(0, actual, intervals...)
+}
+
+func (g *Gomega) ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) types.AsyncAssertion {
+ timeoutInterval := g.DurationBundle.ConsistentlyDuration
+ pollingInterval := g.DurationBundle.ConsistentlyPollingInterval
+ if len(intervals) > 0 {
+ timeoutInterval = toDuration(intervals[0])
+ }
+ if len(intervals) > 1 {
+ pollingInterval = toDuration(intervals[1])
+ }
+
+ return NewAsyncAssertion(AsyncAssertionTypeConsistently, actual, g, timeoutInterval, pollingInterval, offset)
+}
+
+func (g *Gomega) SetDefaultEventuallyTimeout(t time.Duration) {
+ g.DurationBundle.EventuallyTimeout = t
+}
+
+func (g *Gomega) SetDefaultEventuallyPollingInterval(t time.Duration) {
+ g.DurationBundle.EventuallyPollingInterval = t
+}
+
+func (g *Gomega) SetDefaultConsistentlyDuration(t time.Duration) {
+ g.DurationBundle.ConsistentlyDuration = t
+}
+
+func (g *Gomega) SetDefaultConsistentlyPollingInterval(t time.Duration) {
+ g.DurationBundle.ConsistentlyPollingInterval = t
+}
diff --git a/vendor/github.com/onsi/gomega/internal/oraclematcher/oracle_matcher.go b/vendor/github.com/onsi/gomega/internal/oraclematcher/oracle_matcher.go
deleted file mode 100644
index 66cad88a1..000000000
--- a/vendor/github.com/onsi/gomega/internal/oraclematcher/oracle_matcher.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package oraclematcher
-
-import "github.com/onsi/gomega/types"
-
-/*
-GomegaMatchers that also match the OracleMatcher interface can convey information about
-whether or not their result will change upon future attempts.
-
-This allows `Eventually` and `Consistently` to short circuit if success becomes impossible.
-
-For example, a process' exit code can never change. So, gexec's Exit matcher returns `true`
-for `MatchMayChangeInTheFuture` until the process exits, at which point it returns `false` forevermore.
-*/
-type OracleMatcher interface {
- MatchMayChangeInTheFuture(actual interface{}) bool
-}
-
-func MatchMayChangeInTheFuture(matcher types.GomegaMatcher, value interface{}) bool {
- oracleMatcher, ok := matcher.(OracleMatcher)
- if !ok {
- return true
- }
-
- return oracleMatcher.MatchMayChangeInTheFuture(value)
-}
diff --git a/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go b/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go
deleted file mode 100644
index bb27032f6..000000000
--- a/vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package testingtsupport
-
-import (
- "regexp"
- "runtime/debug"
- "strings"
-
- "github.com/onsi/gomega/types"
-)
-
-var StackTracePruneRE = regexp.MustCompile(`\/gomega\/|\/ginkgo\/|\/pkg\/testing\/|\/pkg\/runtime\/`)
-
-type EmptyTWithHelper struct{}
-
-func (e EmptyTWithHelper) Helper() {}
-
-type gomegaTestingT interface {
- Fatalf(format string, args ...interface{})
-}
-
-func BuildTestingTGomegaFailWrapper(t gomegaTestingT) *types.GomegaFailWrapper {
- tWithHelper, hasHelper := t.(types.TWithHelper)
- if !hasHelper {
- tWithHelper = EmptyTWithHelper{}
- }
-
- fail := func(message string, callerSkip ...int) {
- if hasHelper {
- tWithHelper.Helper()
- t.Fatalf("\n%s", message)
- } else {
- skip := 2
- if len(callerSkip) > 0 {
- skip += callerSkip[0]
- }
- stackTrace := pruneStack(string(debug.Stack()), skip)
- t.Fatalf("\n%s\n%s\n", stackTrace, message)
- }
- }
-
- return &types.GomegaFailWrapper{
- Fail: fail,
- TWithHelper: tWithHelper,
- }
-}
-
-func pruneStack(fullStackTrace string, skip int) string {
- stack := strings.Split(fullStackTrace, "\n")[1:]
- if len(stack) > 2*skip {
- stack = stack[2*skip:]
- }
- prunedStack := []string{}
- for i := 0; i < len(stack)/2; i++ {
- if !StackTracePruneRE.Match([]byte(stack[i*2])) {
- prunedStack = append(prunedStack, stack[i*2])
- prunedStack = append(prunedStack, stack[i*2+1])
- }
- }
- return strings.Join(prunedStack, "\n")
-}
diff --git a/vendor/github.com/onsi/gomega/matchers/and.go b/vendor/github.com/onsi/gomega/matchers/and.go
index d83a29164..6bd826adc 100644
--- a/vendor/github.com/onsi/gomega/matchers/and.go
+++ b/vendor/github.com/onsi/gomega/matchers/and.go
@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/onsi/gomega/format"
- "github.com/onsi/gomega/internal/oraclematcher"
"github.com/onsi/gomega/types"
)
@@ -52,12 +51,12 @@ func (m *AndMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
if m.firstFailedMatcher == nil {
// so all matchers succeeded.. Any one of them changing would change the result.
for _, matcher := range m.Matchers {
- if oraclematcher.MatchMayChangeInTheFuture(matcher, actual) {
+ if types.MatchMayChangeInTheFuture(matcher, actual) {
return true
}
}
return false // none of were going to change
}
// one of the matchers failed.. it must be able to change in order to affect the result
- return oraclematcher.MatchMayChangeInTheFuture(m.firstFailedMatcher, actual)
+ return types.MatchMayChangeInTheFuture(m.firstFailedMatcher, actual)
}
diff --git a/vendor/github.com/onsi/gomega/matchers/not.go b/vendor/github.com/onsi/gomega/matchers/not.go
index 2c91670bd..78b71910d 100644
--- a/vendor/github.com/onsi/gomega/matchers/not.go
+++ b/vendor/github.com/onsi/gomega/matchers/not.go
@@ -1,7 +1,6 @@
package matchers
import (
- "github.com/onsi/gomega/internal/oraclematcher"
"github.com/onsi/gomega/types"
)
@@ -26,5 +25,5 @@ func (m *NotMatcher) NegatedFailureMessage(actual interface{}) (message string)
}
func (m *NotMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
- return oraclematcher.MatchMayChangeInTheFuture(m.Matcher, actual) // just return m.Matcher's value
+ return types.MatchMayChangeInTheFuture(m.Matcher, actual) // just return m.Matcher's value
}
diff --git a/vendor/github.com/onsi/gomega/matchers/or.go b/vendor/github.com/onsi/gomega/matchers/or.go
index 3bf799800..841ae26ab 100644
--- a/vendor/github.com/onsi/gomega/matchers/or.go
+++ b/vendor/github.com/onsi/gomega/matchers/or.go
@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/onsi/gomega/format"
- "github.com/onsi/gomega/internal/oraclematcher"
"github.com/onsi/gomega/types"
)
@@ -54,11 +53,11 @@ func (m *OrMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
if m.firstSuccessfulMatcher != nil {
// one of the matchers succeeded.. it must be able to change in order to affect the result
- return oraclematcher.MatchMayChangeInTheFuture(m.firstSuccessfulMatcher, actual)
+ return types.MatchMayChangeInTheFuture(m.firstSuccessfulMatcher, actual)
} else {
// so all matchers failed.. Any one of them changing would change the result.
for _, matcher := range m.Matchers {
- if oraclematcher.MatchMayChangeInTheFuture(matcher, actual) {
+ if types.MatchMayChangeInTheFuture(matcher, actual) {
return true
}
}
diff --git a/vendor/github.com/onsi/gomega/matchers/with_transform.go b/vendor/github.com/onsi/gomega/matchers/with_transform.go
index f3dec9101..8a06bd384 100644
--- a/vendor/github.com/onsi/gomega/matchers/with_transform.go
+++ b/vendor/github.com/onsi/gomega/matchers/with_transform.go
@@ -4,7 +4,6 @@ import (
"fmt"
"reflect"
- "github.com/onsi/gomega/internal/oraclematcher"
"github.com/onsi/gomega/types"
)
@@ -77,5 +76,5 @@ func (m *WithTransformMatcher) MatchMayChangeInTheFuture(_ interface{}) bool {
// Querying the next matcher is fine if the transformer always will return the same value.
// But if the transformer is non-deterministic and returns a different value each time, then there
// is no point in querying the next matcher, since it can only comment on the last transformed value.
- return oraclematcher.MatchMayChangeInTheFuture(m.Matcher, m.transformedValue)
+ return types.MatchMayChangeInTheFuture(m.Matcher, m.transformedValue)
}
diff --git a/vendor/github.com/onsi/gomega/types/types.go b/vendor/github.com/onsi/gomega/types/types.go
index ac59a3a5a..c75fcb3cc 100644
--- a/vendor/github.com/onsi/gomega/types/types.go
+++ b/vendor/github.com/onsi/gomega/types/types.go
@@ -1,21 +1,35 @@
package types
-type TWithHelper interface {
- Helper()
-}
+import (
+ "time"
+)
type GomegaFailHandler func(message string, callerSkip ...int)
-type GomegaFailWrapper struct {
- Fail GomegaFailHandler
- TWithHelper TWithHelper
-}
-
//A simple *testing.T interface wrapper
type GomegaTestingT interface {
+ Helper()
Fatalf(format string, args ...interface{})
}
+// Gomega represents an object that can perform synchronous and assynchronous assertions with Gomega matchers
+type Gomega interface {
+ Ω(actual interface{}, extra ...interface{}) Assertion
+ Expect(actual interface{}, extra ...interface{}) Assertion
+ ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Assertion
+
+ Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion
+ EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion
+
+ Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion
+ ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion
+
+ SetDefaultEventuallyTimeout(time.Duration)
+ SetDefaultEventuallyPollingInterval(time.Duration)
+ SetDefaultConsistentlyDuration(time.Duration)
+ SetDefaultConsistentlyPollingInterval(time.Duration)
+}
+
//All Gomega matchers must implement the GomegaMatcher interface
//
//For details on writing custom matchers, check out: http://onsi.github.io/gomega/#adding-your-own-matchers
@@ -24,3 +38,42 @@ type GomegaMatcher interface {
FailureMessage(actual interface{}) (message string)
NegatedFailureMessage(actual interface{}) (message string)
}
+
+/*
+GomegaMatchers that also match the OracleMatcher interface can convey information about
+whether or not their result will change upon future attempts.
+
+This allows `Eventually` and `Consistently` to short circuit if success becomes impossible.
+
+For example, a process' exit code can never change. So, gexec's Exit matcher returns `true`
+for `MatchMayChangeInTheFuture` until the process exits, at which point it returns `false` forevermore.
+*/
+type OracleMatcher interface {
+ MatchMayChangeInTheFuture(actual interface{}) bool
+}
+
+func MatchMayChangeInTheFuture(matcher GomegaMatcher, value interface{}) bool {
+ oracleMatcher, ok := matcher.(OracleMatcher)
+ if !ok {
+ return true
+ }
+
+ return oracleMatcher.MatchMayChangeInTheFuture(value)
+}
+
+// AsyncAssertions are returned by Eventually and Consistently and enable matchers to be polled repeatedly to ensure
+// they are eventually satisfied
+type AsyncAssertion interface {
+ Should(matcher GomegaMatcher, optionalDescription ...interface{}) bool
+ ShouldNot(matcher GomegaMatcher, optionalDescription ...interface{}) bool
+}
+
+// Assertions are returned by Ω and Expect and enable assertions against Gomega matchers
+type Assertion interface {
+ Should(matcher GomegaMatcher, optionalDescription ...interface{}) bool
+ ShouldNot(matcher GomegaMatcher, optionalDescription ...interface{}) bool
+
+ To(matcher GomegaMatcher, optionalDescription ...interface{}) bool
+ ToNot(matcher GomegaMatcher, optionalDescription ...interface{}) bool
+ NotTo(matcher GomegaMatcher, optionalDescription ...interface{}) bool
+}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 541dc37dc..189ffbf0f 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -488,16 +488,12 @@ github.com/onsi/ginkgo/reporters/stenographer
github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable
github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty
github.com/onsi/ginkgo/types
-# github.com/onsi/gomega v1.14.0
+# github.com/onsi/gomega v1.15.0
github.com/onsi/gomega
github.com/onsi/gomega/format
github.com/onsi/gomega/gbytes
github.com/onsi/gomega/gexec
-github.com/onsi/gomega/internal/assertion
-github.com/onsi/gomega/internal/asyncassertion
-github.com/onsi/gomega/internal/defaults
-github.com/onsi/gomega/internal/oraclematcher
-github.com/onsi/gomega/internal/testingtsupport
+github.com/onsi/gomega/internal
github.com/onsi/gomega/matchers
github.com/onsi/gomega/matchers/support/goraph/bipartitegraph
github.com/onsi/gomega/matchers/support/goraph/edge