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
c164b4c2
Commit
c164b4c2
authored
May 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: Actually try more ports for plugins
parent
a519de21
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
16 deletions
+70
-16
packer/plugin/builder_test.go
packer/plugin/builder_test.go
+29
-0
packer/plugin/command_test.go
packer/plugin/command_test.go
+16
-2
packer/plugin/plugin.go
packer/plugin/plugin.go
+21
-1
packer/plugin/plugin_test.go
packer/plugin/plugin_test.go
+2
-11
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+2
-2
No files found.
packer/plugin/builder_test.go
0 → 100644
View file @
c164b4c2
package
plugin
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"os/exec"
"testing"
)
type
helperBuilder
byte
func
(
helperBuilder
)
Prepare
(
interface
{})
{}
func
(
helperBuilder
)
Run
(
packer
.
Build
,
packer
.
Ui
)
{}
func
TestBuilder_NoExist
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
_
,
err
:=
Builder
(
exec
.
Command
(
"i-should-never-ever-ever-exist"
))
assert
.
NotNil
(
err
,
"should have an error"
)
}
func
TestBuilder_Good
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
_
,
err
:=
Builder
(
helperProcess
(
"builder"
))
assert
.
Nil
(
err
,
"should start builder properly"
)
}
packer/plugin/command_test.go
View file @
c164b4c2
...
...
@@ -2,6 +2,7 @@ package plugin
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"os/exec"
"testing"
)
...
...
@@ -9,6 +10,16 @@ import (
// TODO: Test command cleanup functionality
// TODO: Test timeout functionality
type
helperCommand
byte
func
(
helperCommand
)
Run
(
packer
.
Environment
,
[]
string
)
int
{
return
42
}
func
(
helperCommand
)
Synopsis
()
string
{
return
"1"
}
func
TestCommand_NoExist
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
...
@@ -22,8 +33,11 @@ func TestCommand_Good(t *testing.T) {
command
,
err
:=
Command
(
helperProcess
(
"command"
))
assert
.
Nil
(
err
,
"should start command properly"
)
result
:=
command
.
Synopsis
()
assert
.
Equal
(
result
,
"1"
,
"should return result"
)
assert
.
NotNil
(
command
,
"should have a command"
)
if
command
!=
nil
{
result
:=
command
.
Synopsis
()
assert
.
Equal
(
result
,
"1"
,
"should return result"
)
}
}
func
TestCommand_CommandExited
(
t
*
testing
.
T
)
{
...
...
packer/plugin/plugin.go
View file @
c164b4c2
...
...
@@ -16,6 +16,7 @@ import (
"os"
packrpc
"github.com/mitchellh/packer/packer/rpc"
"strconv"
"strings"
)
// This serves a single RPC connection on the given RPC server on
...
...
@@ -40,7 +41,14 @@ func serve(server *rpc.Server) (err error) {
address
=
fmt
.
Sprintf
(
":%d"
,
port
)
listener
,
err
=
net
.
Listen
(
"tcp"
,
address
)
if
err
!=
nil
{
return
if
!
strings
.
Contains
(
err
.
Error
(),
"address already in use"
)
{
// Not an address already in use error, return.
return
}
else
{
// Address is in use, just try another
err
=
nil
continue
}
}
break
...
...
@@ -67,6 +75,18 @@ func serve(server *rpc.Server) (err error) {
return
}
// Serves a builder from a plugin.
func
ServeBuilder
(
builder
packer
.
Builder
)
{
log
.
Println
(
"Preparing to serve a builder plugin..."
)
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterBuilder
(
server
,
builder
)
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Panic
(
err
)
}
}
// Serves a command from a plugin.
func
ServeCommand
(
command
packer
.
Command
)
{
log
.
Println
(
"Preparing to serve a command plugin..."
)
...
...
packer/plugin/plugin_test.go
View file @
c164b4c2
...
...
@@ -2,23 +2,12 @@ package plugin
import
(
"fmt"
"github.com/mitchellh/packer/packer"
"os"
"os/exec"
"testing"
"time"
)
type
helperCommand
byte
func
(
helperCommand
)
Run
(
packer
.
Environment
,
[]
string
)
int
{
return
42
}
func
(
helperCommand
)
Synopsis
()
string
{
return
"1"
}
func
helperProcess
(
s
...
string
)
*
exec
.
Cmd
{
cs
:=
[]
string
{
"-test.run=TestHelperProcess"
,
"--"
}
cs
=
append
(
cs
,
s
...
)
...
...
@@ -59,6 +48,8 @@ func TestHelperProcess(*testing.T) {
cmd
,
args
:=
args
[
0
],
args
[
1
:
]
switch
cmd
{
case
"builder"
:
ServeBuilder
(
new
(
helperBuilder
))
case
"command"
:
ServeCommand
(
new
(
helperCommand
))
case
"invalid-rpc-address"
:
...
...
packer/rpc/builder_test.go
View file @
c164b4c2
...
...
@@ -43,7 +43,7 @@ func TestBuilderRPC(t *testing.T) {
// Test Prepare
config
:=
42
bClient
:=
&
Builder
{
client
}
bClient
:=
Builder
(
client
)
bClient
.
Prepare
(
config
)
assert
.
True
(
b
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
b
.
prepareConfig
,
42
,
"prepare should be called with right arg"
)
...
...
@@ -68,7 +68,7 @@ func TestBuilder_ImplementsBuild(t *testing.T) {
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
realBuilder
packer
.
Builder
b
:=
&
Builder
{
nil
}
b
:=
Builder
(
nil
)
assert
.
Implementor
(
b
,
&
realBuilder
,
"should be a Builder"
)
}
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