Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to the codebase #413

Open
thebigbone opened this issue Jul 13, 2024 · 11 comments
Open

Add tests to the codebase #413

thebigbone opened this issue Jul 13, 2024 · 11 comments
Assignees
Labels
go Pull requests that update Go code

Comments

@thebigbone
Copy link
Contributor

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
Copy link
Collaborator

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 petar-cvit added the go Pull requests that update Go code label Jul 14, 2024
@petar-cvit
Copy link
Collaborator

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

@thebigbone
Copy link
Contributor Author

thebigbone commented Jul 20, 2024

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
Copy link
Collaborator

Cool, thanks

@thebigbone
Copy link
Contributor Author

thebigbone commented Jul 21, 2024

@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
Copy link
Collaborator

@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
Copy link
Collaborator

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
Copy link
Contributor Author

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
Copy link
Collaborator

@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
Copy link
Contributor Author

@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
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code
Projects
None yet
Development

No branches or pull requests

2 participants