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
8f08c5d8
Commit
8f08c5d8
authored
Apr 20, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require Prepare to be called on Build
parent
f579ff05
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
packer/build.go
packer/build.go
+7
-0
packer/build_test.go
packer/build_test.go
+13
-0
No files found.
packer/build.go
View file @
8f08c5d8
...
@@ -7,6 +7,8 @@ package packer
...
@@ -7,6 +7,8 @@ package packer
type
Build
struct
{
type
Build
struct
{
name
string
name
string
builder
Builder
builder
Builder
prepareCalled
bool
}
}
// Implementers of Builder are responsible for actually building images
// Implementers of Builder are responsible for actually building images
...
@@ -42,10 +44,15 @@ func (NilBuilderFactory) CreateBuilder(name string) Builder {
...
@@ -42,10 +44,15 @@ func (NilBuilderFactory) CreateBuilder(name string) Builder {
// 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
*
Build
)
Prepare
(
config
interface
{})
{
func
(
b
*
Build
)
Prepare
(
config
interface
{})
{
b
.
prepareCalled
=
true
b
.
builder
.
Prepare
(
config
)
b
.
builder
.
Prepare
(
config
)
}
}
// Runs the actual build. Prepare must be called prior to running this.
// Runs the actual build. Prepare must be called prior to running this.
func
(
b
*
Build
)
Run
(
ui
Ui
)
{
func
(
b
*
Build
)
Run
(
ui
Ui
)
{
if
!
b
.
prepareCalled
{
panic
(
"Prepare must be called first"
)
}
b
.
builder
.
Run
(
b
,
ui
)
b
.
builder
.
Run
(
b
,
ui
)
}
}
packer/build_test.go
View file @
8f08c5d8
...
@@ -49,6 +49,7 @@ func TestBuild_Run(t *testing.T) {
...
@@ -49,6 +49,7 @@ func TestBuild_Run(t *testing.T) {
ui
:=
testUi
()
ui
:=
testUi
()
build
:=
testBuild
()
build
:=
testBuild
()
build
.
Prepare
(
nil
)
build
.
Run
(
ui
)
build
.
Run
(
ui
)
builder
:=
build
.
builder
.
(
*
TestBuilder
)
builder
:=
build
.
builder
.
(
*
TestBuilder
)
...
@@ -57,3 +58,15 @@ func TestBuild_Run(t *testing.T) {
...
@@ -57,3 +58,15 @@ func TestBuild_Run(t *testing.T) {
assert
.
Equal
(
builder
.
runBuild
,
build
,
"run should be called with build"
)
assert
.
Equal
(
builder
.
runBuild
,
build
,
"run should be called with build"
)
assert
.
Equal
(
builder
.
runUi
,
ui
,
"run should be called with ui"
)
assert
.
Equal
(
builder
.
runUi
,
ui
,
"run should be called with ui"
)
}
}
func
TestBuild_RunBeforePrepare
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defer
func
()
{
p
:=
recover
()
assert
.
NotNil
(
p
,
"should panic"
)
assert
.
Equal
(
p
.
(
string
),
"Prepare must be called first"
,
"right panic"
)
}()
testBuild
()
.
Run
(
testUi
())
}
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