-
Notifications
You must be signed in to change notification settings - Fork 256
refactor (crc/machine) : Provide a dummy implementation for virtualMachine object for writing unit tests (#4407) #4423
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
base: main
Are you sure you want to change the base?
Conversation
|
Hi @rohanKanojia. Thanks for your PR. I'm waiting for a crc-org member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
0e36ad5 to
988b812
Compare
988b812 to
4d2f859
Compare
ada0fc6 to
fac1ad5
Compare
fac1ad5 to
d2022f9
Compare
pkg/crc/machine/stop_test.go
Outdated
| assert.NoError(t, stopErr) | ||
| assert.Equal(t, clusterState, state.Stopped) | ||
| assert.Equal(t, virtualMachine.IsStopped, true) | ||
| assert.Equal(t, virtualMachine.FakeSSHClient.LastExecutedCommand, "sudo -- sh -c 'crictl stop $(crictl ps -q)'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, the fact that crictl stop is the last command we run in the VM should be an implementation detail, it can change at any time if we refactor this code, if we add new things to the bundle which needs to be stopped, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review, I'll remove this assertion.
d2022f9 to
7cc7672
Compare
7cc7672 to
eaa25cd
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
eaa25cd to
4ddff09
Compare
4ddff09 to
d10dd49
Compare
d10dd49 to
e47ec9d
Compare
…raction
Add a VirtualMachine interface and make the CRC `machine` package client use the VirtualMachine interface instead of a concrete implementation. This way we can inject a dummy test FakeVirtualMachine implementation into client tests that can ease writing tests for this package.
- Add some additional methods in VirtualMachine interface so that we can replace direct usage of struct fields with interface methods
- `Bundle()`
- `Driver()`
- `API()`
- `Host()`
- `Kill()`
Introduce a new constructor method `newClientWithVirtualMachine` in machine client that would have an additional VirtualMachine argument, this would be kept package private so that it's used only by tests in the same package.
Add FakeVirtualMachine sturct in `fakemachine` for adding dummy implementation for `VirtualMachine` interface. Currently, I've only completed methods used by `stop_test.go`, I'll add more in small increments as we implement more unit tests using this implementation. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…rtualMachine implementation Add additional tests in `stop_test.go` to verify that client.Stop() updates the state of virtual machine and unexposes exposed ports as expected. Use the fake vm implementation added previously to test vm state modification behavior on stop. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…rface Make VirtualMachine implement vsock methods so that vsock interaction is also done via VirtualMachine interface. This would help in writing tests, we can override the behavior of expose/unexpose in fake vm implementation. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
e47ec9d to
5b63280
Compare
Description
Fixes: Issue #4407
Relates to: Issue #4407, PR #4400
Type of change
test, version modification, documentation, etc.)
Checklist
Solution/Idea
machinepackage client use the VirtualMachine interface instead of a concrete implementation. This way we can inject a dummy test FakeVirtualMachine implementation into client tests that can ease writing tests for this package.Bundle()Driver()API()GetHost()VirtualMachinein the client so we can avoid creating it if it's already created.newClientWithVirtualMachinein machine client that would have an additional VirtualMachine argument, this would be kept package private so that it's used only by tests in the same package.fakemachinefor adding dummy implementation forVirtualMachineinterface. Currently, I've only completed methods used bystop_test.go, I'll add more in small increments as I get more familiar with the project.Proposed changes
VirtualMachineinterface and make client member functions use it instead ofvirtualMachinestruct.VirtualMachineimplementation from testsVirtualMachineinterface instead ofvirtualMachinestruct (these changes are only related to changing use ofvirtualMachinestruct toVirtualMachineinterface:pkg/crc/machine/ip.gopkg/crc/machine/poweroff.gopkg/crc/machine/start.gopkg/crc/machine/status.gopkg/crc/machine/stop.goTesting
It's a small refactor. I've only run E2E tests locally to verify if these changes don't introduce any kind of regression.