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

refactor (crc/machine) : Provide a dummy implementation for virtualMachine object for writing unit tests (#4407) #4423

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Commits on Nov 22, 2024

  1. Add VirtualMachine interface to abstract out crc virtual machine inte…

    …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()`
    rohanKanojia committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    85f2a11 View commit details
    Browse the repository at this point in the history
  2. allow to provide fake vm implementation

    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.
    cfergeau authored and rohanKanojia committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    743a97e View commit details
    Browse the repository at this point in the history
  3. test : Add a dummy VirtualMachine implementation for use in tests

    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 <[email protected]>
    rohanKanojia committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    58b7f9f View commit details
    Browse the repository at this point in the history
  4. test (machine) : Add additional tests in stop_test.go to use dummy Vi…

    …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 <[email protected]>
    rohanKanojia committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    325b81b View commit details
    Browse the repository at this point in the history
  5. test (machine) : add vsock interaction methods to VirtualMachine inte…

    …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 <[email protected]>
    rohanKanojia committed Nov 22, 2024
    Configuration menu
    Copy the full SHA
    7cc7672 View commit details
    Browse the repository at this point in the history