Skip to content

Commit 9642a63

Browse files
committed
Fixed SubResource/Status calling logic
1 parent 00597ac commit 9642a63

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pkg/client/fake/intercept.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (c interceptor) DeleteAllOf(ctx context.Context, obj client.Object, opts ..
9696
}
9797

9898
func (c interceptor) Status() client.SubResourceWriter {
99-
return c.client.Status()
99+
return c.SubResource("status")
100100
}
101101

102102
func (c interceptor) SubResource(subResource string) client.SubResourceClient {

pkg/client/fake/intercept_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,33 @@ var _ = Describe("Interceptor", func() {
220220
_ = client2.SubResource("")
221221
Expect(called).To(BeTrue())
222222
})
223+
It("should call the provided SubResource function with 'status' when calling Status()", func() {
224+
var called bool
225+
client := Interceptor(wrappedClient, InterceptorFns{
226+
SubResource: func(client client.WithWatch, subResource string) client.SubResourceClient {
227+
if subResource == "status" {
228+
called = true
229+
}
230+
return nil
231+
},
232+
})
233+
_ = client.Status()
234+
Expect(called).To(BeTrue())
235+
})
236+
It("should call the underlying client if the provided SubResource function is nil when calling Status", func() {
237+
var called bool
238+
client1 := Interceptor(wrappedClient, InterceptorFns{
239+
SubResource: func(client client.WithWatch, subResource string) client.SubResourceClient {
240+
if subResource == "status" {
241+
called = true
242+
}
243+
return nil
244+
},
245+
})
246+
client2 := Interceptor(client1, InterceptorFns{})
247+
_ = client2.Status()
248+
Expect(called).To(BeTrue())
249+
})
223250
})
224251

225252
var _ = Describe("SubResourceInterceptor", func() {

0 commit comments

Comments
 (0)