Skip to content

KubernetesMockServerExtension uses getDeclaredFields #4649

@wind57

Description

@wind57

Describe the bug

At the moment, KubernetesMockServerExtension uses Field[] fields = testClass.getDeclaredFields(); to find out if server or client are present in the test class.

We have a use case where we want to be able to say something along the lines:

abstract class Common {
     static KubernetesClient mockClient;

     void mockClientMethods() {
             mockClient .... 
     }
}
@EnableKubernetesMockClient(crud = true, https = false)
class ActualTest extends Common {
      
      @Test
      void test() {
           // use mockClient 
      }
}

This obviously fails, because ActualTest has no such field of type KubernetesClient

Fabric8 Kubernetes Client version

6.2.0

Steps to reproduce

Already presented above.

Expected behavior

KubernetesMockServerExtension should traverse the entire hierarchy of the test class to find if a client/server is present and set it in the proper place

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.25.3@latest

Environment

macOS

Fabric8 Kubernetes Client Logs

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions