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
19867b75
Commit
19867b75
authored
Oct 16, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: don't depend on cgl
parent
24ad445e
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
274 additions
and
166 deletions
+274
-166
packer/rpc/artifact_test.go
packer/rpc/artifact_test.go
+20
-14
packer/rpc/build_test.go
packer/rpc/build_test.go
+48
-23
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+50
-24
packer/rpc/cache_test.go
packer/rpc/cache_test.go
+27
-12
packer/rpc/command_test.go
packer/rpc/command_test.go
+24
-18
packer/rpc/environment_test.go
packer/rpc/environment_test.go
+41
-22
packer/rpc/error_test.go
packer/rpc/error_test.go
+4
-10
packer/rpc/hook_test.go
packer/rpc/hook_test.go
+10
-12
packer/rpc/port_test.go
packer/rpc/port_test.go
+12
-7
packer/rpc/provisioner_test.go
packer/rpc/provisioner_test.go
+17
-14
packer/rpc/ui_test.go
packer/rpc/ui_test.go
+21
-10
No files found.
packer/rpc/artifact_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"reflect"
"testing"
"testing"
)
)
...
@@ -30,8 +30,6 @@ func (testArtifact) Destroy() error {
...
@@ -30,8 +30,6 @@ func (testArtifact) Destroy() error {
}
}
func
TestArtifactRPC
(
t
*
testing
.
T
)
{
func
TestArtifactRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
// Create the interface to test
a
:=
new
(
testArtifact
)
a
:=
new
(
testArtifact
)
...
@@ -42,21 +40,29 @@ func TestArtifactRPC(t *testing.T) {
...
@@ -42,21 +40,29 @@ func TestArtifactRPC(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"
,
address
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
assert
.
Nil
(
err
,
"should be able to connect"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
aClient
:=
Artifact
(
client
)
aClient
:=
Artifact
(
client
)
// Test
// Test
assert
.
Equal
(
aClient
.
BuilderId
(),
"bid"
,
"should have correct builder ID"
)
if
aClient
.
BuilderId
()
!=
"bid"
{
assert
.
Equal
(
aClient
.
Files
(),
[]
string
{
"a"
,
"b"
},
"should have correct builder ID"
)
t
.
Fatalf
(
"bad: %s"
,
aClient
.
BuilderId
())
assert
.
Equal
(
aClient
.
Id
(),
"id"
,
"should have correct builder ID"
)
}
assert
.
Equal
(
aClient
.
String
(),
"string"
,
"should have correct builder ID"
)
}
func
TestArtifact_Implements
(
t
*
testing
.
T
)
{
if
!
reflect
.
DeepEqual
(
aClient
.
Files
(),
[]
string
{
"a"
,
"b"
})
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
t
.
Fatalf
(
"bad: %#v"
,
aClient
.
Files
())
}
var
r
packer
.
Artifact
if
aClient
.
Id
()
!=
"id"
{
a
:=
Artifact
(
nil
)
t
.
Fatalf
(
"bad: %s"
,
aClient
.
Id
())
}
assert
.
Implementor
(
a
,
&
r
,
"should be an Artifact"
)
if
aClient
.
String
()
!=
"string"
{
t
.
Fatalf
(
"bad: %s"
,
aClient
.
String
())
}
}
func
TestArtifact_Implements
(
t
*
testing
.
T
)
{
var
_
packer
.
Artifact
=
Artifact
(
nil
)
}
}
packer/rpc/build_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"errors"
"errors"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
...
@@ -60,8 +59,6 @@ func (b *testBuild) Cancel() {
...
@@ -60,8 +59,6 @@ func (b *testBuild) Cancel() {
}
}
func
TestBuildRPC
(
t
*
testing
.
T
)
{
func
TestBuildRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
// Create the interface to test
b
:=
new
(
testBuild
)
b
:=
new
(
testBuild
)
...
@@ -72,16 +69,23 @@ func TestBuildRPC(t *testing.T) {
...
@@ -72,16 +69,23 @@ func TestBuildRPC(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"
,
address
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
assert
.
Nil
(
err
,
"should be able to connect"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
bClient
:=
Build
(
client
)
bClient
:=
Build
(
client
)
// Test Name
// Test Name
bClient
.
Name
()
bClient
.
Name
()
assert
.
True
(
b
.
nameCalled
,
"name should be called"
)
if
!
b
.
nameCalled
{
t
.
Fatal
(
"name should be called"
)
}
// Test Prepare
// Test Prepare
bClient
.
Prepare
(
map
[
string
]
string
{
"foo"
:
"bar"
})
bClient
.
Prepare
(
map
[
string
]
string
{
"foo"
:
"bar"
})
assert
.
True
(
b
.
prepareCalled
,
"prepare should be called"
)
if
!
b
.
prepareCalled
{
t
.
Fatal
(
"prepare should be called"
)
}
if
len
(
b
.
prepareVars
)
!=
1
{
if
len
(
b
.
prepareVars
)
!=
1
{
t
.
Fatalf
(
"bad vars: %#v"
,
b
.
prepareVars
)
t
.
Fatalf
(
"bad vars: %#v"
,
b
.
prepareVars
)
}
}
...
@@ -94,44 +98,65 @@ func TestBuildRPC(t *testing.T) {
...
@@ -94,44 +98,65 @@ func TestBuildRPC(t *testing.T) {
cache
:=
new
(
testCache
)
cache
:=
new
(
testCache
)
ui
:=
new
(
testUi
)
ui
:=
new
(
testUi
)
artifacts
,
err
:=
bClient
.
Run
(
ui
,
cache
)
artifacts
,
err
:=
bClient
.
Run
(
ui
,
cache
)
assert
.
True
(
b
.
runCalled
,
"run should be called"
)
if
!
b
.
runCalled
{
assert
.
Nil
(
err
,
"should not error"
)
t
.
Fatal
(
"run should be called"
)
assert
.
Equal
(
len
(
artifacts
),
1
,
"should have one artifact"
)
}
assert
.
Equal
(
artifacts
[
0
]
.
BuilderId
(),
"bid"
,
"should have proper builder id"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
len
(
artifacts
)
!=
1
{
t
.
Fatalf
(
"bad: %#v"
,
artifacts
)
}
if
artifacts
[
0
]
.
BuilderId
()
!=
"bid"
{
t
.
Fatalf
(
"bad: %#v"
,
artifacts
)
}
// Test the UI given to run, which should be fully functional
// Test the UI given to run, which should be fully functional
if
b
.
runCalled
{
if
b
.
runCalled
{
b
.
runCache
.
Lock
(
"foo"
)
b
.
runCache
.
Lock
(
"foo"
)
assert
.
True
(
cache
.
lockCalled
,
"lock should be called"
)
if
!
cache
.
lockCalled
{
t
.
Fatal
(
"lock shuld be called"
)
}
b
.
runUi
.
Say
(
"format"
)
b
.
runUi
.
Say
(
"format"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
if
!
ui
.
sayCalled
{
assert
.
Equal
(
ui
.
sayMessage
,
"format"
,
"message should be correct"
)
t
.
Fatal
(
"say should be called"
)
}
if
ui
.
sayMessage
!=
"format"
{
t
.
Fatalf
(
"bad: %#v"
,
ui
.
sayMessage
)
}
}
}
// Test run with an error
// Test run with an error
b
.
errRunResult
=
true
b
.
errRunResult
=
true
_
,
err
=
bClient
.
Run
(
ui
,
cache
)
_
,
err
=
bClient
.
Run
(
ui
,
cache
)
assert
.
NotNil
(
err
,
"should not nil"
)
if
err
==
nil
{
t
.
Fatal
(
"should error"
)
}
// Test SetDebug
// Test SetDebug
bClient
.
SetDebug
(
true
)
bClient
.
SetDebug
(
true
)
assert
.
True
(
b
.
setDebugCalled
,
"should be called"
)
if
!
b
.
setDebugCalled
{
t
.
Fatal
(
"should be called"
)
}
// Test SetForce
// Test SetForce
bClient
.
SetForce
(
true
)
bClient
.
SetForce
(
true
)
assert
.
True
(
b
.
setForceCalled
,
"should be called"
)
if
!
b
.
setForceCalled
{
t
.
Fatal
(
"should be called"
)
}
// Test Cancel
// Test Cancel
bClient
.
Cancel
()
bClient
.
Cancel
()
assert
.
True
(
b
.
cancelCalled
,
"cancel should be called"
)
if
!
b
.
cancelCalled
{
t
.
Fatal
(
"should be called"
)
}
}
}
func
TestBuild_ImplementsBuild
(
t
*
testing
.
T
)
{
func
TestBuild_ImplementsBuild
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
_
packer
.
Build
=
Build
(
nil
)
var
realBuild
packer
.
Build
b
:=
Build
(
nil
)
assert
.
Implementor
(
b
,
&
realBuild
,
"should be a Build"
)
}
}
packer/rpc/builder_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"errors"
"errors"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"reflect"
"testing"
"testing"
)
)
...
@@ -49,8 +49,6 @@ func (b *testBuilder) Cancel() {
...
@@ -49,8 +49,6 @@ func (b *testBuilder) Cancel() {
}
}
func
TestBuilderRPC
(
t
*
testing
.
T
)
{
func
TestBuilderRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
// Create the interface to test
b
:=
new
(
testBuilder
)
b
:=
new
(
testBuilder
)
...
@@ -61,60 +59,88 @@ func TestBuilderRPC(t *testing.T) {
...
@@ -61,60 +59,88 @@ func TestBuilderRPC(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"
,
address
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
assert
.
Nil
(
err
,
"should be able to connect"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Test Prepare
// Test Prepare
config
:=
42
config
:=
42
bClient
:=
Builder
(
client
)
bClient
:=
Builder
(
client
)
bClient
.
Prepare
(
config
)
bClient
.
Prepare
(
config
)
assert
.
True
(
b
.
prepareCalled
,
"prepare should be called"
)
if
!
b
.
prepareCalled
{
assert
.
Equal
(
b
.
prepareConfig
,
[]
interface
{}{
42
},
"prepare should be called with right arg"
)
t
.
Fatal
(
"should be called"
)
}
if
!
reflect
.
DeepEqual
(
b
.
prepareConfig
,
[]
interface
{}{
42
})
{
t
.
Fatalf
(
"bad: %#v"
,
b
.
prepareConfig
)
}
// Test Run
// Test Run
cache
:=
new
(
testCache
)
cache
:=
new
(
testCache
)
hook
:=
&
packer
.
MockHook
{}
hook
:=
&
packer
.
MockHook
{}
ui
:=
&
testUi
{}
ui
:=
&
testUi
{}
artifact
,
err
:=
bClient
.
Run
(
ui
,
hook
,
cache
)
artifact
,
err
:=
bClient
.
Run
(
ui
,
hook
,
cache
)
assert
.
Nil
(
err
,
"should have no error"
)
if
err
!=
nil
{
assert
.
True
(
b
.
runCalled
,
"runs hould be called"
)
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
b
.
runCalled
{
t
.
Fatal
(
"run should be called"
)
}
if
b
.
runCalled
{
if
b
.
runCalled
{
b
.
runCache
.
Lock
(
"foo"
)
b
.
runCache
.
Lock
(
"foo"
)
assert
.
True
(
cache
.
lockCalled
,
"lock should be called"
)
if
!
cache
.
lockCalled
{
t
.
Fatal
(
"should be called"
)
}
b
.
runHook
.
Run
(
"foo"
,
nil
,
nil
,
nil
)
b
.
runHook
.
Run
(
"foo"
,
nil
,
nil
,
nil
)
assert
.
True
(
hook
.
RunCalled
,
"run should be called"
)
if
!
hook
.
RunCalled
{
t
.
Fatal
(
"should be called"
)
}
b
.
runUi
.
Say
(
"format"
)
b
.
runUi
.
Say
(
"format"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
if
!
ui
.
sayCalled
{
assert
.
Equal
(
ui
.
sayMessage
,
"format"
,
"message should be correct"
)
t
.
Fatal
(
"say should be called"
)
}
assert
.
Equal
(
artifact
.
Id
(),
testBuilderArtifact
.
Id
(),
"should have artifact Id"
)
if
ui
.
sayMessage
!=
"format"
{
t
.
Fatalf
(
"bad: %s"
,
ui
.
sayMessage
)
}
if
artifact
.
Id
()
!=
testBuilderArtifact
.
Id
()
{
t
.
Fatalf
(
"bad: %s"
,
artifact
.
Id
())
}
}
}
// Test run with nil result
// Test run with nil result
b
.
nilRunResult
=
true
b
.
nilRunResult
=
true
artifact
,
err
=
bClient
.
Run
(
ui
,
hook
,
cache
)
artifact
,
err
=
bClient
.
Run
(
ui
,
hook
,
cache
)
assert
.
Nil
(
artifact
,
"should be nil"
)
if
artifact
!=
nil
{
assert
.
Nil
(
err
,
"should have no error"
)
t
.
Fatalf
(
"bad: %#v"
,
artifact
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"bad: %#v"
,
err
)
}
// Test with an error
// Test with an error
b
.
errRunResult
=
true
b
.
errRunResult
=
true
b
.
nilRunResult
=
false
b
.
nilRunResult
=
false
artifact
,
err
=
bClient
.
Run
(
ui
,
hook
,
cache
)
artifact
,
err
=
bClient
.
Run
(
ui
,
hook
,
cache
)
assert
.
Nil
(
artifact
,
"should be nil"
)
if
artifact
!=
nil
{
assert
.
NotNil
(
err
,
"should have error"
)
t
.
Fatalf
(
"bad: %#v"
,
artifact
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test Cancel
// Test Cancel
bClient
.
Cancel
()
bClient
.
Cancel
()
assert
.
True
(
b
.
cancelCalled
,
"cancel should be called"
)
if
!
b
.
cancelCalled
{
t
.
Fatal
(
"cancel should be called"
)
}
}
}
func
TestBuilder_ImplementsBuilder
(
t
*
testing
.
T
)
{
func
TestBuilder_ImplementsBuilder
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
_
packer
.
Builder
=
Builder
(
nil
)
var
realBuilder
packer
.
Builder
b
:=
Builder
(
nil
)
assert
.
Implementor
(
b
,
&
realBuilder
,
"should be a Builder"
)
}
}
packer/rpc/cache_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"testing"
"testing"
...
@@ -49,8 +48,6 @@ func TestCache_Implements(t *testing.T) {
...
@@ -49,8 +48,6 @@ func TestCache_Implements(t *testing.T) {
}
}
func
TestCacheRPC
(
t
*
testing
.
T
)
{
func
TestCacheRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
// Create the interface to test
c
:=
new
(
testCache
)
c
:=
new
(
testCache
)
...
@@ -61,26 +58,44 @@ func TestCacheRPC(t *testing.T) {
...
@@ -61,26 +58,44 @@ func TestCacheRPC(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
rpcClient
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
rpcClient
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
assert
.
Nil
(
err
,
"should be able to connect"
)
if
err
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
err
)
}
client
:=
Cache
(
rpcClient
)
client
:=
Cache
(
rpcClient
)
// Test Lock
// Test Lock
client
.
Lock
(
"foo"
)
client
.
Lock
(
"foo"
)
assert
.
True
(
c
.
lockCalled
,
"should be called"
)
if
!
c
.
lockCalled
{
assert
.
Equal
(
c
.
lockKey
,
"foo"
,
"should have proper key"
)
t
.
Fatal
(
"should be called"
)
}
if
c
.
lockKey
!=
"foo"
{
t
.
Fatalf
(
"bad: %s"
,
c
.
lockKey
)
}
// Test Unlock
// Test Unlock
client
.
Unlock
(
"foo"
)
client
.
Unlock
(
"foo"
)
assert
.
True
(
c
.
unlockCalled
,
"should be called"
)
if
!
c
.
unlockCalled
{
assert
.
Equal
(
c
.
unlockKey
,
"foo"
,
"should have proper key"
)
t
.
Fatal
(
"should be called"
)
}
if
c
.
unlockKey
!=
"foo"
{
t
.
Fatalf
(
"bad: %s"
,
c
.
unlockKey
)
}
// Test RLock
// Test RLock
client
.
RLock
(
"foo"
)
client
.
RLock
(
"foo"
)
assert
.
True
(
c
.
rlockCalled
,
"should be called"
)
if
!
c
.
rlockCalled
{
assert
.
Equal
(
c
.
rlockKey
,
"foo"
,
"should have proper key"
)
t
.
Fatal
(
"should be called"
)
}
if
c
.
rlockKey
!=
"foo"
{
t
.
Fatalf
(
"bad: %s"
,
c
.
rlockKey
)
}
// Test RUnlock
// Test RUnlock
client
.
RUnlock
(
"foo"
)
client
.
RUnlock
(
"foo"
)
assert
.
True
(
c
.
runlockCalled
,
"should be called"
)
if
!
c
.
runlockCalled
{
assert
.
Equal
(
c
.
runlockKey
,
"foo"
,
"should have proper key"
)
t
.
Fatal
(
"should be called"
)
}
if
c
.
runlockKey
!=
"foo"
{
t
.
Fatalf
(
"bad: %s"
,
c
.
runlockKey
)
}
}
}
packer/rpc/command_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"reflect"
"testing"
"testing"
)
)
...
@@ -29,8 +29,6 @@ func (tc *TestCommand) Synopsis() string {
...
@@ -29,8 +29,6 @@ func (tc *TestCommand) Synopsis() string {
}
}
func
TestRPCCommand
(
t
*
testing
.
T
)
{
func
TestRPCCommand
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the command
// Create the command
command
:=
new
(
TestCommand
)
command
:=
new
(
TestCommand
)
...
@@ -42,37 +40,45 @@ func TestRPCCommand(t *testing.T) {
...
@@ -42,37 +40,45 @@ func TestRPCCommand(t *testing.T) {
// Create the command client over RPC and run some methods to verify
// Create the command client over RPC and run some methods to verify
// we get the proper behavior.
// we get the proper behavior.
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
assert
.
Nil
(
err
,
"should be no error"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
clientComm
:=
Command
(
client
)
clientComm
:=
Command
(
client
)
//Test Help
//Test Help
help
:=
clientComm
.
Help
()
help
:=
clientComm
.
Help
()
assert
.
Equal
(
help
,
"bar"
,
"helps hould be correct"
)
if
help
!=
"bar"
{
t
.
Fatalf
(
"bad: %s"
,
help
)
}
// Test run
// Test run
runArgs
:=
[]
string
{
"foo"
,
"bar"
}
runArgs
:=
[]
string
{
"foo"
,
"bar"
}
testEnv
:=
&
testEnvironment
{}
testEnv
:=
&
testEnvironment
{}
exitCode
:=
clientComm
.
Run
(
testEnv
,
runArgs
)
exitCode
:=
clientComm
.
Run
(
testEnv
,
runArgs
)
assert
.
Equal
(
command
.
runArgs
,
runArgs
,
"Correct args should be sent"
)
if
!
reflect
.
DeepEqual
(
command
.
runArgs
,
runArgs
)
{
assert
.
Equal
(
exitCode
,
0
,
"Exit code should be correct"
)
t
.
Fatalf
(
"bad: %#v"
,
command
.
runArgs
)
}
if
exitCode
!=
0
{
t
.
Fatalf
(
"bad: %d"
,
exitCode
)
}
assert
.
NotNil
(
command
.
runEnv
,
"should have an env"
)
if
command
.
runEnv
==
nil
{
if
command
.
runEnv
!=
nil
{
t
.
Fatal
(
"runEnv should not be nil"
)
command
.
runEnv
.
Ui
()
}
assert
.
True
(
testEnv
.
uiCalled
,
"UI should be called on env"
)
command
.
runEnv
.
Ui
()
if
!
testEnv
.
uiCalled
{
t
.
Fatal
(
"ui should be called"
)
}
}
// Test Synopsis
// Test Synopsis
synopsis
:=
clientComm
.
Synopsis
()
synopsis
:=
clientComm
.
Synopsis
()
assert
.
Equal
(
synopsis
,
"foo"
,
"Synopsis should be correct"
)
if
synopsis
!=
"foo"
{
t
.
Fatalf
(
"bad: %#v"
,
synopsis
)
}
}
}
func
TestCommand_Implements
(
t
*
testing
.
T
)
{
func
TestCommand_Implements
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
_
packer
.
Command
=
Command
(
nil
)
var
r
packer
.
Command
c
:=
Command
(
nil
)
assert
.
Implementor
(
c
,
&
r
,
"should be a Builder"
)
}
}
packer/rpc/environment_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"reflect"
"testing"
"testing"
)
)
...
@@ -65,8 +65,6 @@ func (e *testEnvironment) Ui() packer.Ui {
...
@@ -65,8 +65,6 @@ func (e *testEnvironment) Ui() packer.Ui {
}
}
func
TestEnvironmentRPC
(
t
*
testing
.
T
)
{
func
TestEnvironmentRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
// Create the interface to test
e
:=
&
testEnvironment
{}
e
:=
&
testEnvironment
{}
...
@@ -77,49 +75,70 @@ func TestEnvironmentRPC(t *testing.T) {
...
@@ -77,49 +75,70 @@ 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"
,
address
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
assert
.
Nil
(
err
,
"should be able to connect"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
eClient
:=
&
Environment
{
client
}
eClient
:=
&
Environment
{
client
}
// Test Builder
// Test Builder
builder
,
_
:=
eClient
.
Builder
(
"foo"
)
builder
,
_
:=
eClient
.
Builder
(
"foo"
)
assert
.
True
(
e
.
builderCalled
,
"Builder should be called"
)
if
!
e
.
builderCalled
{
assert
.
Equal
(
e
.
builderName
,
"foo"
,
"Correct name for Builder"
)
t
.
Fatal
(
"builder should be called"
)
}
if
e
.
builderName
!=
"foo"
{
t
.
Fatalf
(
"bad: %#v"
,
e
.
builderName
)
}
builder
.
Prepare
(
nil
)
builder
.
Prepare
(
nil
)
assert
.
True
(
testEnvBuilder
.
prepareCalled
,
"Prepare should be called"
)
if
!
testEnvBuilder
.
prepareCalled
{
t
.
Fatal
(
"should be called"
)
}
// Test Cache
// Test Cache
cache
:=
eClient
.
Cache
()
cache
:=
eClient
.
Cache
()
cache
.
Lock
(
"foo"
)
cache
.
Lock
(
"foo"
)
assert
.
True
(
testEnvCache
.
lockCalled
,
"lock should be called"
)
if
!
testEnvCache
.
lockCalled
{
t
.
Fatal
(
"should be called"
)
}
// Test Cli
// Test Cli
cliArgs
:=
[]
string
{
"foo"
,
"bar"
}
cliArgs
:=
[]
string
{
"foo"
,
"bar"
}
result
,
_
:=
eClient
.
Cli
(
cliArgs
)
result
,
_
:=
eClient
.
Cli
(
cliArgs
)
assert
.
True
(
e
.
cliCalled
,
"CLI should be called"
)
if
!
e
.
cliCalled
{
assert
.
Equal
(
e
.
cliArgs
,
cliArgs
,
"args should match"
)
t
.
Fatal
(
"should be called"
)
assert
.
Equal
(
result
,
42
,
"result shuld be 42"
)
}
if
!
reflect
.
DeepEqual
(
e
.
cliArgs
,
cliArgs
)
{
t
.
Fatalf
(
"bad: %#v"
,
e
.
cliArgs
)
}
if
result
!=
42
{
t
.
Fatalf
(
"bad: %#v"
,
result
)
}
// Test Provisioner
// Test Provisioner
_
,
_
=
eClient
.
Provisioner
(
"foo"
)
_
,
_
=
eClient
.
Provisioner
(
"foo"
)
assert
.
True
(
e
.
provCalled
,
"provisioner should be called"
)
if
!
e
.
provCalled
{
assert
.
Equal
(
e
.
provName
,
"foo"
,
"should have proper name"
)
t
.
Fatal
(
"should be called"
)
}
if
e
.
provName
!=
"foo"
{
t
.
Fatalf
(
"bad: %s"
,
e
.
provName
)
}
// Test Ui
// Test Ui
ui
:=
eClient
.
Ui
()
ui
:=
eClient
.
Ui
()
assert
.
True
(
e
.
uiCalled
,
"Ui should've been called"
)
if
!
e
.
uiCalled
{
t
.
Fatal
(
"should be called"
)
}
// Test calls on the Ui
// Test calls on the Ui
ui
.
Say
(
"format"
)
ui
.
Say
(
"format"
)
assert
.
True
(
testEnvUi
.
sayCalled
,
"Say should be called"
)
if
!
testEnvUi
.
sayCalled
{
assert
.
Equal
(
testEnvUi
.
sayMessage
,
"format"
,
"message should match"
)
t
.
Fatal
(
"should be called"
)
}
if
testEnvUi
.
sayMessage
!=
"format"
{
t
.
Fatalf
(
"bad: %#v"
,
testEnvUi
.
sayMessage
)
}
}
}
func
TestEnvironment_ImplementsEnvironment
(
t
*
testing
.
T
)
{
func
TestEnvironment_ImplementsEnvironment
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
_
packer
.
Environment
=
new
(
Environment
)
var
realVar
packer
.
Environment
e
:=
&
Environment
{
nil
}
assert
.
Implementor
(
e
,
&
realVar
,
"should be an Environment"
)
}
}
packer/rpc/error_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"errors"
"errors"
"testing"
"testing"
)
)
func
TestBasicError_ImplementsError
(
t
*
testing
.
T
)
{
func
TestBasicError_ImplementsError
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
_
error
=
new
(
BasicError
)
var
r
error
e
:=
&
BasicError
{
""
}
assert
.
Implementor
(
e
,
&
r
,
"should be an error"
)
}
}
func
TestBasicError_MatchesMessage
(
t
*
testing
.
T
)
{
func
TestBasicError_MatchesMessage
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
err
:=
errors
.
New
(
"foo"
)
err
:=
errors
.
New
(
"foo"
)
wrapped
:=
NewBasicError
(
err
)
wrapped
:=
NewBasicError
(
err
)
assert
.
Equal
(
wrapped
.
Error
(),
err
.
Error
(),
"should have the same error"
)
if
wrapped
.
Error
()
!=
err
.
Error
()
{
t
.
Fatalf
(
"bad: %#v"
,
wrapped
.
Error
())
}
}
}
packer/rpc/hook_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"reflect"
"reflect"
...
@@ -11,8 +10,6 @@ import (
...
@@ -11,8 +10,6 @@ import (
)
)
func
TestHookRPC
(
t
*
testing
.
T
)
{
func
TestHookRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the UI to test
// Create the UI to test
h
:=
new
(
packer
.
MockHook
)
h
:=
new
(
packer
.
MockHook
)
...
@@ -23,27 +20,28 @@ func TestHookRPC(t *testing.T) {
...
@@ -23,27 +20,28 @@ func TestHookRPC(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"
,
address
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
assert
.
Nil
(
err
,
"should be able to connect"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
hClient
:=
Hook
(
client
)
hClient
:=
Hook
(
client
)
// Test Run
// Test Run
ui
:=
&
testUi
{}
ui
:=
&
testUi
{}
hClient
.
Run
(
"foo"
,
ui
,
nil
,
42
)
hClient
.
Run
(
"foo"
,
ui
,
nil
,
42
)
assert
.
True
(
h
.
RunCalled
,
"run should be called"
)
if
!
h
.
RunCalled
{
t
.
Fatal
(
"should be called"
)
}
// Test Cancel
// Test Cancel
hClient
.
Cancel
()
hClient
.
Cancel
()
assert
.
True
(
h
.
CancelCalled
,
"cancel should be called"
)
if
!
h
.
CancelCalled
{
t
.
Fatal
(
"should be called"
)
}
}
}
func
TestHook_Implements
(
t
*
testing
.
T
)
{
func
TestHook_Implements
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
_
packer
.
Hook
=
new
(
hook
)
var
r
packer
.
Hook
h
:=
&
hook
{
nil
}
assert
.
Implementor
(
h
,
&
r
,
"should be a Hook"
)
}
}
func
TestHook_cancelWhileRun
(
t
*
testing
.
T
)
{
func
TestHook_cancelWhileRun
(
t
*
testing
.
T
)
{
...
...
packer/rpc/port_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"net"
"net"
"strings"
"strings"
"testing"
"testing"
...
@@ -13,21 +12,27 @@ func addrPort(address net.Addr) string {
...
@@ -13,21 +12,27 @@ func addrPort(address net.Addr) string {
}
}
func
Test_netListenerInRange
(
t
*
testing
.
T
)
{
func
Test_netListenerInRange
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Open up port 10000 so that we take up a port
// Open up port 10000 so that we take up a port
L1000
,
err
:=
net
.
Listen
(
"tcp"
,
"127.0.0.1:11000"
)
L1000
,
err
:=
net
.
Listen
(
"tcp"
,
"127.0.0.1:11000"
)
defer
L1000
.
Close
()
defer
L1000
.
Close
()
assert
.
Nil
(
err
,
"should be able to bind to port 10000"
)
if
err
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
err
)
}
if
err
==
nil
{
if
err
==
nil
{
// Verify it selects an open port
// Verify it selects an open port
L
:=
netListenerInRange
(
11000
,
11005
)
L
:=
netListenerInRange
(
11000
,
11005
)
assert
.
NotNil
(
L
,
"should have a listener"
)
if
L
==
nil
{
assert
.
Equal
(
addrPort
(
L
.
Addr
()),
"11001"
,
"should bind to open port"
)
t
.
Fatal
(
"L should not be nil"
)
}
if
addrPort
(
L
.
Addr
())
!=
"11001"
{
t
.
Fatalf
(
"bad: %s"
,
L
.
Addr
())
}
// Returns nil if there are no open ports
// Returns nil if there are no open ports
L
=
netListenerInRange
(
11000
,
11000
)
L
=
netListenerInRange
(
11000
,
11000
)
assert
.
Nil
(
L
,
"should not get a listener"
)
if
L
!=
nil
{
t
.
Fatalf
(
"bad: %#v"
,
L
)
}
}
}
}
}
packer/rpc/provisioner_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"reflect"
"testing"
"testing"
)
)
func
TestProvisionerRPC
(
t
*
testing
.
T
)
{
func
TestProvisionerRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
// Create the interface to test
p
:=
new
(
packer
.
MockProvisioner
)
p
:=
new
(
packer
.
MockProvisioner
)
...
@@ -20,23 +18,33 @@ func TestProvisionerRPC(t *testing.T) {
...
@@ -20,23 +18,33 @@ func TestProvisionerRPC(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"
,
address
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
assert
.
Nil
(
err
,
"should be able to connect"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Test Prepare
// Test Prepare
config
:=
42
config
:=
42
pClient
:=
Provisioner
(
client
)
pClient
:=
Provisioner
(
client
)
pClient
.
Prepare
(
config
)
pClient
.
Prepare
(
config
)
assert
.
True
(
p
.
PrepCalled
,
"prepare should be called"
)
if
!
p
.
PrepCalled
{
assert
.
Equal
(
p
.
PrepConfigs
,
[]
interface
{}{
42
},
"prepare should be called with right arg"
)
t
.
Fatal
(
"should be called"
)
}
if
!
reflect
.
DeepEqual
(
p
.
PrepConfigs
,
[]
interface
{}{
42
})
{
t
.
Fatalf
(
"bad: %#v"
,
p
.
PrepConfigs
)
}
// Test Provision
// Test Provision
ui
:=
&
testUi
{}
ui
:=
&
testUi
{}
comm
:=
&
packer
.
MockCommunicator
{}
comm
:=
&
packer
.
MockCommunicator
{}
pClient
.
Provision
(
ui
,
comm
)
pClient
.
Provision
(
ui
,
comm
)
assert
.
True
(
p
.
ProvCalled
,
"provision should be called"
)
if
!
p
.
ProvCalled
{
t
.
Fatal
(
"should be called"
)
}
p
.
ProvUi
.
Say
(
"foo"
)
p
.
ProvUi
.
Say
(
"foo"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
if
!
ui
.
sayCalled
{
t
.
Fatal
(
"should be called"
)
}
// Test Cancel
// Test Cancel
pClient
.
Cancel
()
pClient
.
Cancel
()
...
@@ -46,10 +54,5 @@ func TestProvisionerRPC(t *testing.T) {
...
@@ -46,10 +54,5 @@ func TestProvisionerRPC(t *testing.T) {
}
}
func
TestProvisioner_Implements
(
t
*
testing
.
T
)
{
func
TestProvisioner_Implements
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
_
packer
.
Provisioner
=
Provisioner
(
nil
)
var
r
packer
.
Provisioner
p
:=
Provisioner
(
nil
)
assert
.
Implementor
(
p
,
&
r
,
"should be a provisioner"
)
}
}
packer/rpc/ui_test.go
View file @
19867b75
package
rpc
package
rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"net/rpc"
"net/rpc"
"reflect"
"reflect"
"testing"
"testing"
...
@@ -49,8 +48,6 @@ func (u *testUi) Say(message string) {
...
@@ -49,8 +48,6 @@ func (u *testUi) Say(message string) {
}
}
func
TestUiRPC
(
t
*
testing
.
T
)
{
func
TestUiRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the UI to test
// Create the UI to test
ui
:=
new
(
testUi
)
ui
:=
new
(
testUi
)
...
@@ -69,19 +66,33 @@ func TestUiRPC(t *testing.T) {
...
@@ -69,19 +66,33 @@ func TestUiRPC(t *testing.T) {
// Basic error and say tests
// Basic error and say tests
result
,
err
:=
uiClient
.
Ask
(
"query"
)
result
,
err
:=
uiClient
.
Ask
(
"query"
)
assert
.
Nil
(
err
,
"should not error"
)
if
err
!=
nil
{
assert
.
True
(
ui
.
askCalled
,
"ask should be called"
)
t
.
Fatalf
(
"err: %s"
,
err
)
assert
.
Equal
(
ui
.
askQuery
,
"query"
,
"should be correct"
)
}
assert
.
Equal
(
result
,
"foo"
,
"should have correct result"
)
if
!
ui
.
askCalled
{
t
.
Fatal
(
"should be called"
)
}
if
ui
.
askQuery
!=
"query"
{
t
.
Fatalf
(
"bad: %s"
,
ui
.
askQuery
)
}
if
result
!=
"foo"
{
t
.
Fatalf
(
"bad: %#v"
,
result
)
}
uiClient
.
Error
(
"message"
)
uiClient
.
Error
(
"message"
)
assert
.
Equal
(
ui
.
errorMessage
,
"message"
,
"message should be correct"
)
if
ui
.
errorMessage
!=
"message"
{
t
.
Fatalf
(
"bad: %#v"
,
ui
.
errorMessage
)
}
uiClient
.
Message
(
"message"
)
uiClient
.
Message
(
"message"
)
assert
.
Equal
(
ui
.
messageMessage
,
"message"
,
"message should be correct"
)
if
ui
.
messageMessage
!=
"message"
{
t
.
Fatalf
(
"bad: %#v"
,
ui
.
errorMessage
)
}
uiClient
.
Say
(
"message"
)
uiClient
.
Say
(
"message"
)
assert
.
Equal
(
ui
.
sayMessage
,
"message"
,
"message should be correct"
)
if
ui
.
sayMessage
!=
"message"
{
t
.
Fatalf
(
"bad: %#v"
,
ui
.
errorMessage
)
}
uiClient
.
Machine
(
"foo"
,
"bar"
,
"baz"
)
uiClient
.
Machine
(
"foo"
,
"bar"
,
"baz"
)
if
!
ui
.
machineCalled
{
if
!
ui
.
machineCalled
{
...
...
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