@@ -11,7 +11,8 @@ import (
1111 "k8s.io/apimachinery/pkg/runtime"
1212 "k8s.io/apimachinery/pkg/runtime/schema"
1313 discoveryfake "k8s.io/client-go/discovery/fake"
14- "k8s.io/client-go/dynamic/fake"
14+ dynamicfake "k8s.io/client-go/dynamic/fake"
15+ kubefake "k8s.io/client-go/kubernetes/fake"
1516 ktesting "k8s.io/client-go/testing"
1617)
1718
@@ -24,7 +25,7 @@ func TestListClusteredResources(t *testing.T) {
2425 {Group : "rbac.authorization.k8s.io" , Version : "v1" , Resource : "clusterroles" }: "ClusterRoleList" ,
2526 }
2627
27- client := fake .NewSimpleDynamicClientWithCustomListKinds (scheme , listKinds )
28+ client := dynamicfake .NewSimpleDynamicClientWithCustomListKinds (scheme , listKinds )
2829
2930 // Create a test client with the fake dynamic client
3031 testClient := & Client {
@@ -84,7 +85,7 @@ func TestListNamespacedResources(t *testing.T) {
8485 {Group : "" , Version : "v1" , Resource : "services" }: "ServiceList" ,
8586 }
8687
87- client := fake .NewSimpleDynamicClientWithCustomListKinds (scheme , listKinds )
88+ client := dynamicfake .NewSimpleDynamicClientWithCustomListKinds (scheme , listKinds )
8889
8990 // Create a test client with the fake dynamic client
9091 testClient := & Client {
@@ -140,7 +141,7 @@ func TestListNamespacedResources(t *testing.T) {
140141func TestApplyClusteredResource (t * testing.T ) {
141142 // Create a fake dynamic client
142143 scheme := runtime .NewScheme ()
143- client := fake .NewSimpleDynamicClient (scheme )
144+ client := dynamicfake .NewSimpleDynamicClient (scheme )
144145
145146 // Create a test client with the fake dynamic client
146147 testClient := & Client {
@@ -196,7 +197,7 @@ func TestApplyClusteredResource(t *testing.T) {
196197func TestApplyNamespacedResource (t * testing.T ) {
197198 // Create a fake dynamic client
198199 scheme := runtime .NewScheme ()
199- client := fake .NewSimpleDynamicClient (scheme )
200+ client := dynamicfake .NewSimpleDynamicClient (scheme )
200201
201202 // Create a test client with the fake dynamic client
202203 testClient := & Client {
@@ -254,7 +255,7 @@ func TestApplyNamespacedResource(t *testing.T) {
254255func TestGetClusteredResource (t * testing.T ) {
255256 // Create a fake dynamic client
256257 scheme := runtime .NewScheme ()
257- client := fake .NewSimpleDynamicClient (scheme )
258+ client := dynamicfake .NewSimpleDynamicClient (scheme )
258259
259260 // Create a test client with the fake dynamic client
260261 testClient := & Client {
@@ -307,7 +308,7 @@ func TestGetClusteredResource(t *testing.T) {
307308func TestGetNamespacedResource (t * testing.T ) {
308309 // Create a fake dynamic client
309310 scheme := runtime .NewScheme ()
310- client := fake .NewSimpleDynamicClient (scheme )
311+ client := dynamicfake .NewSimpleDynamicClient (scheme )
311312
312313 // Create a test client with the fake dynamic client
313314 testClient := & Client {
@@ -365,7 +366,7 @@ func TestSetDynamicClient(t *testing.T) {
365366
366367 // Create a fake dynamic client
367368 scheme := runtime .NewScheme ()
368- fakeDynamicClient := fake .NewSimpleDynamicClient (scheme )
369+ fakeDynamicClient := dynamicfake .NewSimpleDynamicClient (scheme )
369370
370371 // Set the dynamic client
371372 testClient .SetDynamicClient (fakeDynamicClient )
@@ -389,28 +390,35 @@ func TestSetDiscoveryClient(t *testing.T) {
389390}
390391
391392func TestIsReady (t * testing.T ) {
392- // Test with both clients nil
393+ // Test with all clients nil
393394 testClient := & Client {}
394- assert .False (t , testClient .IsReady (), "Expected IsReady to return false when both clients are nil" )
395+ assert .False (t , testClient .IsReady (), "Expected IsReady to return false when all clients are nil" )
395396
396397 // Test with only dynamic client set
397398 testClient = & Client {}
398399 scheme := runtime .NewScheme ()
399- fakeDynamicClient := fake .NewSimpleDynamicClient (scheme )
400+ fakeDynamicClient := dynamicfake .NewSimpleDynamicClient (scheme )
400401 testClient .SetDynamicClient (fakeDynamicClient )
401- assert .False (t , testClient .IsReady (), "Expected IsReady to return false when discovery client is nil" )
402+ assert .False (t , testClient .IsReady (), "Expected IsReady to return false when some clients are nil" )
402403
403404 // Test with only discovery client set
404405 testClient = & Client {}
405406 fakeDiscoveryClient := & discoveryfake.FakeDiscovery {Fake : & ktesting.Fake {}}
406407 testClient .SetDiscoveryClient (fakeDiscoveryClient )
407- assert .False (t , testClient .IsReady (), "Expected IsReady to return false when dynamic client is nil" )
408+ assert .False (t , testClient .IsReady (), "Expected IsReady to return false when some clients are nil" )
408409
409- // Test with both clients set
410+ // Test with only clientset set
411+ testClient = & Client {}
412+ fakeClientset := kubefake .NewSimpleClientset ()
413+ testClient .SetClientset (fakeClientset )
414+ assert .False (t , testClient .IsReady (), "Expected IsReady to return false when some clients are nil" )
415+
416+ // Test with all clients set
410417 testClient = & Client {}
411418 testClient .SetDynamicClient (fakeDynamicClient )
412419 testClient .SetDiscoveryClient (fakeDiscoveryClient )
413- assert .True (t , testClient .IsReady (), "Expected IsReady to return true when both clients are set" )
420+ testClient .SetClientset (fakeClientset )
421+ assert .True (t , testClient .IsReady (), "Expected IsReady to return true when all clients are set" )
414422}
415423
416424func TestListAPIResources (t * testing.T ) {
0 commit comments