summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/gomega/internal/asyncassertion
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2021-08-06 12:21:04 +0000
committerGitHub <noreply@github.com>2021-08-06 12:21:04 +0000
commit79e4baf4ca5d61a4e9c997f9ec025e46e45e5d9d (patch)
tree25665b6dd2710671a866f3546fde36caa0b09678 /vendor/github.com/onsi/gomega/internal/asyncassertion
parenta82ceafb73356d8e3ed825be2f0ad0a29b7c3761 (diff)
downloadpodman-79e4baf4ca5d61a4e9c997f9ec025e46e45e5d9d.tar.gz
podman-79e4baf4ca5d61a4e9c997f9ec025e46e45e5d9d.tar.bz2
podman-79e4baf4ca5d61a4e9c997f9ec025e46e45e5d9d.zip
Bump github.com/onsi/gomega from 1.14.0 to 1.15.0
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.14.0 to 1.15.0. - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.14.0...v1.15.0) --- updated-dependencies: - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/onsi/gomega/internal/asyncassertion')
-rw-r--r--vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go235
1 files changed, 0 insertions, 235 deletions
diff --git a/vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go b/vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go
deleted file mode 100644
index 6aa02bc5d..000000000
--- a/vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go
+++ /dev/null
@@ -1,235 +0,0 @@
-// untested sections: 2
-
-package asyncassertion
-
-import (
- "errors"
- "fmt"
- "reflect"
- "runtime"
- "time"
-
- "github.com/onsi/gomega/internal/oraclematcher"
- "github.com/onsi/gomega/types"
-)
-
-type AsyncAssertionType uint
-
-const (
- AsyncAssertionTypeEventually AsyncAssertionType = iota
- AsyncAssertionTypeConsistently
-)
-
-type AsyncAssertion struct {
- asyncType AsyncAssertionType
- actualInput interface{}
- timeoutInterval time.Duration
- pollingInterval time.Duration
- failWrapper *types.GomegaFailWrapper
- offset int
-}
-
-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{
- asyncType: asyncType,
- actualInput: actualInput,
- failWrapper: failWrapper,
- timeoutInterval: timeoutInterval,
- pollingInterval: pollingInterval,
- offset: offset,
- }
-}
-
-func (assertion *AsyncAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
- return assertion.match(matcher, true, optionalDescription...)
-}
-
-func (assertion *AsyncAssertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
- assertion.failWrapper.TWithHelper.Helper()
- return assertion.match(matcher, false, optionalDescription...)
-}
-
-func (assertion *AsyncAssertion) buildDescription(optionalDescription ...interface{}) string {
- switch len(optionalDescription) {
- case 0:
- return ""
- case 1:
- if describe, ok := optionalDescription[0].(func() string); ok {
- return describe() + "\n"
- }
- }
- 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
- }
- 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)
- }
- }
-
- 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
- }
-
- return nil, nil
-}
-
-func (assertion *AsyncAssertion) matcherMayChange(matcher types.GomegaMatcher, value interface{}) bool {
- if assertion.actualInputIsAFunction() {
- return true
- }
-
- return oraclematcher.MatchMayChangeInTheFuture(matcher, value)
-}
-
-func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
- timer := time.Now()
- timeout := time.After(assertion.timeoutInterval)
-
- var matches bool
- var err error
- mayChange := true
- value, err := assertion.pollActual()
- if err == nil {
- mayChange = assertion.matcherMayChange(matcher, value)
- matches, err = matcher.Match(value)
- }
-
- assertion.failWrapper.TWithHelper.Helper()
-
- fail := func(preamble string) {
- errMsg := ""
- message := ""
- if err != nil {
- errMsg = "Error: " + err.Error()
- } else {
- if desiredMatch {
- message = matcher.FailureMessage(value)
- } else {
- message = matcher.NegatedFailureMessage(value)
- }
- }
- assertion.failWrapper.TWithHelper.Helper()
- 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)
- }
-
- if assertion.asyncType == AsyncAssertionTypeEventually {
- for {
- if err == nil && matches == desiredMatch {
- return true
- }
-
- if !mayChange {
- fail("No future change is possible. Bailing out early")
- return false
- }
-
- select {
- case <-time.After(assertion.pollingInterval):
- value, err = assertion.pollActual()
- if err == nil {
- mayChange = assertion.matcherMayChange(matcher, value)
- matches, err = matcher.Match(value)
- }
- case <-timeout:
- fail("Timed out")
- return false
- }
- }
- } else if assertion.asyncType == AsyncAssertionTypeConsistently {
- for {
- if !(err == nil && matches == desiredMatch) {
- fail("Failed")
- return false
- }
-
- if !mayChange {
- return true
- }
-
- select {
- case <-time.After(assertion.pollingInterval):
- value, err = assertion.pollActual()
- if err == nil {
- mayChange = assertion.matcherMayChange(matcher, value)
- matches, err = matcher.Match(value)
- }
- case <-timeout:
- return true
- }
- }
- }
-
- 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, ""
-}