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
caa2b771
Commit
caa2b771
authored
May 21, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: Builders return valid artifacts
parent
53c3d330
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
+24
-8
packer/rpc/builder.go
packer/rpc/builder.go
+18
-6
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+6
-2
No files found.
packer/rpc/builder.go
View file @
caa2b771
...
...
@@ -46,10 +46,18 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
RegisterHook
(
server
,
hook
)
args
:=
&
BuilderRunArgs
{
serveSingleConn
(
server
)}
b
.
client
.
Call
(
"Builder.Run"
,
args
,
new
(
interface
{}))
// TODO: artifact
return
nil
var
reply
string
if
err
:=
b
.
client
.
Call
(
"Builder.Run"
,
args
,
&
reply
);
err
!=
nil
{
panic
(
err
)
}
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
reply
)
if
err
!=
nil
{
panic
(
err
)
}
return
Artifact
(
client
)
}
func
(
b
*
BuilderServer
)
Prepare
(
args
*
BuilderPrepareArgs
,
reply
*
error
)
error
{
...
...
@@ -61,7 +69,7 @@ func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error {
return
nil
}
func
(
b
*
BuilderServer
)
Run
(
args
*
BuilderRunArgs
,
reply
*
interface
{}
)
error
{
func
(
b
*
BuilderServer
)
Run
(
args
*
BuilderRunArgs
,
reply
*
string
)
error
{
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
args
.
RPCAddress
)
if
err
!=
nil
{
return
err
...
...
@@ -69,8 +77,12 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error {
hook
:=
Hook
(
client
)
ui
:=
&
Ui
{
client
}
b
.
builder
.
Run
(
ui
,
hook
)
artifact
:=
b
.
builder
.
Run
(
ui
,
hook
)
// Wrap the artifact
server
:=
rpc
.
NewServer
()
RegisterArtifact
(
server
,
artifact
)
*
reply
=
nil
*
reply
=
serveSingleConn
(
server
)
return
nil
}
packer/rpc/builder_test.go
View file @
caa2b771
...
...
@@ -7,6 +7,8 @@ import (
"testing"
)
var
testBuilderArtifact
=
&
testArtifact
{}
type
testBuilder
struct
{
prepareCalled
bool
prepareConfig
interface
{}
...
...
@@ -25,7 +27,7 @@ func (b *testBuilder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
b
.
runCalled
=
true
b
.
runHook
=
hook
b
.
runUi
=
ui
return
nil
return
testBuilderArtifact
}
func
TestBuilderRPC
(
t
*
testing
.
T
)
{
...
...
@@ -53,7 +55,7 @@ func TestBuilderRPC(t *testing.T) {
// Test Run
hook
:=
&
testHook
{}
ui
:=
&
testUi
{}
bClient
.
Run
(
ui
,
hook
)
artifact
:=
bClient
.
Run
(
ui
,
hook
)
assert
.
True
(
b
.
runCalled
,
"runs hould be called"
)
if
b
.
runCalled
{
...
...
@@ -63,6 +65,8 @@ func TestBuilderRPC(t *testing.T) {
b
.
runUi
.
Say
(
"format"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
assert
.
Equal
(
ui
.
sayFormat
,
"format"
,
"format should be correct"
)
assert
.
Equal
(
artifact
.
Id
(),
testBuilderArtifact
.
Id
(),
"should have artifact Id"
)
}
}
...
...
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