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
534f3206
Commit
534f3206
authored
May 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Test that hooks are callable from builds
parent
0f57370d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
31 deletions
+56
-31
packer/build.go
packer/build.go
+8
-1
packer/build_test.go
packer/build_test.go
+23
-30
packer/builder_test.go
packer/builder_test.go
+22
-0
packer/hook.go
packer/hook.go
+3
-0
No files found.
packer/build.go
View file @
534f3206
...
@@ -63,6 +63,13 @@ func (b *coreBuild) Run(ui Ui) Artifact {
...
@@ -63,6 +63,13 @@ func (b *coreBuild) Run(ui Ui) Artifact {
panic
(
"Prepare must be called first"
)
panic
(
"Prepare must be called first"
)
}
}
hook
:=
&
DispatchHook
{
b
.
hooks
}
// Copy the hooks
hooks
:=
make
(
map
[
string
][]
Hook
)
for
hookName
,
hookList
:=
range
b
.
hooks
{
hooks
[
hookName
]
=
make
([]
Hook
,
len
(
hookList
))
copy
(
hooks
[
hookName
],
hookList
)
}
hook
:=
&
DispatchHook
{
hooks
}
return
b
.
builder
.
Run
(
ui
,
hook
)
return
b
.
builder
.
Run
(
ui
,
hook
)
}
}
packer/build_test.go
View file @
534f3206
...
@@ -5,32 +5,14 @@ import (
...
@@ -5,32 +5,14 @@ import (
"testing"
"testing"
)
)
type
TestBuilder
struct
{
prepareCalled
bool
prepareConfig
interface
{}
runCalled
bool
runHook
Hook
runUi
Ui
}
func
(
tb
*
TestBuilder
)
Prepare
(
config
interface
{})
error
{
tb
.
prepareCalled
=
true
tb
.
prepareConfig
=
config
return
nil
}
func
(
tb
*
TestBuilder
)
Run
(
ui
Ui
,
h
Hook
)
Artifact
{
tb
.
runCalled
=
true
tb
.
runHook
=
h
tb
.
runUi
=
ui
return
nil
}
func
testBuild
()
Build
{
func
testBuild
()
Build
{
return
&
coreBuild
{
return
&
coreBuild
{
name
:
"test"
,
name
:
"test"
,
builder
:
&
TestBuilder
{},
builder
:
&
TestBuilder
{},
builderConfig
:
42
,
builderConfig
:
42
,
hooks
:
map
[
string
][]
Hook
{
"foo"
:
[]
Hook
{
&
TestHook
{}},
},
provisioners
:
[]
coreBuildProvisioner
{
provisioners
:
[]
coreBuildProvisioner
{
coreBuildProvisioner
{
&
TestProvisioner
{},
42
},
coreBuildProvisioner
{
&
TestProvisioner
{},
42
},
},
},
...
@@ -52,11 +34,21 @@ func TestBuild_Prepare(t *testing.T) {
...
@@ -52,11 +34,21 @@ func TestBuild_Prepare(t *testing.T) {
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
build
:=
testBuild
()
build
:=
testBuild
()
builder
:=
build
.
(
*
coreBuild
)
.
builder
.
(
*
TestBuilder
)
ui
:=
testUi
()
coreB
:=
build
.
(
*
coreBuild
)
builder
:=
coreB
.
builder
.
(
*
TestBuilder
)
build
.
Prepare
(
nil
)
build
.
Prepare
(
ui
)
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
42
,
"prepare config should be 42"
)
assert
.
Equal
(
builder
.
prepareConfig
,
42
,
"prepare config should be 42"
)
// Verify provisioners were prepared
coreProv
:=
coreB
.
provisioners
[
0
]
prov
:=
coreProv
.
provisioner
.
(
*
TestProvisioner
)
assert
.
True
(
prov
.
prepCalled
,
"prepare should be called"
)
assert
.
Equal
(
prov
.
prepConfig
,
42
,
"prepare should be called with proper config"
)
assert
.
Equal
(
prov
.
prepUi
,
ui
,
"prepare should be called with proper ui"
)
}
}
func
TestBuild_Run
(
t
*
testing
.
T
)
{
func
TestBuild_Run
(
t
*
testing
.
T
)
{
...
@@ -70,17 +62,18 @@ func TestBuild_Run(t *testing.T) {
...
@@ -70,17 +62,18 @@ func TestBuild_Run(t *testing.T) {
coreB
:=
build
.
(
*
coreBuild
)
coreB
:=
build
.
(
*
coreBuild
)
// Verify builder was
prepared
// Verify builder was
run
builder
:=
coreB
.
builder
.
(
*
TestBuilder
)
builder
:=
coreB
.
builder
.
(
*
TestBuilder
)
assert
.
True
(
builder
.
runCalled
,
"run should be called"
)
assert
.
True
(
builder
.
runCalled
,
"run should be called"
)
assert
.
Equal
(
builder
.
runUi
,
ui
,
"run should be called with ui"
)
assert
.
Equal
(
builder
.
runUi
,
ui
,
"run should be called with ui"
)
// Verify provisioners were prepared
// Verify hooks are disapatchable
coreProv
:=
coreB
.
provisioners
[
0
]
dispatchHook
:=
builder
.
runHook
prov
:=
coreProv
.
provisioner
.
(
*
TestProvisioner
)
dispatchHook
.
Run
(
"foo"
,
nil
,
nil
,
42
)
assert
.
True
(
prov
.
prepCalled
,
"prepare should be called"
)
assert
.
Equal
(
prov
.
prepConfig
,
42
,
"prepare should be called with proper config"
)
hook
:=
coreB
.
hooks
[
"foo"
][
0
]
.
(
*
TestHook
)
assert
.
Equal
(
prov
.
prepUi
,
ui
,
"prepare should be called with proper ui"
)
assert
.
True
(
hook
.
runCalled
,
"run should be called"
)
assert
.
Equal
(
hook
.
runData
,
42
,
"should have correct data"
)
}
}
func
TestBuild_RunBeforePrepare
(
t
*
testing
.
T
)
{
func
TestBuild_RunBeforePrepare
(
t
*
testing
.
T
)
{
...
...
packer/builder_test.go
0 → 100644
View file @
534f3206
package
packer
type
TestBuilder
struct
{
prepareCalled
bool
prepareConfig
interface
{}
runCalled
bool
runHook
Hook
runUi
Ui
}
func
(
tb
*
TestBuilder
)
Prepare
(
config
interface
{})
error
{
tb
.
prepareCalled
=
true
tb
.
prepareConfig
=
config
return
nil
}
func
(
tb
*
TestBuilder
)
Run
(
ui
Ui
,
h
Hook
)
Artifact
{
tb
.
runCalled
=
true
tb
.
runHook
=
h
tb
.
runUi
=
ui
return
nil
}
packer/hook.go
View file @
534f3206
package
packer
package
packer
// This is the hook that should be fired for provisioners to run.
const
HookProvision
=
"packer_provision"
// A Hook is used to hook into an arbitrarily named location in a build,
// A Hook is used to hook into an arbitrarily named location in a build,
// allowing custom behavior to run at certain points along a build.
// allowing custom behavior to run at certain points along a build.
//
//
...
...
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