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
812722c2
Commit
812722c2
authored
May 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: ProvisionHook
parent
73b7d949
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
packer/provisioner.go
packer/provisioner.go
+14
-0
packer/provisioner_test.go
packer/provisioner_test.go
+30
-0
No files found.
packer/provisioner.go
View file @
812722c2
...
...
@@ -14,3 +14,17 @@ type Provisioner interface {
// can be done.
Provision
(
Ui
,
Communicator
)
}
// A Hook implementation that runs the given provisioners.
type
ProvisionHook
struct
{
// The provisioners to run as part of the hook. These should already
// be prepared (by calling Prepare) at some earlier stage.
Provisioners
[]
Provisioner
}
// Runs the provisioners in order.
func
(
h
*
ProvisionHook
)
Run
(
name
string
,
ui
Ui
,
comm
Communicator
,
data
interface
{})
{
for
_
,
p
:=
range
h
.
Provisioners
{
p
.
Provision
(
ui
,
comm
)
}
}
packer/provisioner_test.go
View file @
812722c2
package
packer
import
"testing"
type
TestProvisioner
struct
{
prepCalled
bool
prepConfig
interface
{}
...
...
@@ -16,3 +18,31 @@ func (t *TestProvisioner) Prepare(config interface{}, ui Ui) {
func
(
t
*
TestProvisioner
)
Provision
(
Ui
,
Communicator
)
{
t
.
provCalled
=
true
}
func
TestProvisionHook_Impl
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
ProvisionHook
{}
if
_
,
ok
:=
raw
.
(
Hook
);
!
ok
{
t
.
Fatalf
(
"must be a Hook"
)
}
}
func
TestProvisionHook
(
t
*
testing
.
T
)
{
pA
:=
&
TestProvisioner
{}
pB
:=
&
TestProvisioner
{}
ui
:=
testUi
()
var
comm
Communicator
=
nil
var
data
interface
{}
=
nil
hook
:=
&
ProvisionHook
{[]
Provisioner
{
pA
,
pB
}}
hook
.
Run
(
"foo"
,
ui
,
comm
,
data
)
if
!
pA
.
provCalled
{
t
.
Error
(
"provision should be called on pA"
)
}
if
!
pB
.
provCalled
{
t
.
Error
(
"provision should be called on pB"
)
}
}
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