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
a6aafde0
Commit
a6aafde0
authored
May 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: tests green from new BuilderFactory changes
parent
14c568a9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
0 additions
and
143 deletions
+0
-143
packer/rpc/builder_factory.go
packer/rpc/builder_factory.go
+0
-46
packer/rpc/builder_factory_test.go
packer/rpc/builder_factory_test.go
+0
-58
packer/rpc/environment.go
packer/rpc/environment.go
+0
-21
packer/rpc/environment_test.go
packer/rpc/environment_test.go
+0
-14
packer/rpc/server.go
packer/rpc/server.go
+0
-4
No files found.
packer/rpc/builder_factory.go
deleted
100644 → 0
View file @
14c568a9
package
rpc
import
(
"github.com/mitchellh/packer/packer"
"net/rpc"
)
// An implementation of packer.BuilderFactory where the factory is actually
// executed over an RPC connection.
type
BuilderFactory
struct
{
client
*
rpc
.
Client
}
// BuilderFactoryServer wraps a packer.BuilderFactory and makes it exportable
// as part of a Golang RPC server.
type
BuilderFactoryServer
struct
{
bf
packer
.
BuilderFactory
}
type
BuilderFactoryCreateArgs
struct
{
Name
string
}
func
(
b
*
BuilderFactory
)
CreateBuilder
(
name
string
)
packer
.
Builder
{
var
reply
string
b
.
client
.
Call
(
"BuilderFactory.CreateBuilder"
,
&
BuilderFactoryCreateArgs
{
name
},
&
reply
)
// TODO: error handling
client
,
_
:=
rpc
.
Dial
(
"tcp"
,
reply
)
return
&
Builder
{
client
}
}
func
(
b
*
BuilderFactoryServer
)
CreateBuilder
(
args
*
BuilderFactoryCreateArgs
,
reply
*
string
)
error
{
// Get the actual builder response
builder
:=
b
.
bf
.
CreateBuilder
(
args
.
Name
)
// Now we wrap that back up into a server, and send it on backwards.
server
:=
NewServer
()
server
.
RegisterBuilder
(
builder
)
server
.
StartSingle
()
// Set the reply to the address of the sever
*
reply
=
server
.
Address
()
return
nil
}
packer/rpc/builder_factory_test.go
deleted
100644 → 0
View file @
14c568a9
package
rpc
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"testing"
)
var
createResult
=
&
testBuilder
{}
type
testBuilderFactory
struct
{
createCalled
bool
createName
string
}
func
(
b
*
testBuilderFactory
)
CreateBuilder
(
name
string
)
packer
.
Builder
{
b
.
createCalled
=
true
b
.
createName
=
name
return
createResult
}
func
TestBuilderFactoryRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
b
:=
new
(
testBuilderFactory
)
// Start the server
server
:=
NewServer
()
server
.
RegisterBuilderFactory
(
b
)
server
.
Start
()
defer
server
.
Stop
()
// Create the client over RPC and run some methods to verify it works
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
server
.
Address
())
assert
.
Nil
(
err
,
"should be able to connect"
)
// Test Create
name
:=
"foo"
bClient
:=
&
BuilderFactory
{
client
}
builder
:=
bClient
.
CreateBuilder
(
name
)
assert
.
True
(
b
.
createCalled
,
"create should be called"
)
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
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
realVar
packer
.
BuilderFactory
b
:=
&
BuilderFactory
{
nil
}
assert
.
Implementor
(
b
,
&
realVar
,
"should be a BuilderFactory"
)
}
packer/rpc/environment.go
View file @
a6aafde0
...
@@ -21,15 +21,6 @@ type EnvironmentCliArgs struct {
...
@@ -21,15 +21,6 @@ type EnvironmentCliArgs struct {
Args
[]
string
Args
[]
string
}
}
func
(
e
*
Environment
)
BuilderFactory
()
packer
.
BuilderFactory
{
var
reply
string
e
.
client
.
Call
(
"Environment.BuilderFactory"
,
new
(
interface
{}),
&
reply
)
// TODO: error handling
client
,
_
:=
rpc
.
Dial
(
"tcp"
,
reply
)
return
&
BuilderFactory
{
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
)
...
@@ -45,18 +36,6 @@ func (e *Environment) Ui() packer.Ui {
...
@@ -45,18 +36,6 @@ func (e *Environment) Ui() packer.Ui {
return
&
Ui
{
client
}
return
&
Ui
{
client
}
}
}
func
(
e
*
EnvironmentServer
)
BuilderFactory
(
args
*
interface
{},
reply
*
string
)
error
{
bf
:=
e
.
env
.
BuilderFactory
()
// Wrap that up into a server, and server a single connection back
server
:=
NewServer
()
server
.
RegisterBuilderFactory
(
bf
)
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 @
a6aafde0
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"testing"
"testing"
)
)
var
testEnvBF
=
&
testBuilderFactory
{}
var
testEnvUi
=
&
testUi
{}
var
testEnvUi
=
&
testUi
{}
type
testEnvironment
struct
{
type
testEnvironment
struct
{
...
@@ -17,11 +16,6 @@ type testEnvironment struct {
...
@@ -17,11 +16,6 @@ type testEnvironment struct {
uiCalled
bool
uiCalled
bool
}
}
func
(
e
*
testEnvironment
)
BuilderFactory
()
packer
.
BuilderFactory
{
e
.
bfCalled
=
true
return
testEnvBF
}
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
...
@@ -48,15 +42,7 @@ func TestEnvironmentRPC(t *testing.T) {
...
@@ -48,15 +42,7 @@ func TestEnvironmentRPC(t *testing.T) {
// Create the client over RPC and run some methods to verify it works
// Create the client over RPC and run some methods to verify it works
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
server
.
Address
())
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
server
.
Address
())
assert
.
Nil
(
err
,
"should be able to connect"
)
assert
.
Nil
(
err
,
"should be able to connect"
)
// Test BuilderFactory
eClient
:=
&
Environment
{
client
}
eClient
:=
&
Environment
{
client
}
bf
:=
eClient
.
BuilderFactory
()
assert
.
True
(
e
.
bfCalled
,
"BuilderFactory should be called"
)
// Test calls on the factory
_
=
bf
.
CreateBuilder
(
"foo"
)
assert
.
True
(
testEnvBF
.
createCalled
,
"create should be called on BF"
)
// Test Cli
// Test Cli
cliArgs
:=
[]
string
{
"foo"
,
"bar"
}
cliArgs
:=
[]
string
{
"foo"
,
"bar"
}
...
...
packer/rpc/server.go
View file @
a6aafde0
...
@@ -37,10 +37,6 @@ func (s *Server) RegisterBuilder(b packer.Builder) {
...
@@ -37,10 +37,6 @@ func (s *Server) RegisterBuilder(b packer.Builder) {
s
.
server
.
RegisterName
(
"Builder"
,
&
BuilderServer
{
b
})
s
.
server
.
RegisterName
(
"Builder"
,
&
BuilderServer
{
b
})
}
}
func
(
s
*
Server
)
RegisterBuilderFactory
(
b
packer
.
BuilderFactory
)
{
s
.
server
.
RegisterName
(
"BuilderFactory"
,
&
BuilderFactoryServer
{
b
})
}
func
(
s
*
Server
)
RegisterCommand
(
c
packer
.
Command
)
{
func
(
s
*
Server
)
RegisterCommand
(
c
packer
.
Command
)
{
s
.
server
.
RegisterName
(
"Command"
,
&
ServerCommand
{
c
})
s
.
server
.
RegisterName
(
"Command"
,
&
ServerCommand
{
c
})
}
}
...
...
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