cyclops icon indicating copy to clipboard operation
cyclops copied to clipboard

Add tests to the codebase

Open thebigbone opened this issue 1 year ago • 16 comments
trafficstars

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

thebigbone avatar Jul 13 '24 11:07 thebigbone

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 avatar Jul 14 '24 10:07 petar-cvit

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

petar-cvit avatar Jul 20 '24 11:07 petar-cvit

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!

thebigbone avatar Jul 20 '24 11:07 thebigbone

Cool, thanks

petar-cvit avatar Jul 20 '24 11:07 petar-cvit

@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?

thebigbone avatar Jul 21 '24 13:07 thebigbone

@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 avatar Jul 21 '24 13:07 petar-cvit

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

petar-cvit avatar Aug 05 '24 11:08 petar-cvit

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.

thebigbone avatar Aug 05 '24 11:08 thebigbone

@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

petar-cvit avatar Aug 05 '24 11:08 petar-cvit

@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?

thebigbone avatar Aug 05 '24 11:08 thebigbone

@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 avatar Aug 05 '24 12:08 petar-cvit

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

petar-cvit avatar Aug 16 '24 11:08 petar-cvit

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

Abiji-2020 avatar Oct 02 '24 04:10 Abiji-2020

@Abiji-2020 sure thing, will assign you

petar-cvit avatar Oct 04 '24 06:10 petar-cvit

@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

petar-cvit avatar Oct 09 '24 18:10 petar-cvit

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

  • Will update on adding tests

Abiji-2020 avatar Oct 10 '24 03:10 Abiji-2020