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
da683afd
Commit
da683afd
authored
Nov 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: config validation test
parent
23ad5442
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
0 deletions
+102
-0
builder/docker/builder.go
builder/docker/builder.go
+6
-0
builder/docker/config.go
builder/docker/config.go
+29
-0
builder/docker/config_test.go
builder/docker/config_test.go
+67
-0
No files found.
builder/docker/builder.go
View file @
da683afd
...
...
@@ -25,9 +25,15 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return
nil
,
err
}
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
warnings
:=
make
([]
string
,
0
)
// Validate the configuration
cwarns
,
cerrs
:=
b
.
config
.
Prepare
()
errs
=
packer
.
MultiErrorAppend
(
errs
,
cerrs
...
)
warnings
=
append
(
warnings
,
cwarns
...
)
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
warnings
,
errs
}
...
...
builder/docker/config.go
View file @
da683afd
package
docker
import
(
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
)
...
...
@@ -13,3 +14,31 @@ type Config struct {
tpl
*
packer
.
ConfigTemplate
}
func
(
c
*
Config
)
Prepare
()
([]
string
,
[]
error
)
{
errs
:=
make
([]
error
,
0
)
templates
:=
map
[
string
]
*
string
{
"export_path"
:
&
c
.
ExportPath
,
"image"
:
&
c
.
Image
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
c
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
c
.
ExportPath
==
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"export_path must be specified"
))
}
if
c
.
Image
==
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"image must be specified"
))
}
return
nil
,
errs
}
builder/docker/config_test.go
0 → 100644
View file @
da683afd
package
docker
import
(
"github.com/mitchellh/packer/packer"
"testing"
)
func
testConfigStruct
(
t
*
testing
.
T
)
*
Config
{
tpl
,
err
:=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
return
&
Config
{
ExportPath
:
"foo"
,
Image
:
"bar"
,
tpl
:
tpl
,
}
}
func
TestConfigPrepare_exportPath
(
t
*
testing
.
T
)
{
c
:=
testConfigStruct
(
t
)
// No export path
c
.
ExportPath
=
""
warns
,
errs
:=
c
.
Prepare
()
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
len
(
errs
)
<=
0
{
t
.
Fatalf
(
"bad: %#v"
,
errs
)
}
// Good export path
c
.
ExportPath
=
"path"
warns
,
errs
=
c
.
Prepare
()
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
errs
)
}
}
func
TestConfigPrepare_image
(
t
*
testing
.
T
)
{
c
:=
testConfigStruct
(
t
)
// No image
c
.
Image
=
""
warns
,
errs
:=
c
.
Prepare
()
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
len
(
errs
)
<=
0
{
t
.
Fatalf
(
"bad: %#v"
,
errs
)
}
// Good image
c
.
Image
=
"path"
warns
,
errs
=
c
.
Prepare
()
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
errs
)
}
}
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