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
4223e5bc
Commit
4223e5bc
authored
Jun 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazonebs: Additional validation
parent
6a23cb72
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
3 deletions
+87
-3
builder/amazonebs/builder.go
builder/amazonebs/builder.go
+12
-3
builder/amazonebs/builder_test.go
builder/amazonebs/builder_test.go
+75
-0
No files found.
builder/amazonebs/builder.go
View file @
4223e5bc
...
@@ -60,15 +60,24 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
...
@@ -60,15 +60,24 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
errs
=
append
(
errs
,
errors
.
New
(
"A secret_key must be specified"
))
errs
=
append
(
errs
,
errors
.
New
(
"A secret_key must be specified"
))
}
}
if
b
.
config
.
SourceAmi
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"A source_ami must be specified"
))
}
if
b
.
config
.
InstanceType
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An instance_type must be specified"
))
}
if
b
.
config
.
SSHUsername
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An ssh_username must be specified"
))
}
if
len
(
errs
)
>
0
{
if
len
(
errs
)
>
0
{
return
&
packer
.
MultiError
{
errs
}
return
&
packer
.
MultiError
{
errs
}
}
}
// TODO: config validation and asking for fields:
// TODO: config validation and asking for fields:
// * region (exists and valid)
// * region (exists and valid)
// * source ami
// * instance type
// * SSH username
log
.
Printf
(
"Config: %+v"
,
b
.
config
)
log
.
Printf
(
"Config: %+v"
,
b
.
config
)
return
return
...
...
builder/amazonebs/builder_test.go
View file @
4223e5bc
...
@@ -9,6 +9,9 @@ func testConfig() map[string]interface{} {
...
@@ -9,6 +9,9 @@ func testConfig() map[string]interface{} {
return
map
[
string
]
interface
{}{
return
map
[
string
]
interface
{}{
"access_key"
:
"foo"
,
"access_key"
:
"foo"
,
"secret_key"
:
"bar"
,
"secret_key"
:
"bar"
,
"source_ami"
:
"foo"
,
"instance_type"
:
"foo"
,
"ssh_username"
:
"root"
,
}
}
}
}
...
@@ -56,6 +59,30 @@ func TestBuilderPrepare_AccessKey(t *testing.T) {
...
@@ -56,6 +59,30 @@ func TestBuilderPrepare_AccessKey(t *testing.T) {
}
}
}
}
func
TestBuilderPrepare_InstanceType
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test good
config
[
"instance_type"
]
=
"foo"
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
InstanceType
!=
"foo"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
InstanceType
)
}
// Test bad
delete
(
config
,
"instance_type"
)
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestBuilderPrepare_SecretKey
(
t
*
testing
.
T
)
{
func
TestBuilderPrepare_SecretKey
(
t
*
testing
.
T
)
{
var
b
Builder
var
b
Builder
config
:=
testConfig
()
config
:=
testConfig
()
...
@@ -80,6 +107,30 @@ func TestBuilderPrepare_SecretKey(t *testing.T) {
...
@@ -80,6 +107,30 @@ func TestBuilderPrepare_SecretKey(t *testing.T) {
}
}
}
}
func
TestBuilderPrepare_SourceAmi
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test good
config
[
"source_ami"
]
=
"foo"
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
SourceAmi
!=
"foo"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
SourceAmi
)
}
// Test bad
delete
(
config
,
"source_ami"
)
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestBuilderPrepare_SSHPort
(
t
*
testing
.
T
)
{
func
TestBuilderPrepare_SSHPort
(
t
*
testing
.
T
)
{
var
b
Builder
var
b
Builder
config
:=
testConfig
()
config
:=
testConfig
()
...
@@ -106,3 +157,27 @@ func TestBuilderPrepare_SSHPort(t *testing.T) {
...
@@ -106,3 +157,27 @@ func TestBuilderPrepare_SSHPort(t *testing.T) {
t
.
Errorf
(
"invalid: %d"
,
b
.
config
.
SSHPort
)
t
.
Errorf
(
"invalid: %d"
,
b
.
config
.
SSHPort
)
}
}
}
}
func
TestBuilderPrepare_SSHUsername
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test good
config
[
"ssh_username"
]
=
"foo"
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
SSHUsername
!=
"foo"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
SSHUsername
)
}
// Test bad
delete
(
config
,
"ssh_username"
)
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
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