@@ -150,6 +150,27 @@ var _ = Describe("runtime inject", func() {
150
150
Expect (res ).To (Equal (true ))
151
151
})
152
152
153
+ It ("should set api reader" , func () {
154
+ apiReader := & client.DelegatingReader {}
155
+
156
+ By ("Validating injecting client" )
157
+ res , err := APIReaderInto (apiReader , instance )
158
+ Expect (err ).NotTo (HaveOccurred ())
159
+ Expect (res ).To (Equal (true ))
160
+ Expect (apiReader ).To (Equal (instance .GetAPIReader ()))
161
+
162
+ By ("Returning false if the type does not implement inject.Client" )
163
+ res , err = APIReaderInto (apiReader , uninjectable )
164
+ Expect (err ).NotTo (HaveOccurred ())
165
+ Expect (res ).To (Equal (false ))
166
+ Expect (uninjectable .GetAPIReader ()).To (BeNil ())
167
+
168
+ By ("Returning an error if client injection fails" )
169
+ res , err = APIReaderInto (nil , instance )
170
+ Expect (err ).To (Equal (errInjectFail ))
171
+ Expect (res ).To (Equal (true ))
172
+ })
173
+
153
174
It ("should set dependencies" , func () {
154
175
155
176
f := func (interface {}) error { return nil }
@@ -175,12 +196,13 @@ var _ = Describe("runtime inject", func() {
175
196
})
176
197
177
198
type testSource struct {
178
- scheme * runtime.Scheme
179
- cache cache.Cache
180
- config * rest.Config
181
- client client.Client
182
- f Func
183
- stop <- chan struct {}
199
+ scheme * runtime.Scheme
200
+ cache cache.Cache
201
+ config * rest.Config
202
+ client client.Client
203
+ apiReader client.Reader
204
+ f Func
205
+ stop <- chan struct {}
184
206
}
185
207
186
208
func (s * testSource ) InjectCache (c cache.Cache ) error {
@@ -223,6 +245,14 @@ func (s *testSource) InjectStopChannel(stop <-chan struct{}) error {
223
245
return fmt .Errorf ("injection fails" )
224
246
}
225
247
248
+ func (s * testSource ) InjectAPIReader (reader client.Reader ) error {
249
+ if reader != nil {
250
+ s .apiReader = reader
251
+ return nil
252
+ }
253
+ return fmt .Errorf ("injection fails" )
254
+ }
255
+
226
256
func (s * testSource ) InjectFunc (f Func ) error {
227
257
if f != nil {
228
258
s .f = f
@@ -247,6 +277,10 @@ func (s *testSource) GetClient() client.Client {
247
277
return s .client
248
278
}
249
279
280
+ func (s * testSource ) GetAPIReader () client.Reader {
281
+ return s .apiReader
282
+ }
283
+
250
284
func (s * testSource ) GetFunc () Func {
251
285
return s .f
252
286
}
@@ -256,12 +290,13 @@ func (s *testSource) GetStop() <-chan struct{} {
256
290
}
257
291
258
292
type failSource struct {
259
- scheme * runtime.Scheme
260
- cache cache.Cache
261
- config * rest.Config
262
- client client.Client
263
- f Func
264
- stop <- chan struct {}
293
+ scheme * runtime.Scheme
294
+ cache cache.Cache
295
+ config * rest.Config
296
+ client client.Client
297
+ apiReader client.Reader
298
+ f Func
299
+ stop <- chan struct {}
265
300
}
266
301
267
302
func (s * failSource ) GetCache () cache.Cache {
@@ -280,6 +315,10 @@ func (s *failSource) GetClient() client.Client {
280
315
return s .client
281
316
}
282
317
318
+ func (s * failSource ) GetAPIReader () client.Reader {
319
+ return s .apiReader
320
+ }
321
+
283
322
func (s * failSource ) GetFunc () Func {
284
323
return s .f
285
324
}
0 commit comments