cyclops-ui / cyclops

Developer Friendly Kubernetes 👁️
https://cyclops-ui.com
Apache License 2.0
2.48k stars 774 forks source link

Add tests to the codebase #413

Open thebigbone opened 4 months ago

thebigbone commented 4 months ago

I think we should start adding tests and possibly add it to the CI as well? I can start with the cli and aim for a good coverage score

petar-cvit commented 4 months ago

Completely agree. I have set up the CI for the controller, but since there were no tests on the cyctl, I didn't add the tests there. If you would like to add tests to cyctl, you can change this GH action to run them on each push.

petar-cvit commented 3 months ago

Hey @thebigbone, do you have any updates on this?

thebigbone commented 3 months ago

Hey @thebigbone, do you have any updates on this?

Hey I have not made much progress because of less spare time. I am planning to atleast cover the half of cli in the next week!

petar-cvit commented 3 months ago

Cool, thanks

thebigbone commented 3 months ago

@petar-cvit should we use minikube in the github actions for commands like init and serve? Or should I just write simple tests which do not require testing on a cluster?

petar-cvit commented 3 months ago

@thebigbone I think it's good enough to test it with unit tests without setting up the cluster, at least for start. We can add tests that require a cluster later on

petar-cvit commented 3 months ago

Hey @thebigbone, do you have any update on cyctl unit tests? I'm looking to update our CI for cyctl and add a test step

thebigbone commented 3 months ago

Hey, I should have asked this before but I am stuck at what tests would be sufficient. Should I just compare the output buffer only or should I create fake clientsets for kubernetes commands? Apologies for the delay.

petar-cvit commented 3 months ago

@thebigbone you can create a mock for clientset? You can create and use an interface in the code and then pass a mock in tests

thebigbone commented 3 months ago

@thebigbone you can create a mock for clientset? You can create and use an interface in the code and then pass a mock in tests

Mock of the k8s client right? And what about the module commands?

petar-cvit commented 3 months ago

@thebigbone you can take an interface here instead of passing CyclopsV1Alpha1Client struct directly. Then, you can pass a mock struct in your tests and an actual struct in code when creating Modules and other resources.

Same goes for other actions also. We are using ginkgo and gomega for testing in cyclops-ctrl, so you can use those as well and check how to use mocks with those

petar-cvit commented 2 months ago

Hey @thebigbone, did you manage to create some tests for the cyctl? Would love to take a look and try to integrate it with our CI

Abiji-2020 commented 1 month ago

@petar-cvit interested to add tests for the cyctl command line. Shall I start creating the unit tests ?

petar-cvit commented 1 month ago

@Abiji-2020 sure thing, will assign you

petar-cvit commented 1 month ago

@Abiji-2020 I made a K8s client mock you can use in your tests. Still on a PR, but you can branch out from there and implement tests for cyctl. Here is the PR

cc @thebigbone

Abiji-2020 commented 1 month ago

@petar-cvit thanks very much I am finding it hard to create a mock. you helped me 🧡