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
255b9476
Commit
255b9476
authored
May 04, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: Test BuilderFactory result works. Close back RPC after one
conn
parent
5aebe7b1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
17 deletions
+31
-17
packer/rpc/builder_factory.go
packer/rpc/builder_factory.go
+1
-8
packer/rpc/builder_factory_test.go
packer/rpc/builder_factory_test.go
+8
-2
packer/rpc/server.go
packer/rpc/server.go
+22
-7
No files found.
packer/rpc/builder_factory.go
View file @
255b9476
...
@@ -3,7 +3,6 @@ package rpc
...
@@ -3,7 +3,6 @@ package rpc
import
(
import
(
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"time"
)
)
// An implementation of packer.BuilderFactory where the factory is actually
// An implementation of packer.BuilderFactory where the factory is actually
...
@@ -39,13 +38,7 @@ func (b *BuilderFactoryServer) CreateBuilder(args *BuilderFactoryCreateArgs, rep
...
@@ -39,13 +38,7 @@ func (b *BuilderFactoryServer) CreateBuilder(args *BuilderFactoryCreateArgs, rep
// Now we wrap that back up into a server, and send it on backwards.
// Now we wrap that back up into a server, and send it on backwards.
server
:=
NewServer
()
server
:=
NewServer
()
server
.
RegisterBuilder
(
builder
)
server
.
RegisterBuilder
(
builder
)
server
.
Start
()
server
.
StartSingle
()
// Start a timer where we'll quit the server after some number of seconds.
go
func
()
{
time
.
Sleep
(
30
*
time
.
Second
)
server
.
Stop
()
}()
// Set the reply to the address of the sever
// Set the reply to the address of the sever
*
reply
=
server
.
Address
()
*
reply
=
server
.
Address
()
...
...
packer/rpc/builder_factory_test.go
View file @
255b9476
...
@@ -7,6 +7,8 @@ import (
...
@@ -7,6 +7,8 @@ import (
"testing"
"testing"
)
)
var
createResult
=
&
testBuilder
{}
type
testBuilderFactory
struct
{
type
testBuilderFactory
struct
{
createCalled
bool
createCalled
bool
createName
string
createName
string
...
@@ -15,7 +17,7 @@ type testBuilderFactory struct {
...
@@ -15,7 +17,7 @@ type testBuilderFactory struct {
func
(
b
*
testBuilderFactory
)
CreateBuilder
(
name
string
)
packer
.
Builder
{
func
(
b
*
testBuilderFactory
)
CreateBuilder
(
name
string
)
packer
.
Builder
{
b
.
createCalled
=
true
b
.
createCalled
=
true
b
.
createName
=
name
b
.
createName
=
name
return
&
testBuilder
{}
return
createResult
}
}
func
TestBuilderFactoryRPC
(
t
*
testing
.
T
)
{
func
TestBuilderFactoryRPC
(
t
*
testing
.
T
)
{
...
@@ -37,9 +39,13 @@ func TestBuilderFactoryRPC(t *testing.T) {
...
@@ -37,9 +39,13 @@ func TestBuilderFactoryRPC(t *testing.T) {
// Test Create
// Test Create
name
:=
"foo"
name
:=
"foo"
bClient
:=
&
BuilderFactory
{
client
}
bClient
:=
&
BuilderFactory
{
client
}
_
=
bClient
.
CreateBuilder
(
name
)
builder
:
=
bClient
.
CreateBuilder
(
name
)
assert
.
True
(
b
.
createCalled
,
"create should be called"
)
assert
.
True
(
b
.
createCalled
,
"create should be called"
)
assert
.
Equal
(
b
.
createName
,
"foo"
,
"name should be foo"
)
assert
.
Equal
(
b
.
createName
,
"foo"
,
"name should be foo"
)
builder
.
Prepare
(
42
)
assert
.
True
(
createResult
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
createResult
.
prepareConfig
,
42
,
"42 should be config"
)
}
}
func
TestBuilderFactory_ImplementsBuilderFactory
(
t
*
testing
.
T
)
{
func
TestBuilderFactory_ImplementsBuilderFactory
(
t
*
testing
.
T
)
{
...
...
packer/rpc/server.go
View file @
255b9476
...
@@ -46,6 +46,21 @@ func (s *Server) RegisterUi(ui packer.Ui) {
...
@@ -46,6 +46,21 @@ func (s *Server) RegisterUi(ui packer.Ui) {
}
}
func
(
s
*
Server
)
Start
()
error
{
func
(
s
*
Server
)
Start
()
error
{
return
s
.
start
(
false
)
}
func
(
s
*
Server
)
StartSingle
()
error
{
return
s
.
start
(
true
)
}
func
(
s
*
Server
)
Stop
()
{
if
s
.
listener
!=
nil
{
s
.
listener
.
Close
()
s
.
listener
=
nil
}
}
func
(
s
*
Server
)
start
(
singleConn
bool
)
error
{
if
s
.
listener
!=
nil
{
if
s
.
listener
!=
nil
{
return
errors
.
New
(
"Server already started."
)
return
errors
.
New
(
"Server already started."
)
}
}
...
@@ -66,15 +81,15 @@ func (s *Server) Start() error {
...
@@ -66,15 +81,15 @@ func (s *Server) Start() error {
}
}
go
s
.
server
.
ServeConn
(
conn
)
go
s
.
server
.
ServeConn
(
conn
)
// If we're only accepting a single connection then
// stop.
if
singleConn
{
s
.
Stop
()
break
}
}
}
}(
s
.
listener
)
}(
s
.
listener
)
return
nil
return
nil
}
}
func
(
s
*
Server
)
Stop
()
{
if
s
.
listener
!=
nil
{
s
.
listener
.
Close
()
s
.
listener
=
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