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
e69e74b2
Commit
e69e74b2
authored
May 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Panic if provisioners and no provisioner function
parent
3d0dde03
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
packer/template.go
packer/template.go
+4
-0
packer/template_test.go
packer/template_test.go
+63
-0
No files found.
packer/template.go
View file @
e69e74b2
...
...
@@ -162,6 +162,10 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
panic
(
"no builder function"
)
}
if
len
(
t
.
Provisioners
)
>
0
&&
components
.
Provisioner
==
nil
{
panic
(
"no provisioner function"
)
}
builder
,
err
:=
components
.
Builder
(
builderConfig
.
builderType
)
if
err
!=
nil
{
return
...
...
packer/template_test.go
View file @
e69e74b2
...
...
@@ -327,6 +327,69 @@ func TestTemplate_Build_NilBuilderFunc(t *testing.T) {
template
.
Build
(
"test1"
,
&
ComponentFinder
{})
}
func
TestTemplate_Build_NilProvisionerFunc
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
data
:=
`
{
"name": "my-image",
"builders": [
{
"name": "test1",
"type": "test-builder"
}
],
"provisioners": [
{
"type": "test-prov"
}
]
}
`
template
,
err
:=
ParseTemplate
([]
byte
(
data
))
assert
.
Nil
(
err
,
"should not error"
)
defer
func
()
{
p
:=
recover
()
assert
.
NotNil
(
p
,
"should panic"
)
if
p
!=
nil
{
assert
.
Equal
(
p
.
(
string
),
"no provisioner function"
,
"right panic"
)
}
}()
template
.
Build
(
"test1"
,
&
ComponentFinder
{
Builder
:
func
(
string
)
(
Builder
,
error
)
{
return
nil
,
nil
},
})
}
func
TestTemplate_Build_NilProvisionerFunc_WithNoProvisioners
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
data
:=
`
{
"name": "my-image",
"builders": [
{
"name": "test1",
"type": "test-builder"
}
],
"provisioners": []
}
`
template
,
err
:=
ParseTemplate
([]
byte
(
data
))
assert
.
Nil
(
err
,
"should not error"
)
template
.
Build
(
"test1"
,
&
ComponentFinder
{
Builder
:
func
(
string
)
(
Builder
,
error
)
{
return
nil
,
nil
},
})
}
func
TestTemplate_Build
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
...
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