K8 unit test for Describe package in meshkit

Hello devs, i am creating unit tests for the describe package in meshkit,

Here is the link to my pr K8 Unit tests by Philip-21 · Pull Request #319 · meshery/meshkit · GitHub

The main goal of this testcase is to test the describe() which takes in a mesh client and k8 resource options .
When running the testcase it gave this error message ,
“A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.”
i dont know if the issue is from the request url or the response in my testcase struct , i had minikube and kubectl running locally while performing the tests case and it gave this error,

Initially, i also tried using a fake client as a testcase

	// Create a fake clientset
clientset := fake.NewSimpleClientset()
// Convert clientset to JSON
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(clientset)
if err != nil {
	log.Fatalf("Failed to convert clientset to unstructured: %v", err)
jsonBytes, err := json.Marshal(obj)
if err != nil {
	log.Fatalf("Failed to marshal clientset to JSON: %v", err)
meshclient, err := meshkitkube.New(jsonBytes)
if err != nil {
	log.Println("error in loading Kube configs for tests", err)

but i got errors because it couldnt convert some certain aspects of the fake client to []bytes which will be used as a parameter for the meshkit.New() that will be used and initaized in the describe().

Since Kubernetes unit test does not necessarily require a yml file and yml files are mainly for deployment , the Unit tests are meant to be typically focused on testing individual functions or components in isolation rather than interacting with actual Kubernetes clusters, and our main focus is testing the describe() , but on testing the describe() we need to initialize a meshclient, and the meshclient requires me to use a yml file.
Please i really need help in figuring this out

@revoly You might like to take a look here.

@Aisuko also might want to offer some thoughts here

Hi, guys. We already have two strategies for unit test cases in meshery-operator also in other projects too.
1, The first one is fakeclient from k8s packages and it is used to test CRDs compatibility for newer version k8s.
2, env-test from controller-runtime package, and it is used to run the integration test for the controller.

If you want to mock api-server response you can also use controller-runtime to create a response. So, there is no reason to use anything related to Unstructured. We register the CRDs scheme at the test beginning. We do not want to the code be more complex for other contributors. And as I mentioned before, please make sure you get a proposal from Revolyssup (Ashish Tiwari) · GitHub, He is the core maintainer of meshery/meshkit. After that, you can continue to work for your PR.

Thanks for the feedback.
So are you saying the error is from the Mock response Fields I created ?
And Using controller-runtime to create a response will be the best case

This is some great work, @Philip-21. :clap: