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
7475ee83
Commit
7475ee83
authored
May 12, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Add Communicator to Hook arguments
parent
7fdb53f5
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
17 additions
and
14 deletions
+17
-14
packer/hook.go
packer/hook.go
+3
-3
packer/hook_test.go
packer/hook_test.go
+5
-3
packer/plugin/hook.go
packer/plugin/hook.go
+2
-2
packer/plugin/hook_test.go
packer/plugin/hook_test.go
+1
-1
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+1
-1
packer/rpc/hook.go
packer/rpc/hook.go
+3
-2
packer/rpc/hook_test.go
packer/rpc/hook_test.go
+2
-2
No files found.
packer/hook.go
View file @
7475ee83
...
...
@@ -9,7 +9,7 @@ package packer
// in. In addition to that, the Hook is given access to a UI so that it can
// output things to the user.
type
Hook
interface
{
Run
(
string
,
interface
{},
Ui
)
Run
(
string
,
Ui
,
Communicator
,
interface
{}
)
}
// A Hook implementation that dispatches based on an internal mapping.
...
...
@@ -20,7 +20,7 @@ type DispatchHook struct {
// 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
)
{
func
(
h
*
DispatchHook
)
Run
(
name
string
,
ui
Ui
,
comm
Communicator
,
data
interface
{}
)
{
hooks
,
ok
:=
h
.
Mapping
[
name
]
if
!
ok
{
// No hooks for that name. No problem.
...
...
@@ -28,6 +28,6 @@ func (h *DispatchHook) Run(name string, data interface{}, ui Ui) {
}
for
_
,
hook
:=
range
hooks
{
hook
.
Run
(
name
,
data
,
ui
)
hook
.
Run
(
name
,
ui
,
comm
,
data
)
}
}
packer/hook_test.go
View file @
7475ee83
...
...
@@ -7,13 +7,15 @@ import (
type
TestHook
struct
{
runCalled
bool
runComm
Communicator
runData
interface
{}
runName
string
runUi
Ui
}
func
(
t
*
TestHook
)
Run
(
name
string
,
data
interface
{},
ui
Ui
)
{
func
(
t
*
TestHook
)
Run
(
name
string
,
ui
Ui
,
comm
Communicator
,
data
interface
{}
)
{
t
.
runCalled
=
true
t
.
runComm
=
comm
t
.
runData
=
data
t
.
runName
=
name
t
.
runUi
=
ui
...
...
@@ -31,7 +33,7 @@ func TestDispatchHook_Implements(t *testing.T) {
func
TestDispatchHook_Run_NoHooks
(
t
*
testing
.
T
)
{
// Just make sure nothing blows up
dh
:=
&
DispatchHook
{
make
(
map
[
string
][]
Hook
)}
dh
.
Run
(
"foo"
,
nil
,
nil
)
dh
.
Run
(
"foo"
,
nil
,
nil
,
nil
)
}
func
TestDispatchHook_Run
(
t
*
testing
.
T
)
{
...
...
@@ -42,7 +44,7 @@ func TestDispatchHook_Run(t *testing.T) {
mapping
:=
make
(
map
[
string
][]
Hook
)
mapping
[
"foo"
]
=
[]
Hook
{
hook
}
dh
:=
&
DispatchHook
{
mapping
}
dh
.
Run
(
"foo"
,
42
,
nil
)
dh
.
Run
(
"foo"
,
nil
,
nil
,
42
)
assert
.
True
(
hook
.
runCalled
,
"run should be called"
)
assert
.
Equal
(
hook
.
runName
,
"foo"
,
"should be proper event"
)
...
...
packer/plugin/hook.go
View file @
7475ee83
...
...
@@ -13,13 +13,13 @@ type cmdHook struct {
client
*
client
}
func
(
c
*
cmdHook
)
Run
(
name
string
,
data
interface
{},
ui
packer
.
Ui
)
{
func
(
c
*
cmdHook
)
Run
(
name
string
,
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
data
interface
{}
)
{
defer
func
()
{
r
:=
recover
()
c
.
checkExit
(
r
,
nil
)
}()
c
.
hook
.
Run
(
name
,
data
,
ui
)
c
.
hook
.
Run
(
name
,
ui
,
comm
,
data
)
}
func
(
c
*
cmdHook
)
checkExit
(
p
interface
{},
cb
func
())
{
...
...
packer/plugin/hook_test.go
View file @
7475ee83
...
...
@@ -9,7 +9,7 @@ import (
type
helperHook
byte
func
(
helperHook
)
Run
(
string
,
interface
{},
packer
.
Ui
)
{}
func
(
helperHook
)
Run
(
string
,
packer
.
Ui
,
packer
.
Communicator
,
interface
{}
)
{}
func
TestHook_NoExist
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
...
packer/rpc/builder_test.go
View file @
7475ee83
...
...
@@ -56,7 +56,7 @@ func TestBuilderRPC(t *testing.T) {
assert
.
True
(
b
.
runCalled
,
"runs hould be called"
)
if
b
.
runCalled
{
b
.
runHook
.
Run
(
"foo"
,
nil
,
nil
)
b
.
runHook
.
Run
(
"foo"
,
nil
,
nil
,
nil
)
assert
.
True
(
hook
.
runCalled
,
"run should be called"
)
b
.
runUi
.
Say
(
"format"
)
...
...
packer/rpc/hook.go
View file @
7475ee83
...
...
@@ -27,8 +27,9 @@ func Hook(client *rpc.Client) *hook {
return
&
hook
{
client
}
}
func
(
h
*
hook
)
Run
(
name
string
,
data
interface
{},
ui
packer
.
Ui
)
{
func
(
h
*
hook
)
Run
(
name
string
,
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
data
interface
{}
)
{
server
:=
rpc
.
NewServer
()
RegisterCommunicator
(
server
,
comm
)
RegisterUi
(
server
,
ui
)
address
:=
serveSingleConn
(
server
)
...
...
@@ -43,7 +44,7 @@ func (h *HookServer) Run(args *HookRunArgs, reply *interface{}) error {
return
err
}
h
.
hook
.
Run
(
args
.
Name
,
args
.
Data
,
&
Ui
{
client
}
)
h
.
hook
.
Run
(
args
.
Name
,
&
Ui
{
client
},
Communicator
(
client
),
args
.
Data
)
*
reply
=
nil
return
nil
...
...
packer/rpc/hook_test.go
View file @
7475ee83
...
...
@@ -12,7 +12,7 @@ type testHook struct {
runUi
packer
.
Ui
}
func
(
h
*
testHook
)
Run
(
name
string
,
data
interface
{},
ui
packer
.
Ui
)
{
func
(
h
*
testHook
)
Run
(
name
string
,
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
data
interface
{}
)
{
h
.
runCalled
=
true
}
...
...
@@ -35,7 +35,7 @@ func TestHookRPC(t *testing.T) {
// Test Run
ui
:=
&
testUi
{}
hClient
.
Run
(
"foo"
,
42
,
ui
)
hClient
.
Run
(
"foo"
,
ui
,
nil
,
42
)
assert
.
True
(
h
.
runCalled
,
"run should be called"
)
}
...
...
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