88 "time"
99
1010 "github.com/onsi/gomega"
11+ "github.com/onsi/gomega/types"
1112 "k8s.io/apimachinery/pkg/runtime"
1213 "k8s.io/apimachinery/pkg/util/uuid"
1314 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -18,6 +19,7 @@ import (
1819 "sigs.k8s.io/controller-runtime/pkg/reconcile"
1920
2021 "github.com/openmcp-project/controller-utils/pkg/logging"
22+ "github.com/openmcp-project/controller-utils/pkg/testing/matchers"
2123)
2224
2325/////////////////
@@ -84,27 +86,37 @@ func (e *ComplexEnvironment) shouldEventuallyReconcile(reconciler string, req re
8486
8587// ShouldNotReconcile calls the given reconciler with the given request and expects an error.
8688func (e * ComplexEnvironment ) ShouldNotReconcile (reconciler string , req reconcile.Request , optionalDescription ... interface {}) reconcile.Result {
87- return e .shouldNotReconcile (reconciler , req , optionalDescription ... )
89+ return e .shouldNotReconcile (reconciler , req , nil , optionalDescription ... )
8890}
8991
90- func (e * ComplexEnvironment ) shouldNotReconcile (reconciler string , req reconcile.Request , optionalDescription ... interface {}) reconcile.Result {
92+ // ShouldNotReconcileWithError calls the given reconciler with the given request and expects an error that matches the given matcher.
93+ func (e * ComplexEnvironment ) ShouldNotReconcileWithError (reconciler string , req reconcile.Request , matcher types.GomegaMatcher , optionalDescription ... interface {}) reconcile.Result {
94+ return e .shouldNotReconcile (reconciler , req , matcher , optionalDescription ... )
95+ }
96+
97+ func (e * ComplexEnvironment ) shouldNotReconcile (reconciler string , req reconcile.Request , matcher types.GomegaMatcher , optionalDescription ... interface {}) reconcile.Result {
9198 res , err := e .Reconcilers [reconciler ].Reconcile (e .Ctx , req )
92- gomega .ExpectWithOffset (2 , err ).To (gomega .HaveOccurred (), optionalDescription ... )
99+ gomega .ExpectWithOffset (2 , err ).To (gomega .And ( gomega . HaveOccurred (), matchers . MaybeMatch ( matcher ) ), optionalDescription ... )
93100 return res
94101}
95102
96103// ShouldEventuallyNotReconcile calls the given reconciler with the given request and retries until an error occurred or the timeout is reached.
97104func (e * ComplexEnvironment ) ShouldEventuallyNotReconcile (reconciler string , req reconcile.Request , timeout , poll time.Duration , optionalDescription ... interface {}) reconcile.Result {
98- return e .shouldEventuallyNotReconcile (reconciler , req , timeout , poll , optionalDescription ... )
105+ return e .shouldEventuallyNotReconcile (reconciler , req , nil , timeout , poll , optionalDescription ... )
106+ }
107+
108+ // ShouldEventuallyNotReconcileWithError calls the given reconciler with the given request and retries until an error that matches the given matcher occurred or the timeout is reached.
109+ func (e * ComplexEnvironment ) ShouldEventuallyNotReconcileWithError (reconciler string , req reconcile.Request , matcher types.GomegaMatcher , timeout , poll time.Duration , optionalDescription ... interface {}) reconcile.Result {
110+ return e .shouldEventuallyNotReconcile (reconciler , req , matcher , timeout , poll , optionalDescription ... )
99111}
100112
101- func (e * ComplexEnvironment ) shouldEventuallyNotReconcile (reconciler string , req reconcile.Request , timeout , poll time.Duration , optionalDescription ... interface {}) reconcile.Result {
113+ func (e * ComplexEnvironment ) shouldEventuallyNotReconcile (reconciler string , req reconcile.Request , matcher types. GomegaMatcher , timeout , poll time.Duration , optionalDescription ... interface {}) reconcile.Result {
102114 var err error
103115 var res reconcile.Result
104116 gomega .EventuallyWithOffset (1 , func () error {
105117 res , err = e .Reconcilers [reconciler ].Reconcile (e .Ctx , req )
106118 return err
107- }, timeout , poll ).ShouldNot (gomega .Succeed (), optionalDescription ... )
119+ }, timeout , poll ).ShouldNot (gomega .And ( gomega . Succeed (), matchers . MaybeMatch ( matcher ) ), optionalDescription ... )
108120 return res
109121}
110122
0 commit comments