mirror of
https://github.com/containers/podman.git
synced 2025-06-29 15:08:09 +08:00
Merge pull request #16126 from containers/dependabot/go_modules/github.com/onsi/gomega-1.22.1
build(deps): bump github.com/onsi/gomega from 1.20.2 to 1.22.1
This commit is contained in:
2
go.mod
2
go.mod
@ -42,7 +42,7 @@ require (
|
|||||||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
|
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
|
||||||
github.com/nxadm/tail v1.4.8
|
github.com/nxadm/tail v1.4.8
|
||||||
github.com/onsi/ginkgo v1.16.5
|
github.com/onsi/ginkgo v1.16.5
|
||||||
github.com/onsi/gomega v1.20.2
|
github.com/onsi/gomega v1.22.1
|
||||||
github.com/opencontainers/go-digest v1.0.0
|
github.com/opencontainers/go-digest v1.0.0
|
||||||
github.com/opencontainers/image-spec v1.1.0-rc2
|
github.com/opencontainers/image-spec v1.1.0-rc2
|
||||||
github.com/opencontainers/runc v1.1.4
|
github.com/opencontainers/runc v1.1.4
|
||||||
|
7
go.sum
7
go.sum
@ -1344,8 +1344,9 @@ github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3
|
|||||||
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||||
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
|
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
|
||||||
github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
|
github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
|
||||||
github.com/onsi/ginkgo/v2 v2.2.0 h1:3ZNA3L1c5FYDFTTxbFeVGGD8jYvjYauHD30YgLxVsNI=
|
|
||||||
github.com/onsi/ginkgo/v2 v2.2.0/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
|
github.com/onsi/ginkgo/v2 v2.2.0/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.3.0 h1:kUMoxMoQG3ogk/QWyKh3zibV7BKZ+xBpWil1cTylVqc=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.3.0/go.mod h1:Eew0uilEqZmIEZr8JrvYlvOM7Rr6xzTmMV8AyFNU9d0=
|
||||||
github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||||
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||||
@ -1361,8 +1362,10 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl
|
|||||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||||
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
|
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
|
||||||
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
|
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
|
||||||
github.com/onsi/gomega v1.20.2 h1:8uQq0zMgLEfa0vRrrBgaJF2gyW9Da9BmfGV+OyUzfkY=
|
|
||||||
github.com/onsi/gomega v1.20.2/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
|
github.com/onsi/gomega v1.20.2/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
|
||||||
|
github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
|
||||||
|
github.com/onsi/gomega v1.22.1 h1:pY8O4lBfsHKZHM/6nrxkhVPUznOlIu3quZcKP/M20KI=
|
||||||
|
github.com/onsi/gomega v1.22.1/go.mod h1:x6n7VNe4hw0vkyYUM4mjIXx3JbLiPaBPNgB7PRQ1tuM=
|
||||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
||||||
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
||||||
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
||||||
|
51
vendor/github.com/onsi/gomega/CHANGELOG.md
generated
vendored
51
vendor/github.com/onsi/gomega/CHANGELOG.md
generated
vendored
@ -1,3 +1,54 @@
|
|||||||
|
## 1.22.1
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
- When passed a context and no explicit timeout, Eventually will only timeout when the context is cancelled [e5105cf]
|
||||||
|
- Allow StopTrying() to be wrapped [bf3cba9]
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
- bump to ginkgo v2.3.0 [c5d5c39]
|
||||||
|
|
||||||
|
## 1.22.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
Several improvements have been made to `Eventually` and `Consistently` in this and the most recent releases:
|
||||||
|
|
||||||
|
- Eventually and Consistently can take a context.Context [65c01bc]
|
||||||
|
This enables integration with Ginkgo 2.3.0's interruptible nodes and node timeouts.
|
||||||
|
- Eventually and Consistently that are passed a SpecContext can provide reports when an interrupt occurs [0d063c9]
|
||||||
|
- Eventually/Consistently will forward an attached context to functions that ask for one [e2091c5]
|
||||||
|
- Eventually/Consistently supports passing arguments to functions via WithArguments() [a2dc7c3]
|
||||||
|
- Eventually and Consistently can now be stopped early with StopTrying(message) and StopTrying(message).Now() [52976bb]
|
||||||
|
|
||||||
|
These improvements are all documented in [Gomega's docs](https://onsi.github.io/gomega/#making-asynchronous-assertions)
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
|
## 1.21.1
|
||||||
|
|
||||||
|
### Features
|
||||||
|
- Eventually and Consistently that are passed a SpecContext can provide reports when an interrupt occurs [0d063c9]
|
||||||
|
|
||||||
|
## 1.21.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
- Eventually and Consistently can take a context.Context [65c01bc]
|
||||||
|
This enables integration with Ginkgo 2.3.0's interruptible nodes and node timeouts.
|
||||||
|
- Introduces Eventually.Within.ProbeEvery with tests and documentation (#591) [f633800]
|
||||||
|
- New BeKeyOf matcher with documentation and unit tests (#590) [fb586b3]
|
||||||
|
|
||||||
|
## Fixes
|
||||||
|
- Cover the entire gmeasure suite with leak detection [8c54344]
|
||||||
|
- Fix gmeasure leak [119d4ce]
|
||||||
|
- Ignore new Ginkgo ProgressSignal goroutine in gleak [ba548e2]
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
|
- Fixes crashes on newer Ruby 3 installations by upgrading github-pages gem dependency (#596) [12469a0]
|
||||||
|
|
||||||
|
|
||||||
## 1.20.2
|
## 1.20.2
|
||||||
|
|
||||||
## Fixes
|
## Fixes
|
||||||
|
8
vendor/github.com/onsi/gomega/RELEASING.md
generated
vendored
8
vendor/github.com/onsi/gomega/RELEASING.md
generated
vendored
@ -1,7 +1,13 @@
|
|||||||
A Gomega release is a tagged sha and a GitHub release. To cut a release:
|
A Gomega release is a tagged sha and a GitHub release. To cut a release:
|
||||||
|
|
||||||
1. Ensure CHANGELOG.md is up to date.
|
1. Ensure CHANGELOG.md is up to date.
|
||||||
- Use `git log --pretty=format:'- %s [%h]' HEAD...vX.X.X` to list all the commits since the last release
|
- Use
|
||||||
|
```bash
|
||||||
|
LAST_VERSION=$(git tag --sort=version:refname | tail -n1)
|
||||||
|
CHANGES=$(git log --pretty=format:'- %s [%h]' HEAD...$LAST_VERSION)
|
||||||
|
echo -e "## NEXT\n\n$CHANGES\n\n### Features\n\n## Fixes\n\n## Maintenance\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
|
||||||
|
```
|
||||||
|
to update the changelog
|
||||||
- Categorize the changes into
|
- Categorize the changes into
|
||||||
- Breaking Changes (requires a major version)
|
- Breaking Changes (requires a major version)
|
||||||
- New Features (minor version)
|
- New Features (minor version)
|
||||||
|
99
vendor/github.com/onsi/gomega/gomega_dsl.go
generated
vendored
99
vendor/github.com/onsi/gomega/gomega_dsl.go
generated
vendored
@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/onsi/gomega/types"
|
"github.com/onsi/gomega/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const GOMEGA_VERSION = "1.20.2"
|
const GOMEGA_VERSION = "1.22.1"
|
||||||
|
|
||||||
const nilGomegaPanic = `You are trying to make an assertion, but haven't registered Gomega's fail handler.
|
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().
|
If you're using Ginkgo then you probably forgot to put your assertion in an It().
|
||||||
@ -233,7 +233,7 @@ func ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Asse
|
|||||||
Eventually enables making assertions on asynchronous behavior.
|
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.
|
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).
|
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). In addition an optional context.Context can be passed in - Eventually will keep trying until either the timeout epxires or the context is cancelled, whichever comes first.
|
||||||
|
|
||||||
Eventually works with any Gomega compatible matcher and supports making assertions against three categories of actual value:
|
Eventually works with any Gomega compatible matcher and supports making assertions against three categories of actual value:
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ this will trigger Go's race detector as the goroutine polling via Eventually wil
|
|||||||
|
|
||||||
**Category 2: Make Eventually assertions on functions**
|
**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.
|
Eventually can be passed functions that **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:
|
For example:
|
||||||
|
|
||||||
@ -286,7 +286,27 @@ Then
|
|||||||
|
|
||||||
will pass only if and when the returned error is nil *and* the returned string satisfies the matcher.
|
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.
|
Eventually can also accept functions that take arguments, however you must provide those arguments using .WithArguments(). For example, consider a function that takes a user-id and makes a network request to fetch a full name:
|
||||||
|
func FetchFullName(userId int) (string, error)
|
||||||
|
|
||||||
|
You can poll this function like so:
|
||||||
|
Eventually(FetchFullName).WithArguments(1138).Should(Equal("Wookie"))
|
||||||
|
|
||||||
|
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. A common practice here is to use a context. Here's an example that combines Ginkgo's spec timeout support with Eventually:
|
||||||
|
|
||||||
|
It("fetches the correct count", func(ctx SpecContext) {
|
||||||
|
Eventually(func() int {
|
||||||
|
return client.FetchCount(ctx, "/users")
|
||||||
|
}, ctx).Should(BeNumerically(">=", 17))
|
||||||
|
}, SpecTimeout(time.Second))
|
||||||
|
|
||||||
|
you an also use Eventually().WithContext(ctx) to pass in the context. Passed-in contexts play nicely with paseed-in arguments as long as the context appears first. You can rewrite the above example as:
|
||||||
|
|
||||||
|
It("fetches the correct count", func(ctx SpecContext) {
|
||||||
|
Eventually(client.FetchCount).WithContext(ctx).WithArguments("/users").Should(BeNumerically(">=", 17))
|
||||||
|
}, SpecTimeout(time.Second))
|
||||||
|
|
||||||
|
Either way the context passd to Eventually is also passed to the underlying funciton. Now, when Ginkgo cancels the context both the FetchCount client and Gomega will be informed and can exit.
|
||||||
|
|
||||||
**Category 3: Making assertions _in_ the function passed into Eventually**
|
**Category 3: Making assertions _in_ the function passed into Eventually**
|
||||||
|
|
||||||
@ -316,12 +336,28 @@ For example:
|
|||||||
|
|
||||||
will rerun the function until all assertions pass.
|
will rerun the function until all assertions pass.
|
||||||
|
|
||||||
`Eventually` specifying a timeout interval (and an optional polling interval) are
|
You can also pass additional arugments to functions that take a Gomega. The only rule is that the Gomega argument must be first. If you also want to pass the context attached to Eventually you must ensure that is the second argument. For example:
|
||||||
the same as `Eventually(...).WithTimeout` or `Eventually(...).WithTimeout(...).WithPolling`.
|
|
||||||
|
Eventually(func(g Gomega, ctx context.Context, path string, expected ...string){
|
||||||
|
tok, err := client.GetToken(ctx)
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
elements, err := client.Fetch(ctx, tok, path)
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
g.Expect(elements).To(ConsistOf(expected))
|
||||||
|
}).WithContext(ctx).WithArguments("/names", "Joe", "Jane", "Sam").Should(Succeed())
|
||||||
|
|
||||||
|
Finally, in addition to passing timeouts and a context to Eventually you can be more explicit with Eventually's chaining configuration methods:
|
||||||
|
|
||||||
|
Eventually(..., "1s", "2s", ctx).Should(...)
|
||||||
|
|
||||||
|
is equivalent to
|
||||||
|
|
||||||
|
Eventually(...).WithTimeout(time.Second).WithPolling(2*time.Second).WithContext(ctx).Should(...)
|
||||||
*/
|
*/
|
||||||
func Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion {
|
func Eventually(actual interface{}, args ...interface{}) AsyncAssertion {
|
||||||
ensureDefaultGomegaIsConfigured()
|
ensureDefaultGomegaIsConfigured()
|
||||||
return Default.Eventually(actual, intervals...)
|
return Default.Eventually(actual, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventuallyWithOffset operates like Eventually but takes an additional
|
// EventuallyWithOffset operates like Eventually but takes an additional
|
||||||
@ -333,9 +369,9 @@ func Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion {
|
|||||||
// `EventuallyWithOffset` specifying a timeout interval (and an optional polling interval) are
|
// `EventuallyWithOffset` specifying a timeout interval (and an optional polling interval) are
|
||||||
// the same as `Eventually(...).WithOffset(...).WithTimeout` or
|
// the same as `Eventually(...).WithOffset(...).WithTimeout` or
|
||||||
// `Eventually(...).WithOffset(...).WithTimeout(...).WithPolling`.
|
// `Eventually(...).WithOffset(...).WithTimeout(...).WithPolling`.
|
||||||
func EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion {
|
func EventuallyWithOffset(offset int, actual interface{}, args ...interface{}) AsyncAssertion {
|
||||||
ensureDefaultGomegaIsConfigured()
|
ensureDefaultGomegaIsConfigured()
|
||||||
return Default.EventuallyWithOffset(offset, actual, intervals...)
|
return Default.EventuallyWithOffset(offset, actual, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -343,7 +379,7 @@ Consistently, like Eventually, enables making assertions on asynchronous behavio
|
|||||||
|
|
||||||
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.
|
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 argument 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.
|
Both the total waiting duration and the polling interval are configurable as optional arguments. The first optional argument 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. You can also pass in an optional context.Context - Consistently will exit early (with a failure) if the context is cancelled before the waiting duration expires.
|
||||||
|
|
||||||
Consistently accepts the same three categories of actual as Eventually, check the Eventually docs to learn more.
|
Consistently accepts the same three categories of actual as Eventually, check the Eventually docs to learn more.
|
||||||
|
|
||||||
@ -353,9 +389,9 @@ Consistently is useful in cases where you want to assert that something *does no
|
|||||||
|
|
||||||
This will block for 200 milliseconds and repeatedly check the channel and ensure nothing has been received.
|
This will block for 200 milliseconds and repeatedly check the channel and ensure nothing has been received.
|
||||||
*/
|
*/
|
||||||
func Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion {
|
func Consistently(actual interface{}, args ...interface{}) AsyncAssertion {
|
||||||
ensureDefaultGomegaIsConfigured()
|
ensureDefaultGomegaIsConfigured()
|
||||||
return Default.Consistently(actual, intervals...)
|
return Default.Consistently(actual, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConsistentlyWithOffset operates like Consistently but takes an additional
|
// ConsistentlyWithOffset operates like Consistently but takes an additional
|
||||||
@ -364,11 +400,44 @@ func Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion {
|
|||||||
//
|
//
|
||||||
// `ConsistentlyWithOffset` is the same as `Consistently(...).WithOffset` and
|
// `ConsistentlyWithOffset` is the same as `Consistently(...).WithOffset` and
|
||||||
// optional `WithTimeout` and `WithPolling`.
|
// optional `WithTimeout` and `WithPolling`.
|
||||||
func ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion {
|
func ConsistentlyWithOffset(offset int, actual interface{}, args ...interface{}) AsyncAssertion {
|
||||||
ensureDefaultGomegaIsConfigured()
|
ensureDefaultGomegaIsConfigured()
|
||||||
return Default.ConsistentlyWithOffset(offset, actual, intervals...)
|
return Default.ConsistentlyWithOffset(offset, actual, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
StopTrying can be used to signal to Eventually and Consistently that the polled function will not change
|
||||||
|
and that they should stop trying. In the case of Eventually, if a match does not occur in this, final, iteration then a failure will result. In the case of Consistently, as long as this last iteration satisfies the match, the assertion will be considered successful.
|
||||||
|
|
||||||
|
You can send the StopTrying signal by either returning a StopTrying("message") messages as an error from your passed-in function _or_ by calling StopTrying("message").Now() to trigger a panic and end execution.
|
||||||
|
|
||||||
|
Here are a couple of examples. This is how you might use StopTrying() as an error to signal that Eventually should stop:
|
||||||
|
|
||||||
|
playerIndex, numPlayers := 0, 11
|
||||||
|
Eventually(func() (string, error) {
|
||||||
|
name := client.FetchPlayer(playerIndex)
|
||||||
|
playerIndex += 1
|
||||||
|
if playerIndex == numPlayers {
|
||||||
|
return name, StopTrying("No more players left")
|
||||||
|
} else {
|
||||||
|
return name, nil
|
||||||
|
}
|
||||||
|
}).Should(Equal("Patrick Mahomes"))
|
||||||
|
|
||||||
|
note that the final `name` returned alongside `StopTrying()` will be processed.
|
||||||
|
|
||||||
|
And here's an example where `StopTrying().Now()` is called to halt execution immediately:
|
||||||
|
|
||||||
|
Eventually(func() []string {
|
||||||
|
names, err := client.FetchAllPlayers()
|
||||||
|
if err == client.IRRECOVERABLE_ERROR {
|
||||||
|
StopTrying("Irrecoverable error occurred").Now()
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
}).Should(ContainElement("Patrick Mahomes"))
|
||||||
|
*/
|
||||||
|
var StopTrying = internal.StopTrying
|
||||||
|
|
||||||
// SetDefaultEventuallyTimeout sets the default timeout duration for Eventually. Eventually will repeatedly poll your condition until it succeeds, or until this timeout elapses.
|
// 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) {
|
func SetDefaultEventuallyTimeout(t time.Duration) {
|
||||||
Default.SetDefaultEventuallyTimeout(t)
|
Default.SetDefaultEventuallyTimeout(t)
|
||||||
|
426
vendor/github.com/onsi/gomega/internal/async_assertion.go
generated
vendored
426
vendor/github.com/onsi/gomega/internal/async_assertion.go
generated
vendored
@ -1,15 +1,61 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/onsi/gomega/types"
|
"github.com/onsi/gomega/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type StopTryingError interface {
|
||||||
|
error
|
||||||
|
Now()
|
||||||
|
wasViaPanic() bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func asStopTryingError(actual interface{}) (StopTryingError, bool) {
|
||||||
|
if actual == nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
if actualErr, ok := actual.(error); ok {
|
||||||
|
var target *stopTryingError
|
||||||
|
if errors.As(actualErr, &target) {
|
||||||
|
return target, true
|
||||||
|
} else {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
type stopTryingError struct {
|
||||||
|
message string
|
||||||
|
viaPanic bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stopTryingError) Error() string {
|
||||||
|
return s.message
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stopTryingError) Now() {
|
||||||
|
s.viaPanic = true
|
||||||
|
panic(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stopTryingError) wasViaPanic() bool {
|
||||||
|
return s.viaPanic
|
||||||
|
}
|
||||||
|
|
||||||
|
var StopTrying = func(message string) StopTryingError {
|
||||||
|
return &stopTryingError{message: message}
|
||||||
|
}
|
||||||
|
|
||||||
type AsyncAssertionType uint
|
type AsyncAssertionType uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -17,71 +63,43 @@ const (
|
|||||||
AsyncAssertionTypeConsistently
|
AsyncAssertionTypeConsistently
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (at AsyncAssertionType) String() string {
|
||||||
|
switch at {
|
||||||
|
case AsyncAssertionTypeEventually:
|
||||||
|
return "Eventually"
|
||||||
|
case AsyncAssertionTypeConsistently:
|
||||||
|
return "Consistently"
|
||||||
|
}
|
||||||
|
return "INVALID ASYNC ASSERTION TYPE"
|
||||||
|
}
|
||||||
|
|
||||||
type AsyncAssertion struct {
|
type AsyncAssertion struct {
|
||||||
asyncType AsyncAssertionType
|
asyncType AsyncAssertionType
|
||||||
|
|
||||||
actualIsFunc bool
|
actualIsFunc bool
|
||||||
actualValue interface{}
|
actual interface{}
|
||||||
actualFunc func() ([]reflect.Value, error)
|
argsToForward []interface{}
|
||||||
|
|
||||||
timeoutInterval time.Duration
|
timeoutInterval time.Duration
|
||||||
pollingInterval time.Duration
|
pollingInterval time.Duration
|
||||||
|
ctx context.Context
|
||||||
offset int
|
offset int
|
||||||
g *Gomega
|
g *Gomega
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAsyncAssertion(asyncType AsyncAssertionType, actualInput interface{}, g *Gomega, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
|
func NewAsyncAssertion(asyncType AsyncAssertionType, actualInput interface{}, g *Gomega, timeoutInterval time.Duration, pollingInterval time.Duration, ctx context.Context, offset int) *AsyncAssertion {
|
||||||
out := &AsyncAssertion{
|
out := &AsyncAssertion{
|
||||||
asyncType: asyncType,
|
asyncType: asyncType,
|
||||||
timeoutInterval: timeoutInterval,
|
timeoutInterval: timeoutInterval,
|
||||||
pollingInterval: pollingInterval,
|
pollingInterval: pollingInterval,
|
||||||
offset: offset,
|
offset: offset,
|
||||||
|
ctx: ctx,
|
||||||
g: g,
|
g: g,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch actualType := reflect.TypeOf(actualInput); {
|
out.actual = actualInput
|
||||||
case actualInput == nil || actualType.Kind() != reflect.Func:
|
if actualInput != nil && reflect.TypeOf(actualInput).Kind() == reflect.Func {
|
||||||
out.actualValue = actualInput
|
|
||||||
case actualType.NumIn() == 0 && actualType.NumOut() > 0:
|
|
||||||
out.actualIsFunc = true
|
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
|
return out
|
||||||
@ -102,6 +120,26 @@ func (assertion *AsyncAssertion) WithPolling(interval time.Duration) types.Async
|
|||||||
return assertion
|
return assertion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) Within(timeout time.Duration) types.AsyncAssertion {
|
||||||
|
assertion.timeoutInterval = timeout
|
||||||
|
return assertion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) ProbeEvery(interval time.Duration) types.AsyncAssertion {
|
||||||
|
assertion.pollingInterval = interval
|
||||||
|
return assertion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) WithContext(ctx context.Context) types.AsyncAssertion {
|
||||||
|
assertion.ctx = ctx
|
||||||
|
return assertion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) WithArguments(argsToForward ...interface{}) types.AsyncAssertion {
|
||||||
|
assertion.argsToForward = argsToForward
|
||||||
|
return assertion
|
||||||
|
}
|
||||||
|
|
||||||
func (assertion *AsyncAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
func (assertion *AsyncAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||||
assertion.g.THelper()
|
assertion.g.THelper()
|
||||||
vetOptionalDescription("Asynchronous assertion", optionalDescription...)
|
vetOptionalDescription("Asynchronous assertion", optionalDescription...)
|
||||||
@ -126,50 +164,225 @@ func (assertion *AsyncAssertion) buildDescription(optionalDescription ...interfa
|
|||||||
return fmt.Sprintf(optionalDescription[0].(string), optionalDescription[1:]...) + "\n"
|
return fmt.Sprintf(optionalDescription[0].(string), optionalDescription[1:]...) + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (assertion *AsyncAssertion) pollActual() (interface{}, error) {
|
func (assertion *AsyncAssertion) processReturnValues(values []reflect.Value) (interface{}, error, StopTryingError) {
|
||||||
|
var err error
|
||||||
|
var stopTrying StopTryingError
|
||||||
|
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil, fmt.Errorf("No values were returned by the function passed to Gomega"), stopTrying
|
||||||
|
}
|
||||||
|
actual := values[0].Interface()
|
||||||
|
if stopTryingErr, ok := asStopTryingError(actual); ok {
|
||||||
|
stopTrying = stopTryingErr
|
||||||
|
}
|
||||||
|
for i, extraValue := range values[1:] {
|
||||||
|
extra := extraValue.Interface()
|
||||||
|
if extra == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if stopTryingErr, ok := asStopTryingError(extra); ok {
|
||||||
|
stopTrying = stopTryingErr
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
zero := reflect.Zero(reflect.TypeOf(extra)).Interface()
|
||||||
|
if reflect.DeepEqual(extra, zero) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
err = fmt.Errorf("Unexpected non-nil/non-zero argument at index %d:\n\t<%T>: %#v", i+1, extra, extra)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return actual, err, stopTrying
|
||||||
|
}
|
||||||
|
|
||||||
|
var gomegaType = reflect.TypeOf((*types.Gomega)(nil)).Elem()
|
||||||
|
var contextType = reflect.TypeOf(new(context.Context)).Elem()
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) invalidFunctionError(t reflect.Type) error {
|
||||||
|
return fmt.Errorf(`The function passed to %s had an invalid signature of %s. Functions passed to %s must either:
|
||||||
|
|
||||||
|
(a) have return values or
|
||||||
|
(b) take a Gomega interface as their first argument and use that Gomega instance to make assertions.
|
||||||
|
|
||||||
|
You can learn more at https://onsi.github.io/gomega/#eventually
|
||||||
|
`, assertion.asyncType, t, assertion.asyncType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) noConfiguredContextForFunctionError() error {
|
||||||
|
return fmt.Errorf(`The function passed to %s requested a context.Context, but no context has been provided. Please pass one in using %s().WithContext().
|
||||||
|
|
||||||
|
You can learn more at https://onsi.github.io/gomega/#eventually
|
||||||
|
`, assertion.asyncType, assertion.asyncType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) argumentMismatchError(t reflect.Type, numProvided int) error {
|
||||||
|
have := "have"
|
||||||
|
if numProvided == 1 {
|
||||||
|
have = "has"
|
||||||
|
}
|
||||||
|
return fmt.Errorf(`The function passed to %s has signature %s takes %d arguments but %d %s been provided. Please use %s().WithArguments() to pass the corect set of arguments.
|
||||||
|
|
||||||
|
You can learn more at https://onsi.github.io/gomega/#eventually
|
||||||
|
`, assertion.asyncType, t, t.NumIn(), numProvided, have, assertion.asyncType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) buildActualPoller() (func() (interface{}, error, StopTryingError), error) {
|
||||||
if !assertion.actualIsFunc {
|
if !assertion.actualIsFunc {
|
||||||
return assertion.actualValue, nil
|
return func() (interface{}, error, StopTryingError) { return assertion.actual, nil, nil }, nil
|
||||||
|
}
|
||||||
|
actualValue := reflect.ValueOf(assertion.actual)
|
||||||
|
actualType := reflect.TypeOf(assertion.actual)
|
||||||
|
numIn, numOut, isVariadic := actualType.NumIn(), actualType.NumOut(), actualType.IsVariadic()
|
||||||
|
|
||||||
|
if numIn == 0 && numOut == 0 {
|
||||||
|
return nil, assertion.invalidFunctionError(actualType)
|
||||||
|
} else if numIn == 0 {
|
||||||
|
return func() (actual interface{}, err error, stopTrying StopTryingError) {
|
||||||
|
defer func() {
|
||||||
|
if e := recover(); e != nil {
|
||||||
|
if stopTryingErr, ok := asStopTryingError(e); ok {
|
||||||
|
stopTrying = stopTryingErr
|
||||||
|
} else {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
actual, err, stopTrying = assertion.processReturnValues(actualValue.Call([]reflect.Value{}))
|
||||||
|
return
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
takesGomega, takesContext := actualType.In(0).Implements(gomegaType), actualType.In(0).Implements(contextType)
|
||||||
|
if takesGomega && numIn > 1 && actualType.In(1).Implements(contextType) {
|
||||||
|
takesContext = true
|
||||||
|
}
|
||||||
|
if takesContext && len(assertion.argsToForward) > 0 && reflect.TypeOf(assertion.argsToForward[0]).Implements(contextType) {
|
||||||
|
takesContext = false
|
||||||
|
}
|
||||||
|
if !takesGomega && numOut == 0 {
|
||||||
|
return nil, assertion.invalidFunctionError(actualType)
|
||||||
|
}
|
||||||
|
if takesContext && assertion.ctx == nil {
|
||||||
|
return nil, assertion.noConfiguredContextForFunctionError()
|
||||||
}
|
}
|
||||||
|
|
||||||
values, err := assertion.actualFunc()
|
var assertionFailure error
|
||||||
if err != nil {
|
inValues := []reflect.Value{}
|
||||||
return nil, err
|
if takesGomega {
|
||||||
|
inValues = append(inValues, reflect.ValueOf(NewGomega(assertion.g.DurationBundle).ConfigureWithFailHandler(func(message string, callerSkip ...int) {
|
||||||
|
skip := 0
|
||||||
|
if len(callerSkip) > 0 {
|
||||||
|
skip = callerSkip[0]
|
||||||
}
|
}
|
||||||
extras := []interface{}{nil}
|
_, file, line, _ := runtime.Caller(skip + 1)
|
||||||
for _, value := range values[1:] {
|
assertionFailure = fmt.Errorf("Assertion in callback at %s:%d failed:\n%s", file, line, message)
|
||||||
extras = append(extras, value.Interface())
|
panic("stop execution")
|
||||||
|
})))
|
||||||
}
|
}
|
||||||
success, message := vetActuals(extras, 0)
|
if takesContext {
|
||||||
if !success {
|
inValues = append(inValues, reflect.ValueOf(assertion.ctx))
|
||||||
return nil, errors.New(message)
|
}
|
||||||
|
for _, arg := range assertion.argsToForward {
|
||||||
|
inValues = append(inValues, reflect.ValueOf(arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
return values[0].Interface(), nil
|
if !isVariadic && numIn != len(inValues) {
|
||||||
|
return nil, assertion.argumentMismatchError(actualType, len(inValues))
|
||||||
|
} else if isVariadic && len(inValues) < numIn-1 {
|
||||||
|
return nil, assertion.argumentMismatchError(actualType, len(inValues))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (assertion *AsyncAssertion) matcherMayChange(matcher types.GomegaMatcher, value interface{}) bool {
|
return func() (actual interface{}, err error, stopTrying StopTryingError) {
|
||||||
if assertion.actualIsFunc {
|
var values []reflect.Value
|
||||||
return true
|
assertionFailure = nil
|
||||||
|
defer func() {
|
||||||
|
if numOut == 0 {
|
||||||
|
actual = assertionFailure
|
||||||
|
} else {
|
||||||
|
actual, err, stopTrying = assertion.processReturnValues(values)
|
||||||
|
if assertionFailure != nil {
|
||||||
|
err = assertionFailure
|
||||||
}
|
}
|
||||||
return types.MatchMayChangeInTheFuture(matcher, value)
|
}
|
||||||
|
if e := recover(); e != nil {
|
||||||
|
if stopTryingErr, ok := asStopTryingError(e); ok {
|
||||||
|
stopTrying = stopTryingErr
|
||||||
|
} else if assertionFailure == nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
values = actualValue.Call(inValues)
|
||||||
|
return
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) matcherSaysStopTrying(matcher types.GomegaMatcher, value interface{}) StopTryingError {
|
||||||
|
if assertion.actualIsFunc || types.MatchMayChangeInTheFuture(matcher, value) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return StopTrying("No future change is possible. Bailing out early")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) afterTimeout() <-chan time.Time {
|
||||||
|
if assertion.timeoutInterval >= 0 {
|
||||||
|
return time.After(assertion.timeoutInterval)
|
||||||
|
}
|
||||||
|
|
||||||
|
if assertion.asyncType == AsyncAssertionTypeConsistently {
|
||||||
|
return time.After(assertion.g.DurationBundle.ConsistentlyDuration)
|
||||||
|
} else {
|
||||||
|
if assertion.ctx == nil {
|
||||||
|
return time.After(assertion.g.DurationBundle.EventuallyTimeout)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (assertion *AsyncAssertion) afterPolling() <-chan time.Time {
|
||||||
|
if assertion.pollingInterval >= 0 {
|
||||||
|
return time.After(assertion.pollingInterval)
|
||||||
|
}
|
||||||
|
if assertion.asyncType == AsyncAssertionTypeConsistently {
|
||||||
|
return time.After(assertion.g.DurationBundle.ConsistentlyPollingInterval)
|
||||||
|
} else {
|
||||||
|
return time.After(assertion.g.DurationBundle.EventuallyPollingInterval)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type contextWithAttachProgressReporter interface {
|
||||||
|
AttachProgressReporter(func() string) func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
|
func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
|
||||||
timer := time.Now()
|
timer := time.Now()
|
||||||
timeout := time.After(assertion.timeoutInterval)
|
timeout := assertion.afterTimeout()
|
||||||
|
lock := sync.Mutex{}
|
||||||
|
|
||||||
var matches bool
|
var matches bool
|
||||||
var err error
|
var err error
|
||||||
mayChange := true
|
|
||||||
value, err := assertion.pollActual()
|
|
||||||
if err == nil {
|
|
||||||
mayChange = assertion.matcherMayChange(matcher, value)
|
|
||||||
matches, err = matcher.Match(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
assertion.g.THelper()
|
assertion.g.THelper()
|
||||||
|
|
||||||
fail := func(preamble string) {
|
pollActual, err := assertion.buildActualPoller()
|
||||||
|
if err != nil {
|
||||||
|
assertion.g.Fail(err.Error(), 2+assertion.offset)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err, stopTrying := pollActual()
|
||||||
|
if err == nil {
|
||||||
|
if stopTrying == nil {
|
||||||
|
stopTrying = assertion.matcherSaysStopTrying(matcher, value)
|
||||||
|
}
|
||||||
|
matches, err = matcher.Match(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
messageGenerator := func() string {
|
||||||
|
// can be called out of band by Ginkgo if the user requests a progress report
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
errMsg := ""
|
errMsg := ""
|
||||||
message := ""
|
message := ""
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,9 +394,22 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
|
|||||||
message = matcher.NegatedFailureMessage(value)
|
message = matcher.NegatedFailureMessage(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertion.g.THelper()
|
|
||||||
description := assertion.buildDescription(optionalDescription...)
|
description := assertion.buildDescription(optionalDescription...)
|
||||||
assertion.g.Fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
|
return fmt.Sprintf("%s%s%s", description, message, errMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
fail := func(preamble string) {
|
||||||
|
assertion.g.THelper()
|
||||||
|
assertion.g.Fail(fmt.Sprintf("%s after %.3fs.\n%s", preamble, time.Since(timer).Seconds(), messageGenerator()), 3+assertion.offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
var contextDone <-chan struct{}
|
||||||
|
if assertion.ctx != nil {
|
||||||
|
contextDone = assertion.ctx.Done()
|
||||||
|
if v, ok := assertion.ctx.Value("GINKGO_SPEC_CONTEXT").(contextWithAttachProgressReporter); ok {
|
||||||
|
detach := v.AttachProgressReporter(messageGenerator)
|
||||||
|
defer detach()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if assertion.asyncType == AsyncAssertionTypeEventually {
|
if assertion.asyncType == AsyncAssertionTypeEventually {
|
||||||
@ -192,18 +418,35 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !mayChange {
|
if stopTrying != nil {
|
||||||
fail("No future change is possible. Bailing out early")
|
fail(stopTrying.Error() + " -")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(assertion.pollingInterval):
|
case <-assertion.afterPolling():
|
||||||
value, err = assertion.pollActual()
|
v, e, st := pollActual()
|
||||||
if err == nil {
|
if st != nil && st.wasViaPanic() {
|
||||||
mayChange = assertion.matcherMayChange(matcher, value)
|
// we were told to stop trying via panic - which means we dont' have reasonable new values
|
||||||
matches, err = matcher.Match(value)
|
// we should simply use the old values and exit now
|
||||||
|
fail(st.Error() + " -")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
lock.Lock()
|
||||||
|
value, err, stopTrying = v, e, st
|
||||||
|
lock.Unlock()
|
||||||
|
if err == nil {
|
||||||
|
if stopTrying == nil {
|
||||||
|
stopTrying = assertion.matcherSaysStopTrying(matcher, value)
|
||||||
|
}
|
||||||
|
matches, e = matcher.Match(value)
|
||||||
|
lock.Lock()
|
||||||
|
err = e
|
||||||
|
lock.Unlock()
|
||||||
|
}
|
||||||
|
case <-contextDone:
|
||||||
|
fail("Context was cancelled")
|
||||||
|
return false
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
fail("Timed out")
|
fail("Timed out")
|
||||||
return false
|
return false
|
||||||
@ -216,17 +459,32 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !mayChange {
|
if stopTrying != nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(assertion.pollingInterval):
|
case <-assertion.afterPolling():
|
||||||
value, err = assertion.pollActual()
|
v, e, st := pollActual()
|
||||||
if err == nil {
|
if st != nil && st.wasViaPanic() {
|
||||||
mayChange = assertion.matcherMayChange(matcher, value)
|
// we were told to stop trying via panic - which means we made it this far and should return successfully
|
||||||
matches, err = matcher.Match(value)
|
return true
|
||||||
}
|
}
|
||||||
|
lock.Lock()
|
||||||
|
value, err, stopTrying = v, e, st
|
||||||
|
lock.Unlock()
|
||||||
|
if err == nil {
|
||||||
|
if stopTrying == nil {
|
||||||
|
stopTrying = assertion.matcherSaysStopTrying(matcher, value)
|
||||||
|
}
|
||||||
|
matches, e = matcher.Match(value)
|
||||||
|
lock.Lock()
|
||||||
|
err = e
|
||||||
|
lock.Unlock()
|
||||||
|
}
|
||||||
|
case <-contextDone:
|
||||||
|
fail("Context was cancelled")
|
||||||
|
return false
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
37
vendor/github.com/onsi/gomega/internal/gomega.go
generated
vendored
37
vendor/github.com/onsi/gomega/internal/gomega.go
generated
vendored
@ -1,6 +1,7 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/onsi/gomega/types"
|
"github.com/onsi/gomega/types"
|
||||||
@ -55,9 +56,19 @@ func (g *Gomega) Eventually(actual interface{}, intervals ...interface{}) types.
|
|||||||
return g.EventuallyWithOffset(0, actual, intervals...)
|
return g.EventuallyWithOffset(0, actual, intervals...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gomega) EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) types.AsyncAssertion {
|
func (g *Gomega) EventuallyWithOffset(offset int, actual interface{}, args ...interface{}) types.AsyncAssertion {
|
||||||
timeoutInterval := g.DurationBundle.EventuallyTimeout
|
timeoutInterval := -time.Duration(1)
|
||||||
pollingInterval := g.DurationBundle.EventuallyPollingInterval
|
pollingInterval := -time.Duration(1)
|
||||||
|
intervals := []interface{}{}
|
||||||
|
var ctx context.Context
|
||||||
|
for _, arg := range args {
|
||||||
|
switch v := arg.(type) {
|
||||||
|
case context.Context:
|
||||||
|
ctx = v
|
||||||
|
default:
|
||||||
|
intervals = append(intervals, arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(intervals) > 0 {
|
if len(intervals) > 0 {
|
||||||
timeoutInterval = toDuration(intervals[0])
|
timeoutInterval = toDuration(intervals[0])
|
||||||
}
|
}
|
||||||
@ -65,16 +76,26 @@ func (g *Gomega) EventuallyWithOffset(offset int, actual interface{}, intervals
|
|||||||
pollingInterval = toDuration(intervals[1])
|
pollingInterval = toDuration(intervals[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewAsyncAssertion(AsyncAssertionTypeEventually, actual, g, timeoutInterval, pollingInterval, offset)
|
return NewAsyncAssertion(AsyncAssertionTypeEventually, actual, g, timeoutInterval, pollingInterval, ctx, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gomega) Consistently(actual interface{}, intervals ...interface{}) types.AsyncAssertion {
|
func (g *Gomega) Consistently(actual interface{}, intervals ...interface{}) types.AsyncAssertion {
|
||||||
return g.ConsistentlyWithOffset(0, actual, intervals...)
|
return g.ConsistentlyWithOffset(0, actual, intervals...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gomega) ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) types.AsyncAssertion {
|
func (g *Gomega) ConsistentlyWithOffset(offset int, actual interface{}, args ...interface{}) types.AsyncAssertion {
|
||||||
timeoutInterval := g.DurationBundle.ConsistentlyDuration
|
timeoutInterval := -time.Duration(1)
|
||||||
pollingInterval := g.DurationBundle.ConsistentlyPollingInterval
|
pollingInterval := -time.Duration(1)
|
||||||
|
intervals := []interface{}{}
|
||||||
|
var ctx context.Context
|
||||||
|
for _, arg := range args {
|
||||||
|
switch v := arg.(type) {
|
||||||
|
case context.Context:
|
||||||
|
ctx = v
|
||||||
|
default:
|
||||||
|
intervals = append(intervals, arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(intervals) > 0 {
|
if len(intervals) > 0 {
|
||||||
timeoutInterval = toDuration(intervals[0])
|
timeoutInterval = toDuration(intervals[0])
|
||||||
}
|
}
|
||||||
@ -82,7 +103,7 @@ func (g *Gomega) ConsistentlyWithOffset(offset int, actual interface{}, interval
|
|||||||
pollingInterval = toDuration(intervals[1])
|
pollingInterval = toDuration(intervals[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewAsyncAssertion(AsyncAssertionTypeConsistently, actual, g, timeoutInterval, pollingInterval, offset)
|
return NewAsyncAssertion(AsyncAssertionTypeConsistently, actual, g, timeoutInterval, pollingInterval, ctx, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gomega) SetDefaultEventuallyTimeout(t time.Duration) {
|
func (g *Gomega) SetDefaultEventuallyTimeout(t time.Duration) {
|
||||||
|
37
vendor/github.com/onsi/gomega/matchers.go
generated
vendored
37
vendor/github.com/onsi/gomega/matchers.go
generated
vendored
@ -62,6 +62,7 @@ func BeFalse() types.GomegaMatcher {
|
|||||||
|
|
||||||
// HaveOccurred succeeds if actual is a non-nil error
|
// HaveOccurred succeeds if actual is a non-nil error
|
||||||
// The typical Go error checking pattern looks like:
|
// The typical Go error checking pattern looks like:
|
||||||
|
//
|
||||||
// err := SomethingThatMightFail()
|
// err := SomethingThatMightFail()
|
||||||
// Expect(err).ShouldNot(HaveOccurred())
|
// Expect(err).ShouldNot(HaveOccurred())
|
||||||
func HaveOccurred() types.GomegaMatcher {
|
func HaveOccurred() types.GomegaMatcher {
|
||||||
@ -70,10 +71,12 @@ func HaveOccurred() types.GomegaMatcher {
|
|||||||
|
|
||||||
// Succeed passes if actual is a nil error
|
// Succeed passes if actual is a nil error
|
||||||
// Succeed is intended to be used with functions that return a single error value. Instead of
|
// Succeed is intended to be used with functions that return a single error value. Instead of
|
||||||
|
//
|
||||||
// err := SomethingThatMightFail()
|
// err := SomethingThatMightFail()
|
||||||
// Expect(err).ShouldNot(HaveOccurred())
|
// Expect(err).ShouldNot(HaveOccurred())
|
||||||
//
|
//
|
||||||
// You can write:
|
// You can write:
|
||||||
|
//
|
||||||
// Expect(SomethingThatMightFail()).Should(Succeed())
|
// Expect(SomethingThatMightFail()).Should(Succeed())
|
||||||
//
|
//
|
||||||
// It is a mistake to use Succeed with a function that has multiple return values. Gomega's Ω and Expect
|
// It is a mistake to use Succeed with a function that has multiple return values. Gomega's Ω and Expect
|
||||||
@ -86,6 +89,7 @@ func Succeed() types.GomegaMatcher {
|
|||||||
// MatchError succeeds if actual is a non-nil error that matches the passed in string/error.
|
// MatchError succeeds if actual is a non-nil error that matches the passed in string/error.
|
||||||
//
|
//
|
||||||
// These are valid use-cases:
|
// These are valid use-cases:
|
||||||
|
//
|
||||||
// Expect(err).Should(MatchError("an error")) //asserts that err.Error() == "an error"
|
// Expect(err).Should(MatchError("an error")) //asserts that err.Error() == "an error"
|
||||||
// Expect(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual)
|
// Expect(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual)
|
||||||
//
|
//
|
||||||
@ -123,14 +127,17 @@ func BeClosed() types.GomegaMatcher {
|
|||||||
// - If there is something on the channel `c` ready to be read, then Expect(c).Should(Receive()) will pass and Ω(c).ShouldNot(Receive()) will fail.
|
// - If there is something on the channel `c` ready to be read, then Expect(c).Should(Receive()) will pass and Ω(c).ShouldNot(Receive()) will fail.
|
||||||
//
|
//
|
||||||
// If you have a go-routine running in the background that will write to channel `c` you can:
|
// If you have a go-routine running in the background that will write to channel `c` you can:
|
||||||
|
//
|
||||||
// Eventually(c).Should(Receive())
|
// Eventually(c).Should(Receive())
|
||||||
//
|
//
|
||||||
// This will timeout if nothing gets sent to `c` (you can modify the timeout interval as you normally do with `Eventually`)
|
// This will timeout if nothing gets sent to `c` (you can modify the timeout interval as you normally do with `Eventually`)
|
||||||
//
|
//
|
||||||
// A similar use-case is to assert that no go-routine writes to a channel (for a period of time). You can do this with `Consistently`:
|
// A similar use-case is to assert that no go-routine writes to a channel (for a period of time). You can do this with `Consistently`:
|
||||||
|
//
|
||||||
// Consistently(c).ShouldNot(Receive())
|
// Consistently(c).ShouldNot(Receive())
|
||||||
//
|
//
|
||||||
// You can pass `Receive` a matcher. If you do so, it will match the received object against the matcher. For example:
|
// You can pass `Receive` a matcher. If you do so, it will match the received object against the matcher. For example:
|
||||||
|
//
|
||||||
// Expect(c).Should(Receive(Equal("foo")))
|
// Expect(c).Should(Receive(Equal("foo")))
|
||||||
//
|
//
|
||||||
// When given a matcher, `Receive` will always fail if there is nothing to be received on the channel.
|
// When given a matcher, `Receive` will always fail if there is nothing to be received on the channel.
|
||||||
@ -142,6 +149,7 @@ func BeClosed() types.GomegaMatcher {
|
|||||||
// will repeatedly attempt to pull values out of `c` until a value matching "bar" is received.
|
// will repeatedly attempt to pull values out of `c` until a value matching "bar" is received.
|
||||||
//
|
//
|
||||||
// Finally, if you want to have a reference to the value *sent* to the channel you can pass the `Receive` matcher a pointer to a variable of the appropriate type:
|
// Finally, if you want to have a reference to the value *sent* to the channel you can pass the `Receive` matcher a pointer to a variable of the appropriate type:
|
||||||
|
//
|
||||||
// var myThing thing
|
// var myThing thing
|
||||||
// Eventually(thingChan).Should(Receive(&myThing))
|
// Eventually(thingChan).Should(Receive(&myThing))
|
||||||
// Expect(myThing.Sprocket).Should(Equal("foo"))
|
// Expect(myThing.Sprocket).Should(Equal("foo"))
|
||||||
@ -269,6 +277,7 @@ func BeZero() types.GomegaMatcher {
|
|||||||
// ContainElement succeeds if actual contains the passed in element. By default
|
// ContainElement succeeds if actual contains the passed in element. By default
|
||||||
// ContainElement() uses Equal() to perform the match, however a matcher can be
|
// ContainElement() uses Equal() to perform the match, however a matcher can be
|
||||||
// passed in instead:
|
// passed in instead:
|
||||||
|
//
|
||||||
// Expect([]string{"Foo", "FooBar"}).Should(ContainElement(ContainSubstring("Bar")))
|
// Expect([]string{"Foo", "FooBar"}).Should(ContainElement(ContainSubstring("Bar")))
|
||||||
//
|
//
|
||||||
// Actual must be an array, slice or map. For maps, ContainElement searches
|
// Actual must be an array, slice or map. For maps, ContainElement searches
|
||||||
@ -293,9 +302,12 @@ func ContainElement(element interface{}, result ...interface{}) types.GomegaMatc
|
|||||||
// BeElementOf() always uses Equal() to perform the match.
|
// BeElementOf() always uses Equal() to perform the match.
|
||||||
// When the passed in elements are comprised of a single element that is either an Array or Slice, BeElementOf() behaves
|
// When the passed in elements are comprised of a single element that is either an Array or Slice, BeElementOf() behaves
|
||||||
// as the reverse of ContainElement() that operates with Equal() to perform the match.
|
// as the reverse of ContainElement() that operates with Equal() to perform the match.
|
||||||
|
//
|
||||||
// Expect(2).Should(BeElementOf([]int{1, 2}))
|
// Expect(2).Should(BeElementOf([]int{1, 2}))
|
||||||
// Expect(2).Should(BeElementOf([2]int{1, 2}))
|
// Expect(2).Should(BeElementOf([2]int{1, 2}))
|
||||||
|
//
|
||||||
// Otherwise, BeElementOf() provides a syntactic sugar for Or(Equal(_), Equal(_), ...):
|
// Otherwise, BeElementOf() provides a syntactic sugar for Or(Equal(_), Equal(_), ...):
|
||||||
|
//
|
||||||
// Expect(2).Should(BeElementOf(1, 2))
|
// Expect(2).Should(BeElementOf(1, 2))
|
||||||
//
|
//
|
||||||
// Actual must be typed.
|
// Actual must be typed.
|
||||||
@ -305,6 +317,16 @@ func BeElementOf(elements ...interface{}) types.GomegaMatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BeKeyOf succeeds if actual is contained in the keys of the passed in map.
|
||||||
|
// BeKeyOf() always uses Equal() to perform the match between actual and the map keys.
|
||||||
|
//
|
||||||
|
// Expect("foo").Should(BeKeyOf(map[string]bool{"foo": true, "bar": false}))
|
||||||
|
func BeKeyOf(element interface{}) types.GomegaMatcher {
|
||||||
|
return &matchers.BeKeyOfMatcher{
|
||||||
|
Map: element,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ConsistOf succeeds if actual contains precisely the elements passed into the matcher. The ordering of the elements does not matter.
|
// ConsistOf succeeds if actual contains precisely the elements passed into the matcher. The ordering of the elements does not matter.
|
||||||
// By default ConsistOf() uses Equal() to match the elements, however custom matchers can be passed in instead. Here are some examples:
|
// By default ConsistOf() uses Equal() to match the elements, however custom matchers can be passed in instead. Here are some examples:
|
||||||
//
|
//
|
||||||
@ -344,6 +366,7 @@ func ContainElements(elements ...interface{}) types.GomegaMatcher {
|
|||||||
// Please note that if actual is empty, HaveEach always will succeed.
|
// Please note that if actual is empty, HaveEach always will succeed.
|
||||||
// By default HaveEach() uses Equal() to perform the match, however a
|
// By default HaveEach() uses Equal() to perform the match, however a
|
||||||
// matcher can be passed in instead:
|
// matcher can be passed in instead:
|
||||||
|
//
|
||||||
// Expect([]string{"Foo", "FooBar"}).Should(HaveEach(ContainSubstring("Foo")))
|
// Expect([]string{"Foo", "FooBar"}).Should(HaveEach(ContainSubstring("Foo")))
|
||||||
//
|
//
|
||||||
// Actual must be an array, slice or map.
|
// Actual must be an array, slice or map.
|
||||||
@ -357,6 +380,7 @@ func HaveEach(element interface{}) types.GomegaMatcher {
|
|||||||
// HaveKey succeeds if actual is a map with the passed in key.
|
// HaveKey succeeds if actual is a map with the passed in key.
|
||||||
// By default HaveKey uses Equal() to perform the match, however a
|
// By default HaveKey uses Equal() to perform the match, however a
|
||||||
// matcher can be passed in instead:
|
// matcher can be passed in instead:
|
||||||
|
//
|
||||||
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKey(MatchRegexp(`.+Foo$`)))
|
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKey(MatchRegexp(`.+Foo$`)))
|
||||||
func HaveKey(key interface{}) types.GomegaMatcher {
|
func HaveKey(key interface{}) types.GomegaMatcher {
|
||||||
return &matchers.HaveKeyMatcher{
|
return &matchers.HaveKeyMatcher{
|
||||||
@ -367,6 +391,7 @@ func HaveKey(key interface{}) types.GomegaMatcher {
|
|||||||
// HaveKeyWithValue succeeds if actual is a map with the passed in key and value.
|
// HaveKeyWithValue succeeds if actual is a map with the passed in key and value.
|
||||||
// By default HaveKeyWithValue uses Equal() to perform the match, however a
|
// By default HaveKeyWithValue uses Equal() to perform the match, however a
|
||||||
// matcher can be passed in instead:
|
// matcher can be passed in instead:
|
||||||
|
//
|
||||||
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKeyWithValue("Foo", "Bar"))
|
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKeyWithValue("Foo", "Bar"))
|
||||||
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKeyWithValue(MatchRegexp(`.+Foo$`), "Bar"))
|
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKeyWithValue(MatchRegexp(`.+Foo$`), "Bar"))
|
||||||
func HaveKeyWithValue(key interface{}, value interface{}) types.GomegaMatcher {
|
func HaveKeyWithValue(key interface{}, value interface{}) types.GomegaMatcher {
|
||||||
@ -442,6 +467,7 @@ func HaveValue(matcher types.GomegaMatcher) types.GomegaMatcher {
|
|||||||
// number is irrelevant (float32, float64, uint8, etc...).
|
// number is irrelevant (float32, float64, uint8, etc...).
|
||||||
//
|
//
|
||||||
// There are six, self-explanatory, supported comparators:
|
// There are six, self-explanatory, supported comparators:
|
||||||
|
//
|
||||||
// Expect(1.0).Should(BeNumerically("==", 1))
|
// Expect(1.0).Should(BeNumerically("==", 1))
|
||||||
// Expect(1.0).Should(BeNumerically("~", 0.999, 0.01))
|
// Expect(1.0).Should(BeNumerically("~", 0.999, 0.01))
|
||||||
// Expect(1.0).Should(BeNumerically(">", 0.9))
|
// Expect(1.0).Should(BeNumerically(">", 0.9))
|
||||||
@ -457,6 +483,7 @@ func BeNumerically(comparator string, compareTo ...interface{}) types.GomegaMatc
|
|||||||
|
|
||||||
// BeTemporally compares time.Time's like BeNumerically
|
// BeTemporally compares time.Time's like BeNumerically
|
||||||
// Actual and expected must be time.Time. The comparators are the same as for BeNumerically
|
// Actual and expected must be time.Time. The comparators are the same as for BeNumerically
|
||||||
|
//
|
||||||
// Expect(time.Now()).Should(BeTemporally(">", time.Time{}))
|
// Expect(time.Now()).Should(BeTemporally(">", time.Time{}))
|
||||||
// Expect(time.Now()).Should(BeTemporally("~", time.Now(), time.Second))
|
// Expect(time.Now()).Should(BeTemporally("~", time.Now(), time.Second))
|
||||||
func BeTemporally(comparator string, compareTo time.Time, threshold ...time.Duration) types.GomegaMatcher {
|
func BeTemporally(comparator string, compareTo time.Time, threshold ...time.Duration) types.GomegaMatcher {
|
||||||
@ -469,6 +496,7 @@ func BeTemporally(comparator string, compareTo time.Time, threshold ...time.Dura
|
|||||||
|
|
||||||
// BeAssignableToTypeOf succeeds if actual is assignable to the type of expected.
|
// BeAssignableToTypeOf succeeds if actual is assignable to the type of expected.
|
||||||
// It will return an error when one of the values is nil.
|
// It will return an error when one of the values is nil.
|
||||||
|
//
|
||||||
// Expect(0).Should(BeAssignableToTypeOf(0)) // Same values
|
// Expect(0).Should(BeAssignableToTypeOf(0)) // Same values
|
||||||
// Expect(5).Should(BeAssignableToTypeOf(-1)) // different values same type
|
// Expect(5).Should(BeAssignableToTypeOf(-1)) // different values same type
|
||||||
// Expect("foo").Should(BeAssignableToTypeOf("bar")) // different values same type
|
// Expect("foo").Should(BeAssignableToTypeOf("bar")) // different values same type
|
||||||
@ -490,6 +518,7 @@ func Panic() types.GomegaMatcher {
|
|||||||
//
|
//
|
||||||
// By default PanicWith uses Equal() to perform the match, however a
|
// By default PanicWith uses Equal() to perform the match, however a
|
||||||
// matcher can be passed in instead:
|
// matcher can be passed in instead:
|
||||||
|
//
|
||||||
// Expect(fn).Should(PanicWith(MatchRegexp(`.+Foo$`)))
|
// Expect(fn).Should(PanicWith(MatchRegexp(`.+Foo$`)))
|
||||||
func PanicWith(expected interface{}) types.GomegaMatcher {
|
func PanicWith(expected interface{}) types.GomegaMatcher {
|
||||||
return &matchers.PanicMatcher{Expected: expected}
|
return &matchers.PanicMatcher{Expected: expected}
|
||||||
@ -516,6 +545,7 @@ func BeADirectory() types.GomegaMatcher {
|
|||||||
// HaveHTTPStatus succeeds if the Status or StatusCode field of an HTTP response matches.
|
// HaveHTTPStatus succeeds if the Status or StatusCode field of an HTTP response matches.
|
||||||
// Actual must be either a *http.Response or *httptest.ResponseRecorder.
|
// Actual must be either a *http.Response or *httptest.ResponseRecorder.
|
||||||
// Expected must be either an int or a string.
|
// Expected must be either an int or a string.
|
||||||
|
//
|
||||||
// Expect(resp).Should(HaveHTTPStatus(http.StatusOK)) // asserts that resp.StatusCode == 200
|
// Expect(resp).Should(HaveHTTPStatus(http.StatusOK)) // asserts that resp.StatusCode == 200
|
||||||
// Expect(resp).Should(HaveHTTPStatus("404 Not Found")) // asserts that resp.Status == "404 Not Found"
|
// Expect(resp).Should(HaveHTTPStatus("404 Not Found")) // asserts that resp.Status == "404 Not Found"
|
||||||
// Expect(resp).Should(HaveHTTPStatus(http.StatusOK, http.StatusNoContent)) // asserts that resp.StatusCode == 200 || resp.StatusCode == 204
|
// Expect(resp).Should(HaveHTTPStatus(http.StatusOK, http.StatusNoContent)) // asserts that resp.StatusCode == 200 || resp.StatusCode == 204
|
||||||
@ -543,6 +573,7 @@ func HaveHTTPBody(expected interface{}) types.GomegaMatcher {
|
|||||||
|
|
||||||
// And succeeds only if all of the given matchers succeed.
|
// And succeeds only if all of the given matchers succeed.
|
||||||
// The matchers are tried in order, and will fail-fast if one doesn't succeed.
|
// The matchers are tried in order, and will fail-fast if one doesn't succeed.
|
||||||
|
//
|
||||||
// Expect("hi").To(And(HaveLen(2), Equal("hi"))
|
// Expect("hi").To(And(HaveLen(2), Equal("hi"))
|
||||||
//
|
//
|
||||||
// And(), Or(), Not() and WithTransform() allow matchers to be composed into complex expressions.
|
// And(), Or(), Not() and WithTransform() allow matchers to be composed into complex expressions.
|
||||||
@ -551,6 +582,7 @@ func And(ms ...types.GomegaMatcher) types.GomegaMatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SatisfyAll is an alias for And().
|
// SatisfyAll is an alias for And().
|
||||||
|
//
|
||||||
// Expect("hi").Should(SatisfyAll(HaveLen(2), Equal("hi")))
|
// Expect("hi").Should(SatisfyAll(HaveLen(2), Equal("hi")))
|
||||||
func SatisfyAll(matchers ...types.GomegaMatcher) types.GomegaMatcher {
|
func SatisfyAll(matchers ...types.GomegaMatcher) types.GomegaMatcher {
|
||||||
return And(matchers...)
|
return And(matchers...)
|
||||||
@ -558,6 +590,7 @@ func SatisfyAll(matchers ...types.GomegaMatcher) types.GomegaMatcher {
|
|||||||
|
|
||||||
// Or succeeds if any of the given matchers succeed.
|
// Or succeeds if any of the given matchers succeed.
|
||||||
// The matchers are tried in order and will return immediately upon the first successful match.
|
// The matchers are tried in order and will return immediately upon the first successful match.
|
||||||
|
//
|
||||||
// Expect("hi").To(Or(HaveLen(3), HaveLen(2))
|
// Expect("hi").To(Or(HaveLen(3), HaveLen(2))
|
||||||
//
|
//
|
||||||
// And(), Or(), Not() and WithTransform() allow matchers to be composed into complex expressions.
|
// And(), Or(), Not() and WithTransform() allow matchers to be composed into complex expressions.
|
||||||
@ -566,12 +599,14 @@ func Or(ms ...types.GomegaMatcher) types.GomegaMatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SatisfyAny is an alias for Or().
|
// SatisfyAny is an alias for Or().
|
||||||
|
//
|
||||||
// Expect("hi").SatisfyAny(Or(HaveLen(3), HaveLen(2))
|
// Expect("hi").SatisfyAny(Or(HaveLen(3), HaveLen(2))
|
||||||
func SatisfyAny(matchers ...types.GomegaMatcher) types.GomegaMatcher {
|
func SatisfyAny(matchers ...types.GomegaMatcher) types.GomegaMatcher {
|
||||||
return Or(matchers...)
|
return Or(matchers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not negates the given matcher; it succeeds if the given matcher fails.
|
// Not negates the given matcher; it succeeds if the given matcher fails.
|
||||||
|
//
|
||||||
// Expect(1).To(Not(Equal(2))
|
// Expect(1).To(Not(Equal(2))
|
||||||
//
|
//
|
||||||
// And(), Or(), Not() and WithTransform() allow matchers to be composed into complex expressions.
|
// And(), Or(), Not() and WithTransform() allow matchers to be composed into complex expressions.
|
||||||
@ -583,6 +618,7 @@ func Not(matcher types.GomegaMatcher) types.GomegaMatcher {
|
|||||||
// The given transform must be either a function of one parameter that returns one value or a
|
// The given transform must be either a function of one parameter that returns one value or a
|
||||||
// function of one parameter that returns two values, where the second value must be of the
|
// function of one parameter that returns two values, where the second value must be of the
|
||||||
// error type.
|
// error type.
|
||||||
|
//
|
||||||
// var plus1 = func(i int) int { return i + 1 }
|
// var plus1 = func(i int) int { return i + 1 }
|
||||||
// Expect(1).To(WithTransform(plus1, Equal(2))
|
// Expect(1).To(WithTransform(plus1, Equal(2))
|
||||||
//
|
//
|
||||||
@ -596,6 +632,7 @@ func WithTransform(transform interface{}, matcher types.GomegaMatcher) types.Gom
|
|||||||
|
|
||||||
// Satisfy matches the actual value against the `predicate` function.
|
// Satisfy matches the actual value against the `predicate` function.
|
||||||
// The given predicate must be a function of one paramter that returns bool.
|
// The given predicate must be a function of one paramter that returns bool.
|
||||||
|
//
|
||||||
// var isEven = func(i int) bool { return i%2 == 0 }
|
// var isEven = func(i int) bool { return i%2 == 0 }
|
||||||
// Expect(2).To(Satisfy(isEven))
|
// Expect(2).To(Satisfy(isEven))
|
||||||
func Satisfy(predicate interface{}) types.GomegaMatcher {
|
func Satisfy(predicate interface{}) types.GomegaMatcher {
|
||||||
|
45
vendor/github.com/onsi/gomega/matchers/be_key_of_matcher.go
generated
vendored
Normal file
45
vendor/github.com/onsi/gomega/matchers/be_key_of_matcher.go
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package matchers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/onsi/gomega/format"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BeKeyOfMatcher struct {
|
||||||
|
Map interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (matcher *BeKeyOfMatcher) Match(actual interface{}) (success bool, err error) {
|
||||||
|
if !isMap(matcher.Map) {
|
||||||
|
return false, fmt.Errorf("BeKeyOf matcher needs expected to be a map type")
|
||||||
|
}
|
||||||
|
|
||||||
|
if reflect.TypeOf(actual) == nil {
|
||||||
|
return false, fmt.Errorf("BeKeyOf matcher expects actual to be typed")
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastError error
|
||||||
|
for _, key := range reflect.ValueOf(matcher.Map).MapKeys() {
|
||||||
|
matcher := &EqualMatcher{Expected: key.Interface()}
|
||||||
|
success, err := matcher.Match(actual)
|
||||||
|
if err != nil {
|
||||||
|
lastError = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if success {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, lastError
|
||||||
|
}
|
||||||
|
|
||||||
|
func (matcher *BeKeyOfMatcher) FailureMessage(actual interface{}) (message string) {
|
||||||
|
return format.Message(actual, "to be a key of", presentable(valuesOf(matcher.Map)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (matcher *BeKeyOfMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||||
|
return format.Message(actual, "not to be a key of", presentable(valuesOf(matcher.Map)))
|
||||||
|
}
|
5
vendor/github.com/onsi/gomega/types/types.go
generated
vendored
5
vendor/github.com/onsi/gomega/types/types.go
generated
vendored
@ -1,6 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,6 +71,10 @@ type AsyncAssertion interface {
|
|||||||
WithOffset(offset int) AsyncAssertion
|
WithOffset(offset int) AsyncAssertion
|
||||||
WithTimeout(interval time.Duration) AsyncAssertion
|
WithTimeout(interval time.Duration) AsyncAssertion
|
||||||
WithPolling(interval time.Duration) AsyncAssertion
|
WithPolling(interval time.Duration) AsyncAssertion
|
||||||
|
Within(timeout time.Duration) AsyncAssertion
|
||||||
|
ProbeEvery(interval time.Duration) AsyncAssertion
|
||||||
|
WithContext(ctx context.Context) AsyncAssertion
|
||||||
|
WithArguments(argsToForward ...interface{}) AsyncAssertion
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assertions are returned by Ω and Expect and enable assertions against Gomega matchers
|
// Assertions are returned by Ω and Expect and enable assertions against Gomega matchers
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -592,7 +592,7 @@ github.com/onsi/ginkgo/reporters/stenographer
|
|||||||
github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable
|
github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable
|
||||||
github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty
|
github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty
|
||||||
github.com/onsi/ginkgo/types
|
github.com/onsi/ginkgo/types
|
||||||
# github.com/onsi/gomega v1.20.2
|
# github.com/onsi/gomega v1.22.1
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
github.com/onsi/gomega
|
github.com/onsi/gomega
|
||||||
github.com/onsi/gomega/format
|
github.com/onsi/gomega/format
|
||||||
|
Reference in New Issue
Block a user