rebase: Bump github.com/onsi/gomega from 1.27.4 to 1.27.6

Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.4 to 1.27.6.
- [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.27.4...v1.27.6)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2023-04-18 08:07:36 +00:00
committed by mergify[bot]
parent 7b44054a7e
commit 86a7acc2fb
7 changed files with 47 additions and 21 deletions

View File

@ -1,3 +1,17 @@
## 1.27.6
### Fixes
- Allow collections matchers to work correctly when expected has nil elements [60e7cf3]
### Maintenance
- updates MatchError godoc comment to also accept a Gomega matcher (#654) [67b869d]
## 1.27.5
### Maintenance
- Bump github.com/onsi/ginkgo/v2 from 2.9.1 to 2.9.2 (#653) [a215021]
- Bump github.com/go-task/slim-sprig (#652) [a26fed8]
## 1.27.4
### Fixes

View File

@ -22,7 +22,7 @@ import (
"github.com/onsi/gomega/types"
)
const GOMEGA_VERSION = "1.27.4"
const GOMEGA_VERSION = "1.27.6"
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().

View File

@ -87,14 +87,17 @@ func Succeed() types.GomegaMatcher {
return &matchers.SucceedMatcher{}
}
// 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, or matcher.
//
// These are valid use-cases:
//
// 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("an error")) //asserts that err.Error() == "an error"
// Expect(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual)
// Expect(err).Should(MatchError(ContainsSubstring("sprocket not found"))) // asserts that edrr.Error() contains substring "sprocket not found"
//
// It is an error for err to be nil or an object that does not implement the Error interface
// It is an error for err to be nil or an object that does not implement the
// Error interface
func MatchError(expected interface{}) types.GomegaMatcher {
return &matchers.MatchErrorMatcher{
Expected: expected,

View File

@ -48,11 +48,13 @@ func neighbours(value, matcher interface{}) (bool, error) {
func equalMatchersToElements(matchers []interface{}) (elements []interface{}) {
for _, matcher := range matchers {
equalMatcher, ok := matcher.(*EqualMatcher)
if ok {
matcher = equalMatcher.Expected
if equalMatcher, ok := matcher.(*EqualMatcher); ok {
elements = append(elements, equalMatcher.Expected)
} else if _, ok := matcher.(*BeNilMatcher); ok {
elements = append(elements, nil)
} else {
elements = append(elements, matcher)
}
elements = append(elements, matcher)
}
return
}
@ -72,11 +74,13 @@ func flatten(elems []interface{}) []interface{} {
func matchers(expectedElems []interface{}) (matchers []interface{}) {
for _, e := range flatten(expectedElems) {
matcher, isMatcher := e.(omegaMatcher)
if !isMatcher {
matcher = &EqualMatcher{Expected: e}
if e == nil {
matchers = append(matchers, &BeNilMatcher{})
} else if matcher, isMatcher := e.(omegaMatcher); isMatcher {
matchers = append(matchers, matcher)
} else {
matchers = append(matchers, &EqualMatcher{Expected: e})
}
matchers = append(matchers, matcher)
}
return
}
@ -89,9 +93,14 @@ func presentable(elems []interface{}) interface{} {
}
sv := reflect.ValueOf(elems)
tt := sv.Index(0).Elem().Type()
firstEl := sv.Index(0)
if firstEl.IsNil() {
return elems
}
tt := firstEl.Elem().Type()
for i := 1; i < sv.Len(); i++ {
if sv.Index(i).Elem().Type() != tt {
el := sv.Index(i)
if el.IsNil() || (sv.Index(i).Elem().Type() != tt) {
return elems
}
}