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
57fef224
Commit
57fef224
authored
Jun 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: panic if Prepare called twice on build, lock
parent
e851ac5d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
packer/build.go
packer/build.go
+12
-2
packer/build_test.go
packer/build_test.go
+20
-0
No files found.
packer/build.go
View file @
57fef224
package
packer
package
packer
import
"log"
import
(
"log"
"sync"
)
// This is the key in configurations that is set to "true" when Packer
// This is the key in configurations that is set to "true" when Packer
// debugging is enabled.
// debugging is enabled.
...
@@ -48,6 +51,7 @@ type coreBuild struct {
...
@@ -48,6 +51,7 @@ type coreBuild struct {
provisioners
[]
coreBuildProvisioner
provisioners
[]
coreBuildProvisioner
debug
bool
debug
bool
l
sync
.
Mutex
prepareCalled
bool
prepareCalled
bool
}
}
...
@@ -66,7 +70,13 @@ func (b *coreBuild) Name() string {
...
@@ -66,7 +70,13 @@ func (b *coreBuild) Name() string {
// Prepare prepares the build by doing some initialization for the builder
// Prepare prepares the build by doing some initialization for the builder
// and any hooks. This _must_ be called prior to Run.
// and any hooks. This _must_ be called prior to Run.
func
(
b
*
coreBuild
)
Prepare
()
(
err
error
)
{
func
(
b
*
coreBuild
)
Prepare
()
(
err
error
)
{
// TODO: lock
b
.
l
.
Lock
()
defer
b
.
l
.
Unlock
()
if
b
.
prepareCalled
{
panic
(
"prepare already called"
)
}
b
.
prepareCalled
=
true
b
.
prepareCalled
=
true
debugConfig
:=
map
[
string
]
interface
{}{
debugConfig
:=
map
[
string
]
interface
{}{
...
...
packer/build_test.go
View file @
57fef224
...
@@ -49,6 +49,26 @@ func TestBuild_Prepare(t *testing.T) {
...
@@ -49,6 +49,26 @@ func TestBuild_Prepare(t *testing.T) {
assert
.
Equal
(
prov
.
prepConfigs
,
[]
interface
{}{
42
,
debugFalseConfig
},
"prepare should be called with proper config"
)
assert
.
Equal
(
prov
.
prepConfigs
,
[]
interface
{}{
42
,
debugFalseConfig
},
"prepare should be called with proper config"
)
}
}
func
TestBuild_Prepare_Twice
(
t
*
testing
.
T
)
{
build
:=
testBuild
()
if
err
:=
build
.
Prepare
();
err
!=
nil
{
t
.
Fatalf
(
"bad error: %s"
,
err
)
}
defer
func
()
{
p
:=
recover
()
if
p
==
nil
{
t
.
Fatalf
(
"should've paniced"
)
}
if
p
.
(
string
)
!=
"prepare already called"
{
t
.
Fatalf
(
"Invalid panic: %s"
,
p
)
}
}()
build
.
Prepare
()
}
func
TestBuild_Prepare_Debug
(
t
*
testing
.
T
)
{
func
TestBuild_Prepare_Debug
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
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