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
86f1fbe9
Commit
86f1fbe9
authored
May 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: Support the new Builder func on Environment
parent
a6aafde0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
1 deletion
+59
-1
packer/environment.go
packer/environment.go
+7
-0
packer/environment_test.go
packer/environment_test.go
+14
-0
packer/rpc/environment.go
packer/rpc/environment.go
+21
-0
packer/rpc/environment_test.go
packer/rpc/environment_test.go
+17
-1
No files found.
packer/environment.go
View file @
86f1fbe9
...
@@ -19,6 +19,7 @@ type CommandFunc func(name string) Command
...
@@ -19,6 +19,7 @@ type CommandFunc func(name string) Command
// It allows for things such as executing CLI commands, getting the
// It allows for things such as executing CLI commands, getting the
// list of available builders, and more.
// list of available builders, and more.
type
Environment
interface
{
type
Environment
interface
{
Builder
(
name
string
)
Builder
Cli
(
args
[]
string
)
int
Cli
(
args
[]
string
)
int
Ui
()
Ui
Ui
()
Ui
}
}
...
@@ -68,6 +69,12 @@ func NewEnvironment(config *EnvironmentConfig) (resultEnv Environment, err error
...
@@ -68,6 +69,12 @@ func NewEnvironment(config *EnvironmentConfig) (resultEnv Environment, err error
return
return
}
}
// Returns a builder of the given name that is registered with this
// environment.
func
(
e
*
coreEnvironment
)
Builder
(
name
string
)
Builder
{
return
e
.
builderFunc
(
name
)
}
// Executes a command as if it was typed on the command-line interface.
// Executes a command as if it was typed on the command-line interface.
// The return value is the exit code of the command.
// The return value is the exit code of the command.
func
(
e
*
coreEnvironment
)
Cli
(
args
[]
string
)
int
{
func
(
e
*
coreEnvironment
)
Cli
(
args
[]
string
)
int
{
...
...
packer/environment_test.go
View file @
86f1fbe9
...
@@ -50,6 +50,20 @@ func TestNewEnvironment_NoConfig(t *testing.T) {
...
@@ -50,6 +50,20 @@ func TestNewEnvironment_NoConfig(t *testing.T) {
assert
.
NotNil
(
err
,
"should be an error"
)
assert
.
NotNil
(
err
,
"should be an error"
)
}
}
func
TestEnvironment_Builder
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
builder
:=
&
TestBuilder
{}
builders
:=
make
(
map
[
string
]
Builder
)
builders
[
"foo"
]
=
builder
config
:=
DefaultEnvironmentConfig
()
config
.
BuilderFunc
=
func
(
n
string
)
Builder
{
return
builders
[
n
]
}
env
,
_
:=
NewEnvironment
(
config
)
assert
.
Equal
(
env
.
Builder
(
"foo"
),
builder
,
"should return correct builder"
)
}
func
TestEnvironment_Cli_CallsRun
(
t
*
testing
.
T
)
{
func
TestEnvironment_Cli_CallsRun
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
...
packer/rpc/environment.go
View file @
86f1fbe9
...
@@ -21,6 +21,15 @@ type EnvironmentCliArgs struct {
...
@@ -21,6 +21,15 @@ type EnvironmentCliArgs struct {
Args
[]
string
Args
[]
string
}
}
func
(
e
*
Environment
)
Builder
(
name
string
)
packer
.
Builder
{
var
reply
string
e
.
client
.
Call
(
"Environment.Builder"
,
name
,
&
reply
)
// TODO: error handling
client
,
_
:=
rpc
.
Dial
(
"tcp"
,
reply
)
return
&
Builder
{
client
}
}
func
(
e
*
Environment
)
Cli
(
args
[]
string
)
(
result
int
)
{
func
(
e
*
Environment
)
Cli
(
args
[]
string
)
(
result
int
)
{
rpcArgs
:=
&
EnvironmentCliArgs
{
args
}
rpcArgs
:=
&
EnvironmentCliArgs
{
args
}
e
.
client
.
Call
(
"Environment.Cli"
,
rpcArgs
,
&
result
)
e
.
client
.
Call
(
"Environment.Cli"
,
rpcArgs
,
&
result
)
...
@@ -36,6 +45,18 @@ func (e *Environment) Ui() packer.Ui {
...
@@ -36,6 +45,18 @@ func (e *Environment) Ui() packer.Ui {
return
&
Ui
{
client
}
return
&
Ui
{
client
}
}
}
func
(
e
*
EnvironmentServer
)
Builder
(
name
*
string
,
reply
*
string
)
error
{
builder
:=
e
.
env
.
Builder
(
*
name
)
// Wrap it
server
:=
NewServer
()
server
.
RegisterBuilder
(
builder
)
server
.
StartSingle
()
*
reply
=
server
.
Address
()
return
nil
}
func
(
e
*
EnvironmentServer
)
Cli
(
args
*
EnvironmentCliArgs
,
reply
*
int
)
error
{
func
(
e
*
EnvironmentServer
)
Cli
(
args
*
EnvironmentCliArgs
,
reply
*
int
)
error
{
*
reply
=
e
.
env
.
Cli
(
args
.
Args
)
*
reply
=
e
.
env
.
Cli
(
args
.
Args
)
return
nil
return
nil
...
...
packer/rpc/environment_test.go
View file @
86f1fbe9
...
@@ -7,15 +7,23 @@ import (
...
@@ -7,15 +7,23 @@ import (
"testing"
"testing"
)
)
var
testEnvBuilder
=
&
testBuilder
{}
var
testEnvUi
=
&
testUi
{}
var
testEnvUi
=
&
testUi
{}
type
testEnvironment
struct
{
type
testEnvironment
struct
{
bfCalled
bool
builderCalled
bool
builderName
string
cliCalled
bool
cliCalled
bool
cliArgs
[]
string
cliArgs
[]
string
uiCalled
bool
uiCalled
bool
}
}
func
(
e
*
testEnvironment
)
Builder
(
name
string
)
packer
.
Builder
{
e
.
builderCalled
=
true
e
.
builderName
=
name
return
testEnvBuilder
}
func
(
e
*
testEnvironment
)
Cli
(
args
[]
string
)
int
{
func
(
e
*
testEnvironment
)
Cli
(
args
[]
string
)
int
{
e
.
cliCalled
=
true
e
.
cliCalled
=
true
e
.
cliArgs
=
args
e
.
cliArgs
=
args
...
@@ -44,6 +52,14 @@ func TestEnvironmentRPC(t *testing.T) {
...
@@ -44,6 +52,14 @@ func TestEnvironmentRPC(t *testing.T) {
assert
.
Nil
(
err
,
"should be able to connect"
)
assert
.
Nil
(
err
,
"should be able to connect"
)
eClient
:=
&
Environment
{
client
}
eClient
:=
&
Environment
{
client
}
// Test Builder
builder
:=
eClient
.
Builder
(
"foo"
)
assert
.
True
(
e
.
builderCalled
,
"Builder should be called"
)
assert
.
Equal
(
e
.
builderName
,
"foo"
,
"Correct name for Builder"
)
builder
.
Prepare
(
nil
)
assert
.
True
(
testEnvBuilder
.
prepareCalled
,
"Prepare should be called"
)
// Test Cli
// Test Cli
cliArgs
:=
[]
string
{
"foo"
,
"bar"
}
cliArgs
:=
[]
string
{
"foo"
,
"bar"
}
result
:=
eClient
.
Cli
(
cliArgs
)
result
:=
eClient
.
Cli
(
cliArgs
)
...
...
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