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
1a5c9d30
Commit
1a5c9d30
authored
Jun 06, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: Better config validation, testing
parent
275dc6d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
3 deletions
+92
-3
builder/vmware/builder.go
builder/vmware/builder.go
+9
-3
builder/vmware/builder_test.go
builder/vmware/builder_test.go
+83
-0
No files found.
builder/vmware/builder.go
View file @
1a5c9d30
package
vmware
import
(
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
...
...
@@ -50,10 +51,11 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
b
.
config
.
OutputDir
=
"vmware"
}
errors
:=
make
([]
error
,
0
)
if
b
.
config
.
RawBootWait
!=
""
{
b
.
config
.
BootWait
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawBootWait
)
if
err
!=
nil
{
return
errors
=
append
(
errors
,
fmt
.
Errorf
(
"Failed parsing boot_wait: %s"
,
err
))
}
}
...
...
@@ -63,12 +65,16 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
b
.
config
.
SSHWaitTimeout
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawSSHWaitTimeout
)
if
err
!=
nil
{
return
errors
=
append
(
errors
,
fmt
.
Errorf
(
"Failed parsing ssh_wait_timeout: %s"
,
err
))
}
b
.
driver
,
err
=
b
.
newDriver
()
if
err
!=
nil
{
return
errors
=
append
(
errors
,
fmt
.
Errorf
(
"Failed creating VMware driver: %s"
,
err
))
}
if
len
(
errors
)
>
0
{
return
&
packer
.
MultiError
{
errors
}
}
return
nil
...
...
builder/vmware/builder_test.go
0 → 100644
View file @
1a5c9d30
package
vmware
import
(
"github.com/mitchellh/packer/packer"
"testing"
"time"
)
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
}
}
func
TestBuilder_ImplementsBuilder
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
Builder
{}
if
_
,
ok
:=
raw
.
(
packer
.
Builder
);
!
ok
{
t
.
Error
(
"Builder must implement builder."
)
}
}
func
TestBuilderPrepare_BootWait
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test with a bad boot_wait
config
[
"boot_wait"
]
=
"this is not good"
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test with a good one
config
[
"boot_wait"
]
=
"5s"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_Defaults
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
DiskName
!=
"disk"
{
t
.
Errorf
(
"bad disk name: %s"
,
b
.
config
.
DiskName
)
}
if
b
.
config
.
OutputDir
!=
"vmware"
{
t
.
Errorf
(
"bad output dir: %s"
,
b
.
config
.
OutputDir
)
}
if
b
.
config
.
SSHWaitTimeout
!=
(
20
*
time
.
Minute
)
{
t
.
Errorf
(
"bad wait timeout: %s"
,
b
.
config
.
SSHWaitTimeout
)
}
if
b
.
config
.
VMName
!=
"packer"
{
t
.
Errorf
(
"bad vm name: %s"
,
b
.
config
.
VMName
)
}
}
func
TestBuilderPrepare_SSHWaitTimeout
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test with a bad value
config
[
"ssh_wait_timeout"
]
=
"this is not good"
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test with a good one
config
[
"ssh_wait_timeout"
]
=
"5s"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
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