Skip to content

Commit

Permalink
Fix VirtualMachine.IsPaused (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
rybnico authored Oct 6, 2024
1 parent 824e06b commit 4265950
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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())
}

0 comments on commit 4265950

Please sign in to comment.