Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
b65559d8
Commit
b65559d8
authored
Dec 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: StepShutdown tests
parent
67a87ce3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
1 deletion
+113
-1
builder/virtualbox/common/driver_mock.go
builder/virtualbox/common/driver_mock.go
+7
-0
builder/virtualbox/common/step_shutdown.go
builder/virtualbox/common/step_shutdown.go
+1
-1
builder/virtualbox/common/step_shutdown_test.go
builder/virtualbox/common/step_shutdown_test.go
+105
-0
No files found.
builder/virtualbox/common/driver_mock.go
View file @
b65559d8
package
common
import
"sync"
type
DriverMock
struct
{
sync
.
Mutex
CreateSATAControllerVM
string
CreateSATAControllerController
string
CreateSATAControllerErr
error
...
...
@@ -33,6 +37,9 @@ func (d *DriverMock) CreateSATAController(vm string, controller string) error {
}
func
(
d
*
DriverMock
)
IsRunning
(
name
string
)
(
bool
,
error
)
{
d
.
Lock
()
defer
d
.
Unlock
()
d
.
IsRunningName
=
name
return
d
.
IsRunningReturn
,
d
.
IsRunningErr
}
...
...
builder/virtualbox/common/step_shutdown.go
View file @
b65559d8
...
...
@@ -58,7 +58,7 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction {
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
default
:
time
.
Sleep
(
1
*
time
.
S
econd
)
time
.
Sleep
(
500
*
time
.
Millis
econd
)
}
}
}
else
{
...
...
builder/virtualbox/common/step_shutdown_test.go
0 → 100644
View file @
b65559d8
package
common
import
(
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"testing"
"time"
)
func
TestStepShutdown_impl
(
t
*
testing
.
T
)
{
var
_
multistep
.
Step
=
new
(
StepShutdown
)
}
func
TestStepShutdown_noShutdownCommand
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepShutdown
)
comm
:=
new
(
packer
.
MockCommunicator
)
state
.
Put
(
"communicator"
,
comm
)
state
.
Put
(
"vmName"
,
"foo"
)
driver
:=
state
.
Get
(
"driver"
)
.
(
*
DriverMock
)
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
ok
{
t
.
Fatal
(
"should NOT have error"
)
}
// Test that Stop was just called
if
driver
.
StopName
!=
"foo"
{
t
.
Fatal
(
"should call stop"
)
}
if
comm
.
StartCalled
{
t
.
Fatal
(
"comm start should not be called"
)
}
}
func
TestStepShutdown_shutdownCommand
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepShutdown
)
step
.
Command
=
"poweroff"
step
.
Timeout
=
1
*
time
.
Second
comm
:=
new
(
packer
.
MockCommunicator
)
state
.
Put
(
"communicator"
,
comm
)
state
.
Put
(
"vmName"
,
"foo"
)
driver
:=
state
.
Get
(
"driver"
)
.
(
*
DriverMock
)
driver
.
IsRunningReturn
=
true
go
func
()
{
time
.
Sleep
(
10
*
time
.
Millisecond
)
driver
.
Lock
()
defer
driver
.
Unlock
()
driver
.
IsRunningReturn
=
false
}()
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
ok
{
t
.
Fatal
(
"should NOT have error"
)
}
// Test that Stop was just called
if
driver
.
StopName
!=
""
{
t
.
Fatal
(
"should not call stop"
)
}
if
comm
.
StartCmd
.
Command
!=
step
.
Command
{
t
.
Fatal
(
"comm start should be called"
)
}
}
func
TestStepShutdown_shutdownTimeout
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepShutdown
)
step
.
Command
=
"poweroff"
step
.
Timeout
=
1
*
time
.
Second
comm
:=
new
(
packer
.
MockCommunicator
)
state
.
Put
(
"communicator"
,
comm
)
state
.
Put
(
"vmName"
,
"foo"
)
driver
:=
state
.
Get
(
"driver"
)
.
(
*
DriverMock
)
driver
.
IsRunningReturn
=
true
go
func
()
{
time
.
Sleep
(
2
*
time
.
Second
)
driver
.
Lock
()
defer
driver
.
Unlock
()
driver
.
IsRunningReturn
=
false
}()
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionHalt
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
!
ok
{
t
.
Fatal
(
"should have error"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment