-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor (crc/machine) : Add VirtualMachine interface to
machine
fo…
…r test support Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
0342835
commit c7b5852
Showing
12 changed files
with
263 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package fakemachine | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/crc-org/crc/v2/pkg/crc/machine/bundle" | ||
"github.com/crc-org/crc/v2/pkg/crc/machine/state" | ||
"github.com/crc-org/crc/v2/pkg/crc/ssh" | ||
"github.com/crc-org/crc/v2/pkg/libmachine" | ||
libmachinehost "github.com/crc-org/crc/v2/pkg/libmachine/host" | ||
"github.com/crc-org/machine/libmachine/drivers" | ||
) | ||
|
||
type FakeSSHClient struct { | ||
LastExecutedCommand string | ||
IsSshClientClosed bool | ||
Check failure on line 16 in pkg/crc/machine/fakemachine/virtualmachine.go GitHub Actions / build (ubuntu-latest, 1.22)
|
||
} | ||
|
||
func (client *FakeSSHClient) Run(command string) ([]byte, []byte, error) { | ||
client.LastExecutedCommand = command | ||
return []byte("test"), []byte("test"), nil | ||
} | ||
|
||
func (client *FakeSSHClient) Close() { | ||
client.IsSshClientClosed = true | ||
} | ||
|
||
func NewFakeSSHClient() *FakeSSHClient { | ||
return &FakeSSHClient{ | ||
LastExecutedCommand: "", | ||
IsSshClientClosed: false, | ||
} | ||
} | ||
|
||
type FakeVirtualMachine struct { | ||
IsClosed bool | ||
IsRemoved bool | ||
IsStopped bool | ||
FailingStop bool | ||
FailingState bool | ||
FakeSshClient *FakeSSHClient | ||
Check failure on line 41 in pkg/crc/machine/fakemachine/virtualmachine.go GitHub Actions / build (ubuntu-latest, 1.22)
|
||
} | ||
|
||
func (vm *FakeVirtualMachine) Close() error { | ||
vm.IsClosed = true | ||
return nil | ||
} | ||
|
||
func (vm *FakeVirtualMachine) Remove() error { | ||
vm.IsRemoved = true | ||
return nil | ||
} | ||
|
||
func (vm *FakeVirtualMachine) Stop() error { | ||
if vm.FailingStop { | ||
return errors.New("stopping failed") | ||
} | ||
vm.IsStopped = true | ||
return nil | ||
} | ||
|
||
func (vm *FakeVirtualMachine) State() (state.State, error) { | ||
if vm.FailingState { | ||
return state.Error, errors.New("unable to get virtual machine state") | ||
} | ||
if vm.IsClosed || vm.IsStopped { | ||
return state.Stopped, nil | ||
} | ||
return state.Running, nil | ||
} | ||
|
||
func (vm *FakeVirtualMachine) IP() (string, error) { | ||
panic("not implemented") | ||
} | ||
|
||
func (vm *FakeVirtualMachine) SSHPort() int { | ||
panic("not implemented") | ||
} | ||
|
||
func (vm *FakeVirtualMachine) SSHRunner() (*ssh.Runner, error) { | ||
runner, err := ssh.CreateRunnerWithClient(vm.FakeSshClient) | ||
return runner, err | ||
} | ||
|
||
func (vm *FakeVirtualMachine) Bundle() *bundle.CrcBundleInfo { | ||
panic("not implemented") | ||
} | ||
|
||
func (vm *FakeVirtualMachine) Driver() drivers.Driver { | ||
panic("not implemented") | ||
} | ||
|
||
func (vm *FakeVirtualMachine) API() libmachine.API { | ||
panic("not implemented") | ||
} | ||
|
||
func (vm *FakeVirtualMachine) GetHost() *libmachinehost.Host { | ||
panic("not implemented") | ||
} | ||
|
||
func NewFakeVirtualMachine(failingStop bool, failingState bool) *FakeVirtualMachine { | ||
return &FakeVirtualMachine{ | ||
FakeSshClient: NewFakeSSHClient(), | ||
IsStopped: false, | ||
IsRemoved: false, | ||
IsClosed: false, | ||
FailingStop: failingStop, | ||
FailingState: failingState, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.