@@ -22,6 +22,7 @@ import (
22
22
"strings"
23
23
"sync/atomic"
24
24
25
+ "github.com/go-logr/logr"
25
26
. "github.com/onsi/ginkgo"
26
27
. "github.com/onsi/gomega"
27
28
@@ -48,6 +49,17 @@ func (typedNoop) Reconcile(context.Context, reconcile.Request) (reconcile.Result
48
49
return reconcile.Result {}, nil
49
50
}
50
51
52
+ type testLogger struct {
53
+ logr.Logger
54
+ }
55
+
56
+ func (l * testLogger ) WithName (_ string ) logr.Logger {
57
+ return l
58
+ }
59
+ func (l * testLogger ) WithValues (_ ... interface {}) logr.Logger {
60
+ return l
61
+ }
62
+
51
63
var _ = Describe ("application" , func () {
52
64
var stop chan struct {}
53
65
@@ -160,6 +172,29 @@ var _ = Describe("application", func() {
160
172
Expect (instance ).NotTo (BeNil ())
161
173
})
162
174
175
+ It ("should override logger during creation of controller" , func () {
176
+
177
+ logger := & testLogger {}
178
+ newController = func (name string , mgr manager.Manager , options controller.Options ) (controller.Controller , error ) {
179
+ if options .Log == logger {
180
+ return controller .New (name , mgr , options )
181
+ }
182
+ return nil , fmt .Errorf ("logger expected %T but found %T" , logger , options .Log )
183
+ }
184
+
185
+ By ("creating a controller manager" )
186
+ m , err := manager .New (cfg , manager.Options {})
187
+ Expect (err ).NotTo (HaveOccurred ())
188
+
189
+ instance , err := ControllerManagedBy (m ).
190
+ For (& appsv1.ReplicaSet {}).
191
+ Owns (& appsv1.ReplicaSet {}).
192
+ WithLogger (logger ).
193
+ Build (noop )
194
+ Expect (err ).NotTo (HaveOccurred ())
195
+ Expect (instance ).NotTo (BeNil ())
196
+ })
197
+
163
198
It ("should prefer reconciler from options during creation of controller" , func () {
164
199
newController = func (name string , mgr manager.Manager , options controller.Options ) (controller.Controller , error ) {
165
200
if options .Reconciler != (typedNoop {}) {
0 commit comments