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
eee22b32
Commit
eee22b32
authored
Jun 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Environment can look up post processors
parent
57fef224
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
4 deletions
+81
-4
packer/environment.go
packer/environment.go
+28
-4
packer/environment_test.go
packer/environment_test.go
+42
-0
packer/post_processor_test.go
packer/post_processor_test.go
+11
-0
No files found.
packer/environment.go
View file @
eee22b32
...
@@ -19,6 +19,9 @@ type CommandFunc func(name string) (Command, error)
...
@@ -19,6 +19,9 @@ type CommandFunc func(name string) (Command, error)
// The function type used to lookup Hook implementations.
// The function type used to lookup Hook implementations.
type
HookFunc
func
(
name
string
)
(
Hook
,
error
)
type
HookFunc
func
(
name
string
)
(
Hook
,
error
)
// The function type used to lookup PostProcessor implementations.
type
PostProcessorFunc
func
(
name
string
)
(
PostProcessor
,
error
)
// The function type used to lookup Provisioner implementations.
// The function type used to lookup Provisioner implementations.
type
ProvisionerFunc
func
(
name
string
)
(
Provisioner
,
error
)
type
ProvisionerFunc
func
(
name
string
)
(
Provisioner
,
error
)
...
@@ -29,6 +32,7 @@ type ComponentFinder struct {
...
@@ -29,6 +32,7 @@ type ComponentFinder struct {
Builder
BuilderFunc
Builder
BuilderFunc
Command
CommandFunc
Command
CommandFunc
Hook
HookFunc
Hook
HookFunc
PostProcessor
PostProcessorFunc
Provisioner
ProvisionerFunc
Provisioner
ProvisionerFunc
}
}
...
@@ -42,6 +46,7 @@ type Environment interface {
...
@@ -42,6 +46,7 @@ type Environment interface {
Cache
()
Cache
Cache
()
Cache
Cli
([]
string
)
(
int
,
error
)
Cli
([]
string
)
(
int
,
error
)
Hook
(
string
)
(
Hook
,
error
)
Hook
(
string
)
(
Hook
,
error
)
PostProcessor
(
string
)
(
PostProcessor
,
error
)
Provisioner
(
string
)
(
Provisioner
,
error
)
Provisioner
(
string
)
(
Provisioner
,
error
)
Ui
()
Ui
Ui
()
Ui
}
}
...
@@ -104,6 +109,10 @@ func NewEnvironment(config *EnvironmentConfig) (resultEnv Environment, err error
...
@@ -104,6 +109,10 @@ func NewEnvironment(config *EnvironmentConfig) (resultEnv Environment, err error
env
.
components
.
Hook
=
func
(
string
)
(
Hook
,
error
)
{
return
nil
,
nil
}
env
.
components
.
Hook
=
func
(
string
)
(
Hook
,
error
)
{
return
nil
,
nil
}
}
}
if
env
.
components
.
PostProcessor
==
nil
{
env
.
components
.
PostProcessor
=
func
(
string
)
(
PostProcessor
,
error
)
{
return
nil
,
nil
}
}
if
env
.
components
.
Provisioner
==
nil
{
if
env
.
components
.
Provisioner
==
nil
{
env
.
components
.
Provisioner
=
func
(
string
)
(
Provisioner
,
error
)
{
return
nil
,
nil
}
env
.
components
.
Provisioner
=
func
(
string
)
(
Provisioner
,
error
)
{
return
nil
,
nil
}
}
}
...
@@ -152,6 +161,21 @@ func (e *coreEnvironment) Hook(name string) (h Hook, err error) {
...
@@ -152,6 +161,21 @@ func (e *coreEnvironment) Hook(name string) (h Hook, err error) {
return
return
}
}
// Returns a PostProcessor for the given name that is registered with this
// environment.
func
(
e
*
coreEnvironment
)
PostProcessor
(
name
string
)
(
p
PostProcessor
,
err
error
)
{
p
,
err
=
e
.
components
.
PostProcessor
(
name
)
if
err
!=
nil
{
return
}
if
p
==
nil
{
err
=
fmt
.
Errorf
(
"No post processor found for name: %s"
,
name
)
}
return
}
// Returns a provisioner for the given name that is registered with this
// Returns a provisioner for the given name that is registered with this
// environment.
// environment.
func
(
e
*
coreEnvironment
)
Provisioner
(
name
string
)
(
p
Provisioner
,
err
error
)
{
func
(
e
*
coreEnvironment
)
Provisioner
(
name
string
)
(
p
Provisioner
,
err
error
)
{
...
...
packer/environment_test.go
View file @
eee22b32
...
@@ -67,6 +67,7 @@ func TestEnvironment_NilComponents(t *testing.T) {
...
@@ -67,6 +67,7 @@ func TestEnvironment_NilComponents(t *testing.T) {
env
.
Builder
(
"foo"
)
env
.
Builder
(
"foo"
)
env
.
Cli
([]
string
{
"foo"
})
env
.
Cli
([]
string
{
"foo"
})
env
.
Hook
(
"foo"
)
env
.
Hook
(
"foo"
)
env
.
PostProcessor
(
"foo"
)
env
.
Provisioner
(
"foo"
)
env
.
Provisioner
(
"foo"
)
}
}
...
@@ -246,6 +247,47 @@ func TestEnvironment_Hook_Error(t *testing.T) {
...
@@ -246,6 +247,47 @@ func TestEnvironment_Hook_Error(t *testing.T) {
assert
.
Nil
(
returned
,
"should be no hook"
)
assert
.
Nil
(
returned
,
"should be no hook"
)
}
}
func
TestEnvironment_PostProcessor
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
pp
:=
&
TestPostProcessor
{}
pps
:=
make
(
map
[
string
]
PostProcessor
)
pps
[
"foo"
]
=
pp
config
:=
DefaultEnvironmentConfig
()
config
.
Components
.
PostProcessor
=
func
(
n
string
)
(
PostProcessor
,
error
)
{
return
pps
[
n
],
nil
}
env
,
_
:=
NewEnvironment
(
config
)
returned
,
err
:=
env
.
PostProcessor
(
"foo"
)
assert
.
Nil
(
err
,
"should be no error"
)
assert
.
Equal
(
returned
,
pp
,
"should return correct pp"
)
}
func
TestEnvironment_PostProcessor_NilError
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
config
:=
DefaultEnvironmentConfig
()
config
.
Components
.
PostProcessor
=
func
(
n
string
)
(
PostProcessor
,
error
)
{
return
nil
,
nil
}
env
,
_
:=
NewEnvironment
(
config
)
returned
,
err
:=
env
.
PostProcessor
(
"foo"
)
assert
.
NotNil
(
err
,
"should be an error"
)
assert
.
Nil
(
returned
,
"should be no pp"
)
}
func
TestEnvironment_PostProcessor_Error
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
config
:=
DefaultEnvironmentConfig
()
config
.
Components
.
PostProcessor
=
func
(
n
string
)
(
PostProcessor
,
error
)
{
return
nil
,
errors
.
New
(
"foo"
)
}
env
,
_
:=
NewEnvironment
(
config
)
returned
,
err
:=
env
.
PostProcessor
(
"foo"
)
assert
.
NotNil
(
err
,
"should be an error"
)
assert
.
Equal
(
err
.
Error
(),
"foo"
,
"should be correct error"
)
assert
.
Nil
(
returned
,
"should be no pp"
)
}
func
TestEnvironmentProvisioner
(
t
*
testing
.
T
)
{
func
TestEnvironmentProvisioner
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
...
packer/post_processor_test.go
0 → 100644
View file @
eee22b32
package
packer
type
TestPostProcessor
struct
{}
func
(
*
TestPostProcessor
)
Configure
(
interface
{})
error
{
return
nil
}
func
(
*
TestPostProcessor
)
PostProcess
(
Artifact
)
(
Artifact
,
error
)
{
return
nil
,
nil
}
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