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
ac83cf65
Commit
ac83cf65
authored
May 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: Setup the Environment properly for Command
parent
adb533fd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
packer/rpc/command.go
packer/rpc/command.go
+14
-4
packer/rpc/command_test.go
packer/rpc/command_test.go
+11
-2
No files found.
packer/rpc/command.go
View file @
ac83cf65
...
...
@@ -18,7 +18,7 @@ type ServerCommand struct {
}
type
CommandRunArgs
struct
{
Env
packer
.
Environment
RPCAddress
string
Args
[]
string
}
...
...
@@ -29,8 +29,11 @@ func Command(client *rpc.Client) *ClientCommand {
}
func
(
c
*
ClientCommand
)
Run
(
env
packer
.
Environment
,
args
[]
string
)
(
result
int
)
{
// TODO: Environment
rpcArgs
:=
&
CommandRunArgs
{
nil
,
args
}
// Create and start the server for the Environment
server
:=
rpc
.
NewServer
()
RegisterEnvironment
(
server
,
env
)
rpcArgs
:=
&
CommandRunArgs
{
serveSingleConn
(
server
),
args
}
err
:=
c
.
client
.
Call
(
"Command.Run"
,
rpcArgs
,
&
result
)
if
err
!=
nil
{
panic
(
err
)
...
...
@@ -49,7 +52,14 @@ func (c *ClientCommand) Synopsis() (result string) {
}
func
(
c
*
ServerCommand
)
Run
(
args
*
CommandRunArgs
,
reply
*
int
)
error
{
*
reply
=
c
.
command
.
Run
(
args
.
Env
,
args
.
Args
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
args
.
RPCAddress
)
if
err
!=
nil
{
return
err
}
env
:=
&
Environment
{
client
}
*
reply
=
c
.
command
.
Run
(
env
,
args
.
Args
)
return
nil
}
...
...
packer/rpc/command_test.go
View file @
ac83cf65
...
...
@@ -85,12 +85,21 @@ func TestRPCCommand(t *testing.T) {
}
clientComm
:=
&
ClientCommand
{
client
}
// Test run
runArgs
:=
[]
string
{
"foo"
,
"bar"
}
testEnv
:=
&
testEnvironment
{}
exitCode
:=
clientComm
.
Run
(
testEnv
,
runArgs
)
synopsis
:=
clientComm
.
Synopsis
()
assert
.
Equal
(
command
.
runArgs
,
runArgs
,
"Correct args should be sent"
)
assert
.
Equal
(
exitCode
,
0
,
"Exit code should be correct"
)
assert
.
NotNil
(
command
.
runEnv
,
"should have an env"
)
if
command
.
runEnv
!=
nil
{
command
.
runEnv
.
Ui
()
assert
.
True
(
testEnv
.
uiCalled
,
"UI should be called on env"
)
}
// Test Synopsis
synopsis
:=
clientComm
.
Synopsis
()
assert
.
Equal
(
synopsis
,
"foo"
,
"Synopsis should be correct"
)
}
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