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
441edd25
Commit
441edd25
authored
May 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Changes to build parameters and DispatchHook
parent
25fd2fe8
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
9 deletions
+60
-9
packer/build.go
packer/build.go
+3
-2
packer/build_test.go
packer/build_test.go
+3
-4
packer/builder.go
packer/builder.go
+1
-1
packer/hook.go
packer/hook.go
+20
-0
packer/hook_test.go
packer/hook_test.go
+33
-1
packer/template_test.go
packer/template_test.go
+0
-1
No files found.
packer/build.go
View file @
441edd25
...
...
@@ -7,7 +7,7 @@ import "log"
type
Build
interface
{
Name
()
string
Prepare
()
error
Run
(
ui
Ui
)
Run
(
Ui
)
}
// A build struct represents a single build job, the result of which should
...
...
@@ -46,5 +46,6 @@ func (b *coreBuild) Run(ui Ui) {
panic
(
"Prepare must be called first"
)
}
b
.
builder
.
Run
(
b
,
ui
)
hook
:=
&
DispatchHook
{
b
.
hooks
}
b
.
builder
.
Run
(
ui
,
hook
)
}
packer/build_test.go
View file @
441edd25
...
...
@@ -9,7 +9,7 @@ type TestBuilder struct {
prepareCalled
bool
prepareConfig
interface
{}
runCalled
bool
run
Build
Build
run
Hook
Hook
runUi
Ui
}
...
...
@@ -19,9 +19,9 @@ func (tb *TestBuilder) Prepare(config interface{}) error {
return
nil
}
func
(
tb
*
TestBuilder
)
Run
(
b
Build
,
ui
Ui
)
{
func
(
tb
*
TestBuilder
)
Run
(
ui
Ui
,
h
Hook
)
{
tb
.
runCalled
=
true
tb
.
run
Build
=
b
tb
.
run
Hook
=
h
tb
.
runUi
=
ui
}
...
...
@@ -67,7 +67,6 @@ func TestBuild_Run(t *testing.T) {
builder
:=
build
.
(
*
coreBuild
)
.
builder
.
(
*
TestBuilder
)
assert
.
True
(
builder
.
runCalled
,
"run should be called"
)
assert
.
Equal
(
builder
.
runBuild
,
build
,
"run should be called with build"
)
assert
.
Equal
(
builder
.
runUi
,
ui
,
"run should be called with ui"
)
}
...
...
packer/builder.go
View file @
441edd25
...
...
@@ -11,5 +11,5 @@ package packer
// Run is where the actual build should take place. It takes a Build and a Ui.
type
Builder
interface
{
Prepare
(
config
interface
{})
error
Run
(
build
Build
,
ui
Ui
)
Run
(
ui
Ui
,
hook
Hook
)
}
packer/hook.go
View file @
441edd25
...
...
@@ -11,3 +11,23 @@ package packer
type
Hook
interface
{
Run
(
string
,
interface
{},
Ui
)
}
// A Hook implementation that dispatches based on an internal mapping.
type
DispatchHook
struct
{
Mapping
map
[
string
][]
Hook
}
// Runs the hook with the given name by dispatching it to the proper
// hooks if a mapping exists. If a mapping doesn't exist, then nothing
// happens.
func
(
h
*
DispatchHook
)
Run
(
name
string
,
data
interface
{},
ui
Ui
)
{
hooks
,
ok
:=
h
.
Mapping
[
name
]
if
!
ok
{
// No hooks for that name. No problem.
return
}
for
_
,
hook
:=
range
hooks
{
hook
.
Run
(
name
,
data
,
ui
)
}
}
packer/hook_test.go
View file @
441edd25
package
packer
import
(
"cgl.tideland.biz/asserts"
"testing"
)
type
TestHook
struct
{
runCalled
bool
runData
interface
{}
runName
string
runUi
Ui
}
func
(
t
*
TestHook
)
Run
(
string
,
interface
{},
Ui
)
{
func
(
t
*
TestHook
)
Run
(
name
string
,
data
interface
{},
ui
Ui
)
{
t
.
runCalled
=
true
t
.
runData
=
data
t
.
runName
=
name
t
.
runUi
=
ui
}
func
TestDispatchHook_Run_NoHooks
(
t
*
testing
.
T
)
{
// Just make sure nothing blows up
dh
:=
&
DispatchHook
{
make
(
map
[
string
][]
Hook
)}
dh
.
Run
(
"foo"
,
nil
,
nil
)
}
func
TestDispatchHook_Run
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
hook
:=
&
TestHook
{}
mapping
:=
make
(
map
[
string
][]
Hook
)
mapping
[
"foo"
]
=
[]
Hook
{
hook
}
dh
:=
&
DispatchHook
{
mapping
}
dh
.
Run
(
"foo"
,
42
,
nil
)
assert
.
True
(
hook
.
runCalled
,
"run should be called"
)
assert
.
Equal
(
hook
.
runName
,
"foo"
,
"should be proper event"
)
assert
.
Equal
(
hook
.
runData
,
42
,
"should be correct data"
)
}
packer/template_test.go
View file @
441edd25
...
...
@@ -229,5 +229,4 @@ func TestTemplate_Build(t *testing.T) {
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
expectedConfig
,
"prepare config should be correct"
)
assert
.
True
(
builder
.
runCalled
,
"run should be called"
)
assert
.
Equal
(
builder
.
runBuild
,
build
,
"run should be called with 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