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

[Test] Provide a dummy implementation for virtualMachine object for writing unit tests #4407

Open
2 tasks
rohanKanojia opened this issue Oct 21, 2024 · 7 comments
Assignees

Comments

@rohanKanojia
Copy link
Contributor

Component

Internal Testing Utilities

Description

Originally discussed in internal chat

Currently, there are not many unit tests in pkg/crc/machine module, probably due to the code dealing directly with managing virtual machines. It makes writing unit tests for CRC start, stop, and delete a bit difficult.

I think we can add some dummy mock implementation for this virtualMachine object that can be used while writing unit tests. It can store the state of the virtualMachine as some variable that we can expose in tests to assert whether CRC was able to modify the state of VirtualMachine after performing some action (Stop, Start, Delete, etc).

Gerard said they had something like a null driver in minishift codebase that could be used in the tests. Not 100% sure whether this is the correct reference: minishift@pkg/minishift/provisioner/minishift_provisioner_test.go

Acceptance Criteria

  • A dummy implementation is added so that it can be used in tests.
  • code is refactored so that we can this dummy implementation can be picked with some argument (fake driver?).
@cfergeau
Copy link
Contributor

Would it be enough to be able to override loadVirtualMachine so that it is possible to load a fakemachine instead of the real one?

@rohanKanojia
Copy link
Contributor Author

@cfergeau : Yes, that can satisfy my use case. Do you have some examples of how I can achieve that? Perhaps you could share some old pull requests where the team might have added something close to this?

@cfergeau
Copy link
Contributor

Do you have some examples of how I can achieve that?

@lstocchi did something similar in vfkit unit tests recently, he should be able to help with that.

@lstocchi
Copy link

@rohanKanojia I joined recently and I didn't have the time to look at the crc project yet so I'm not really able to tell you if what I did is suitable for your use case. You can find the code here crc-org/vfkit@41e879f . Basically I had to test cloud-init to see if the configuration file was actually read. So I created a fedora machine, mount an image containing the config file, started the vm and interacted with it to verify everything was set accordingly.
You can give that a look to see if it's helpful.
BTW feel free to ping me if you need help, it would be a chance for me to look at crc 👍

@cfergeau
Copy link
Contributor

What I had in mind is the code where you use a function variable to be able to mock a function in a test, I forgot where it is exactly :)

@rohanKanojia
Copy link
Contributor Author

Could someone please assign this issue to me?

@cfergeau
Copy link
Contributor

Could someone please assign this issue to me?

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants