mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-23 07:58:04 +00:00
Upgrade the operator to use Operator SDK v1.33.0 (#182)
* Move controller package inside internal directory Based on the go/v4 project structure, the following changed: - Pakcage `controllers` is now named `controller` - Package `controller` now lives inside new `internal` directory * Move main.go in cmd directory Based on the new go/v4 project structure, `main.go` now lives in the `cmd` directory. * Change package import in main.go * Update go mod dependencies Update the dependencies based on the versions obtained by creating a new operator project using `kubebuilder init --domain onepassword.com --plugins=go/v4`. This is based on the migration steps provided to go from go/v3 to go/v4 (https://book.kubebuilder.io/migration/migration_guide_gov3_to_gov4) * Update vendor * Adjust code for breaking changes from pkg update sigs.k8s.io/controller-runtime package had breaking changes from v0.14.5 to v0.16.3. This commit brings the changes needed to achieve the same things using the new functionality avaialble. * Adjust paths to connect yaml files Since `main.go` is now in `cmd` directory, the paths to the files for deploying Connect have to be adjusted based on the new location `main.go` is executed from. * Update files based on new structure and scaffolding These changes are made based on the new project structure and scaffolding obtained when using the new go/v4 project structure. These were done based on the migration steps mentioned when migrating to go/v4 (https://book.kubebuilder.io/migration/migration_guide_gov3_to_gov4). * Update config files These updates are made based on the Kustomize v4 syntax. This is part of the upgrate to go/v4 (https://book.kubebuilder.io/migration/migration_guide_gov3_to_gov4) * Update dependencies and GO version * Update vendor * Update Kubernetes tools versions * Update operator version in Makefile Now the version in the Makefile matches the version of the operator * Update Operator SDK version in version.go * Adjust generated deepcopy It seems that the +build tag is no longer needed based on the latest generated scaffolding, therefore it's removed. * Update copyright year * Bring back missing changes from migration Some customization in Makefile was lost during the migration process. Specifically, the namespace customization for `make deploy` command. Also, we push changes to kustomization.yaml for making the deploy process smoother. * Add RBAC perms for coordination.k8s.io It seems that with the latest changes to Kubernetes and Kustomize, we need to add additional RBAC to the service account used so that it can properly access the `leases` resource. * Optimize Dockerfile Dockerfile had a step for caching dependencies (go mod download). However, this is already done by the vendor directory, which we include. Therefore, this step can be removed to make the image build time faster.
This commit is contained in:
2
vendor/github.com/onsi/gomega/.gitignore
generated
vendored
2
vendor/github.com/onsi/gomega/.gitignore
generated
vendored
@@ -3,5 +3,5 @@
|
||||
.
|
||||
.idea
|
||||
gomega.iml
|
||||
TODO.md
|
||||
TODO
|
||||
.vscode
|
89
vendor/github.com/onsi/gomega/CHANGELOG.md
generated
vendored
89
vendor/github.com/onsi/gomega/CHANGELOG.md
generated
vendored
@@ -1,3 +1,92 @@
|
||||
## 1.30.0
|
||||
|
||||
### Features
|
||||
- BeTrueBecause and BeFalseBecause allow for better failure messages [4da4c7f]
|
||||
|
||||
### Maintenance
|
||||
- Bump actions/checkout from 3 to 4 (#694) [6ca6e97]
|
||||
- doc: fix type on gleak go doc [f1b8343]
|
||||
|
||||
## 1.29.0
|
||||
|
||||
### Features
|
||||
- MatchError can now take an optional func(error) bool + description [2b39142]
|
||||
|
||||
## 1.28.1
|
||||
|
||||
### Maintenance
|
||||
- Bump github.com/onsi/ginkgo/v2 from 2.12.0 to 2.13.0 [635d196]
|
||||
- Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 [14f8859]
|
||||
- Bump golang.org/x/net from 0.14.0 to 0.17.0 [d8a6508]
|
||||
- #703 doc(matchers): HaveEach() doc comment updated [2705bdb]
|
||||
- Minor typos (#699) [375648c]
|
||||
|
||||
## 1.28.0
|
||||
|
||||
### Features
|
||||
- Add VerifyHost handler to ghttp (#698) [0b03b36]
|
||||
|
||||
### Fixes
|
||||
- Read Body for Newer Responses in HaveHTTPBodyMatcher (#686) [18d6673]
|
||||
|
||||
### Maintenance
|
||||
- Bump github.com/onsi/ginkgo/v2 from 2.11.0 to 2.12.0 (#693) [55a33f3]
|
||||
- Typo in matchers.go (#691) [de68e8f]
|
||||
- Bump commonmarker from 0.23.9 to 0.23.10 in /docs (#690) [ab17f5e]
|
||||
- chore: update test matrix for Go 1.21 (#689) [5069017]
|
||||
- Bump golang.org/x/net from 0.12.0 to 0.14.0 (#688) [babe25f]
|
||||
|
||||
## 1.27.10
|
||||
|
||||
### Fixes
|
||||
- fix: go 1.21 adding goroutine ID to creator+location (#685) [bdc7803]
|
||||
|
||||
## 1.27.9
|
||||
|
||||
### Fixes
|
||||
- Prevent nil-dereference in format.Object for boxed nil error (#681) [3b31fc3]
|
||||
|
||||
### Maintenance
|
||||
- Bump golang.org/x/net from 0.11.0 to 0.12.0 (#679) [360849b]
|
||||
- chore: use String() instead of fmt.Sprintf (#678) [86f3659]
|
||||
- Bump golang.org/x/net from 0.10.0 to 0.11.0 (#674) [642ead0]
|
||||
- chore: unnecessary use of fmt.Sprintf (#677) [ceb9ca6]
|
||||
- Bump github.com/onsi/ginkgo/v2 from 2.10.0 to 2.11.0 (#675) [a2087d8]
|
||||
- docs: fix ContainSubstring references (#673) [fc9a89f]
|
||||
- Bump github.com/onsi/ginkgo/v2 from 2.9.7 to 2.10.0 (#671) [9076019]
|
||||
|
||||
## 1.27.8
|
||||
|
||||
### Fixes
|
||||
- HaveExactElement should not call FailureMessage if a submatcher returned an error [096f392]
|
||||
|
||||
### Maintenance
|
||||
- Bump github.com/onsi/ginkgo/v2 from 2.9.5 to 2.9.7 (#669) [8884bee]
|
||||
|
||||
## 1.27.7
|
||||
|
||||
### Fixes
|
||||
- fix: gcustom.MakeMatcher accepts nil as actual value (#666) [57054d5]
|
||||
|
||||
### Maintenance
|
||||
- update gitignore [05c1bc6]
|
||||
- Bump github.com/onsi/ginkgo/v2 from 2.9.4 to 2.9.5 (#663) [7cadcf6]
|
||||
- Bump golang.org/x/net from 0.9.0 to 0.10.0 (#662) [b524839]
|
||||
- Bump github.com/onsi/ginkgo/v2 from 2.9.2 to 2.9.4 (#661) [5f44694]
|
||||
- Bump commonmarker from 0.23.8 to 0.23.9 in /docs (#657) [05dc99a]
|
||||
- Bump nokogiri from 1.14.1 to 1.14.3 in /docs (#658) [3a033d1]
|
||||
- Replace deprecated NewGomegaWithT with NewWithT (#659) [a19238f]
|
||||
- Bump golang.org/x/net from 0.8.0 to 0.9.0 (#656) [29ed041]
|
||||
- Bump actions/setup-go from 3 to 4 (#651) [11b2080]
|
||||
|
||||
## 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
|
||||
|
4
vendor/github.com/onsi/gomega/format/format.go
generated
vendored
4
vendor/github.com/onsi/gomega/format/format.go
generated
vendored
@@ -259,7 +259,7 @@ func Object(object interface{}, indentation uint) string {
|
||||
indent := strings.Repeat(Indent, int(indentation))
|
||||
value := reflect.ValueOf(object)
|
||||
commonRepresentation := ""
|
||||
if err, ok := object.(error); ok {
|
||||
if err, ok := object.(error); ok && !isNilValue(value) { // isNilValue check needed here to avoid nil deref due to boxed nil
|
||||
commonRepresentation += "\n" + IndentString(err.Error(), indentation) + "\n" + indent
|
||||
}
|
||||
return fmt.Sprintf("%s<%s>: %s%s", indent, formatType(value), commonRepresentation, formatValue(value, indentation))
|
||||
@@ -302,7 +302,7 @@ func formatType(v reflect.Value) string {
|
||||
case reflect.Map:
|
||||
return fmt.Sprintf("%s | len:%d", v.Type(), v.Len())
|
||||
default:
|
||||
return fmt.Sprintf("%s", v.Type())
|
||||
return v.Type().String()
|
||||
}
|
||||
}
|
||||
|
||||
|
10
vendor/github.com/onsi/gomega/gomega_dsl.go
generated
vendored
10
vendor/github.com/onsi/gomega/gomega_dsl.go
generated
vendored
@@ -22,7 +22,7 @@ import (
|
||||
"github.com/onsi/gomega/types"
|
||||
)
|
||||
|
||||
const GOMEGA_VERSION = "1.27.5"
|
||||
const GOMEGA_VERSION = "1.30.0"
|
||||
|
||||
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().
|
||||
@@ -242,7 +242,7 @@ func ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Asse
|
||||
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). 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.
|
||||
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 expires 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:
|
||||
|
||||
@@ -313,13 +313,13 @@ It is important to note that the function passed into Eventually is invoked *syn
|
||||
}).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:
|
||||
you an also use Eventually().WithContext(ctx) to pass in the context. Passed-in contexts play nicely with passed-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.
|
||||
Either way the context passd to Eventually is also passed to the underlying function. 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**
|
||||
|
||||
@@ -349,7 +349,7 @@ For example:
|
||||
|
||||
will rerun the function until all assertions pass.
|
||||
|
||||
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:
|
||||
You can also pass additional arguments 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:
|
||||
|
||||
Eventually(func(g Gomega, ctx context.Context, path string, expected ...string){
|
||||
tok, err := client.GetToken(ctx)
|
||||
|
59
vendor/github.com/onsi/gomega/matchers.go
generated
vendored
59
vendor/github.com/onsi/gomega/matchers.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package gomega
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -52,15 +53,31 @@ func BeNil() types.GomegaMatcher {
|
||||
}
|
||||
|
||||
// BeTrue succeeds if actual is true
|
||||
//
|
||||
// In general, it's better to use `BeTrueBecause(reason)` to provide a more useful error message if a true check fails.
|
||||
func BeTrue() types.GomegaMatcher {
|
||||
return &matchers.BeTrueMatcher{}
|
||||
}
|
||||
|
||||
// BeFalse succeeds if actual is false
|
||||
//
|
||||
// In general, it's better to use `BeFalseBecause(reason)` to provide a more useful error message if a false check fails.
|
||||
func BeFalse() types.GomegaMatcher {
|
||||
return &matchers.BeFalseMatcher{}
|
||||
}
|
||||
|
||||
// BeTrueBecause succeeds if actual is true and displays the provided reason if it is false
|
||||
// fmt.Sprintf is used to render the reason
|
||||
func BeTrueBecause(format string, args ...any) types.GomegaMatcher {
|
||||
return &matchers.BeTrueMatcher{Reason: fmt.Sprintf(format, args...)}
|
||||
}
|
||||
|
||||
// BeFalseBecause succeeds if actual is false and displays the provided reason if it is true.
|
||||
// fmt.Sprintf is used to render the reason
|
||||
func BeFalseBecause(format string, args ...any) types.GomegaMatcher {
|
||||
return &matchers.BeFalseMatcher{Reason: fmt.Sprintf(format, args...)}
|
||||
}
|
||||
|
||||
// HaveOccurred succeeds if actual is a non-nil error
|
||||
// The typical Go error checking pattern looks like:
|
||||
//
|
||||
@@ -87,17 +104,45 @@ 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, function, 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)
|
||||
// When passed a string:
|
||||
//
|
||||
// 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 {
|
||||
// Expect(err).To(MatchError("an error"))
|
||||
//
|
||||
// asserts that err.Error() == "an error"
|
||||
//
|
||||
// When passed an error:
|
||||
//
|
||||
// Expect(err).To(MatchError(SomeError))
|
||||
//
|
||||
// First checks if errors.Is(err, SomeError).
|
||||
// If that fails then it checks if reflect.DeepEqual(err, SomeError) repeatedly for err and any errors wrapped by err
|
||||
//
|
||||
// When passed a matcher:
|
||||
//
|
||||
// Expect(err).To(MatchError(ContainSubstring("sprocket not found")))
|
||||
//
|
||||
// the matcher is passed err.Error(). In this case it asserts that err.Error() contains substring "sprocket not found"
|
||||
//
|
||||
// When passed a func(err) bool and a description:
|
||||
//
|
||||
// Expect(err).To(MatchError(os.IsNotExist, "IsNotExist"))
|
||||
//
|
||||
// the function is passed err and matches if the return value is true. The description is required to allow Gomega
|
||||
// to print a useful error message.
|
||||
//
|
||||
// It is an error for err to be nil or an object that does not implement the
|
||||
// Error interface
|
||||
//
|
||||
// The optional second argument is a description of the error function, if used. This is required when passing a function but is ignored in all other cases.
|
||||
func MatchError(expected interface{}, functionErrorDescription ...any) types.GomegaMatcher {
|
||||
return &matchers.MatchErrorMatcher{
|
||||
Expected: expected,
|
||||
Expected: expected,
|
||||
FuncErrDescription: functionErrorDescription,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +423,7 @@ func ContainElements(elements ...interface{}) types.GomegaMatcher {
|
||||
}
|
||||
|
||||
// HaveEach succeeds if actual solely contains elements that match the passed in element.
|
||||
// Please note that if actual is empty, HaveEach always will succeed.
|
||||
// Please note that if actual is empty, HaveEach always will fail.
|
||||
// By default HaveEach() uses Equal() to perform the match, however a
|
||||
// matcher can be passed in instead:
|
||||
//
|
||||
|
2
vendor/github.com/onsi/gomega/matchers/be_a_directory.go
generated
vendored
2
vendor/github.com/onsi/gomega/matchers/be_a_directory.go
generated
vendored
@@ -52,5 +52,5 @@ func (matcher *BeADirectoryMatcher) FailureMessage(actual interface{}) (message
|
||||
}
|
||||
|
||||
func (matcher *BeADirectoryMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, fmt.Sprintf("not be a directory"))
|
||||
return format.Message(actual, "not be a directory")
|
||||
}
|
||||
|
2
vendor/github.com/onsi/gomega/matchers/be_a_regular_file.go
generated
vendored
2
vendor/github.com/onsi/gomega/matchers/be_a_regular_file.go
generated
vendored
@@ -52,5 +52,5 @@ func (matcher *BeARegularFileMatcher) FailureMessage(actual interface{}) (messag
|
||||
}
|
||||
|
||||
func (matcher *BeARegularFileMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, fmt.Sprintf("not be a regular file"))
|
||||
return format.Message(actual, "not be a regular file")
|
||||
}
|
||||
|
4
vendor/github.com/onsi/gomega/matchers/be_an_existing_file.go
generated
vendored
4
vendor/github.com/onsi/gomega/matchers/be_an_existing_file.go
generated
vendored
@@ -32,9 +32,9 @@ func (matcher *BeAnExistingFileMatcher) Match(actual interface{}) (success bool,
|
||||
}
|
||||
|
||||
func (matcher *BeAnExistingFileMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, fmt.Sprintf("to exist"))
|
||||
return format.Message(actual, "to exist")
|
||||
}
|
||||
|
||||
func (matcher *BeAnExistingFileMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, fmt.Sprintf("not to exist"))
|
||||
return format.Message(actual, "not to exist")
|
||||
}
|
||||
|
13
vendor/github.com/onsi/gomega/matchers/be_false_matcher.go
generated
vendored
13
vendor/github.com/onsi/gomega/matchers/be_false_matcher.go
generated
vendored
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type BeFalseMatcher struct {
|
||||
Reason string
|
||||
}
|
||||
|
||||
func (matcher *BeFalseMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
@@ -20,9 +21,17 @@ func (matcher *BeFalseMatcher) Match(actual interface{}) (success bool, err erro
|
||||
}
|
||||
|
||||
func (matcher *BeFalseMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, "to be false")
|
||||
if matcher.Reason == "" {
|
||||
return format.Message(actual, "to be false")
|
||||
} else {
|
||||
return matcher.Reason
|
||||
}
|
||||
}
|
||||
|
||||
func (matcher *BeFalseMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, "not to be false")
|
||||
if matcher.Reason == "" {
|
||||
return format.Message(actual, "not to be false")
|
||||
} else {
|
||||
return fmt.Sprintf(`Expected not false but got false\nNegation of "%s" failed`, matcher.Reason)
|
||||
}
|
||||
}
|
||||
|
13
vendor/github.com/onsi/gomega/matchers/be_true_matcher.go
generated
vendored
13
vendor/github.com/onsi/gomega/matchers/be_true_matcher.go
generated
vendored
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type BeTrueMatcher struct {
|
||||
Reason string
|
||||
}
|
||||
|
||||
func (matcher *BeTrueMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
@@ -20,9 +21,17 @@ func (matcher *BeTrueMatcher) Match(actual interface{}) (success bool, err error
|
||||
}
|
||||
|
||||
func (matcher *BeTrueMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, "to be true")
|
||||
if matcher.Reason == "" {
|
||||
return format.Message(actual, "to be true")
|
||||
} else {
|
||||
return matcher.Reason
|
||||
}
|
||||
}
|
||||
|
||||
func (matcher *BeTrueMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, "not to be true")
|
||||
if matcher.Reason == "" {
|
||||
return format.Message(actual, "not to be true")
|
||||
} else {
|
||||
return fmt.Sprintf(`Expected not true but got true\nNegation of "%s" failed`, matcher.Reason)
|
||||
}
|
||||
}
|
||||
|
29
vendor/github.com/onsi/gomega/matchers/consist_of.go
generated
vendored
29
vendor/github.com/onsi/gomega/matchers/consist_of.go
generated
vendored
@@ -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
|
||||
}
|
||||
}
|
||||
|
7
vendor/github.com/onsi/gomega/matchers/have_exact_elements.go
generated
vendored
7
vendor/github.com/onsi/gomega/matchers/have_exact_elements.go
generated
vendored
@@ -44,7 +44,12 @@ func (matcher *HaveExactElementsMatcher) Match(actual interface{}) (success bool
|
||||
|
||||
elemMatcher := matchers[i].(omegaMatcher)
|
||||
match, err := elemMatcher.Match(values[i])
|
||||
if err != nil || !match {
|
||||
if err != nil {
|
||||
matcher.mismatchFailures = append(matcher.mismatchFailures, mismatchFailure{
|
||||
index: i,
|
||||
failure: err.Error(),
|
||||
})
|
||||
} else if !match {
|
||||
matcher.mismatchFailures = append(matcher.mismatchFailures, mismatchFailure{
|
||||
index: i,
|
||||
failure: elemMatcher.FailureMessage(values[i]),
|
||||
|
9
vendor/github.com/onsi/gomega/matchers/have_http_body_matcher.go
generated
vendored
9
vendor/github.com/onsi/gomega/matchers/have_http_body_matcher.go
generated
vendored
@@ -11,8 +11,9 @@ import (
|
||||
)
|
||||
|
||||
type HaveHTTPBodyMatcher struct {
|
||||
Expected interface{}
|
||||
cachedBody []byte
|
||||
Expected interface{}
|
||||
cachedResponse interface{}
|
||||
cachedBody []byte
|
||||
}
|
||||
|
||||
func (matcher *HaveHTTPBodyMatcher) Match(actual interface{}) (bool, error) {
|
||||
@@ -73,7 +74,7 @@ func (matcher *HaveHTTPBodyMatcher) NegatedFailureMessage(actual interface{}) (m
|
||||
// the Reader is closed and it is not readable again in FailureMessage()
|
||||
// or NegatedFailureMessage()
|
||||
func (matcher *HaveHTTPBodyMatcher) body(actual interface{}) ([]byte, error) {
|
||||
if matcher.cachedBody != nil {
|
||||
if matcher.cachedResponse == actual && matcher.cachedBody != nil {
|
||||
return matcher.cachedBody, nil
|
||||
}
|
||||
|
||||
@@ -91,8 +92,10 @@ func (matcher *HaveHTTPBodyMatcher) body(actual interface{}) ([]byte, error) {
|
||||
|
||||
switch a := actual.(type) {
|
||||
case *http.Response:
|
||||
matcher.cachedResponse = a
|
||||
return body(a)
|
||||
case *httptest.ResponseRecorder:
|
||||
matcher.cachedResponse = a
|
||||
return body(a.Result())
|
||||
default:
|
||||
return nil, fmt.Errorf("HaveHTTPBody matcher expects *http.Response or *httptest.ResponseRecorder. Got:\n%s", format.Object(actual, 1))
|
||||
|
25
vendor/github.com/onsi/gomega/matchers/match_error_matcher.go
generated
vendored
25
vendor/github.com/onsi/gomega/matchers/match_error_matcher.go
generated
vendored
@@ -9,10 +9,14 @@ import (
|
||||
)
|
||||
|
||||
type MatchErrorMatcher struct {
|
||||
Expected interface{}
|
||||
Expected any
|
||||
FuncErrDescription []any
|
||||
isFunc bool
|
||||
}
|
||||
|
||||
func (matcher *MatchErrorMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
func (matcher *MatchErrorMatcher) Match(actual any) (success bool, err error) {
|
||||
matcher.isFunc = false
|
||||
|
||||
if isNil(actual) {
|
||||
return false, fmt.Errorf("Expected an error, got nil")
|
||||
}
|
||||
@@ -42,6 +46,17 @@ func (matcher *MatchErrorMatcher) Match(actual interface{}) (success bool, err e
|
||||
return actualErr.Error() == expected, nil
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(expected)
|
||||
t := v.Type()
|
||||
errorInterface := reflect.TypeOf((*error)(nil)).Elem()
|
||||
if t.Kind() == reflect.Func && t.NumIn() == 1 && t.In(0).Implements(errorInterface) && t.NumOut() == 1 && t.Out(0).Kind() == reflect.Bool {
|
||||
if len(matcher.FuncErrDescription) == 0 {
|
||||
return false, fmt.Errorf("MatchError requires an additional description when passed a function")
|
||||
}
|
||||
matcher.isFunc = true
|
||||
return v.Call([]reflect.Value{reflect.ValueOf(actualErr)})[0].Bool(), nil
|
||||
}
|
||||
|
||||
var subMatcher omegaMatcher
|
||||
var hasSubMatcher bool
|
||||
if expected != nil {
|
||||
@@ -57,9 +72,15 @@ func (matcher *MatchErrorMatcher) Match(actual interface{}) (success bool, err e
|
||||
}
|
||||
|
||||
func (matcher *MatchErrorMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
if matcher.isFunc {
|
||||
return format.Message(actual, fmt.Sprintf("to match error function %s", matcher.FuncErrDescription[0]))
|
||||
}
|
||||
return format.Message(actual, "to match error", matcher.Expected)
|
||||
}
|
||||
|
||||
func (matcher *MatchErrorMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
if matcher.isFunc {
|
||||
return format.Message(actual, fmt.Sprintf("not to match error function %s", matcher.FuncErrDescription[0]))
|
||||
}
|
||||
return format.Message(actual, "not to match error", matcher.Expected)
|
||||
}
|
||||
|
Reference in New Issue
Block a user