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

Fix VirtualMachine.IsPaused #169

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (v *VirtualMachine) Stop(ctx context.Context) (task *Task, err error) {
}

func (v *VirtualMachine) IsPaused() bool {
return v.Status == StatusVirtualMachineRunning
return v.Status == StatusVirtualMachinePaused
}

func (v *VirtualMachine) Pause(ctx context.Context) (task *Task, err error) {
Expand Down
34 changes: 34 additions & 0 deletions virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,37 @@ func TestVirtualMachineCloneWithoutNewID(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 100, newID)
}

func TestVirtualMachineState(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
runningVM := VirtualMachine{
Status: "running",
}
assert.False(t, runningVM.IsStopped())
assert.False(t, runningVM.IsPaused())
assert.False(t, runningVM.IsHibernated())
assert.True(t, runningVM.IsRunning())
stoppedVM := VirtualMachine{
Status: "stopped",
}
assert.True(t, stoppedVM.IsStopped())
assert.False(t, stoppedVM.IsPaused())
assert.False(t, stoppedVM.IsHibernated())
assert.False(t, stoppedVM.IsRunning())
pausedVM := VirtualMachine{
Status: "paused",
}
assert.False(t, pausedVM.IsStopped())
assert.True(t, pausedVM.IsPaused())
assert.False(t, pausedVM.IsHibernated())
assert.False(t, pausedVM.IsRunning())
hibernatedVM := VirtualMachine{
Status: "stopped",
Lock: "suspended",
}
assert.True(t, hibernatedVM.IsStopped())
assert.False(t, hibernatedVM.IsPaused())
assert.True(t, hibernatedVM.IsHibernated())
assert.False(t, hibernatedVM.IsRunning())
}
Loading