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
e629eef9
Commit
e629eef9
authored
Jun 01, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: Start testing the client
parent
45c590f4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
1 deletion
+54
-1
packer/plugin/client.go
packer/plugin/client.go
+4
-1
packer/plugin/client_test.go
packer/plugin/client_test.go
+47
-0
packer/plugin/plugin_test.go
packer/plugin/plugin_test.go
+3
-0
No files found.
packer/plugin/client.go
View file @
e629eef9
...
...
@@ -16,6 +16,8 @@ import (
var
managedClients
=
make
([]
*
client
,
0
,
5
)
type
client
struct
{
StartTimeout
time
.
Duration
cmd
*
exec
.
Cmd
exited
bool
doneLogging
bool
...
...
@@ -52,6 +54,7 @@ func CleanupClients() {
// be properly cleaned.
func
NewClient
(
cmd
*
exec
.
Cmd
)
*
client
{
return
&
client
{
1
*
time
.
Minute
,
cmd
,
false
,
false
,
...
...
@@ -122,7 +125,7 @@ func (c *client) Start() (address string, err error) {
go
c
.
logStderr
(
stderr
)
// Some channels for the next step
timeout
:=
time
.
After
(
1
*
time
.
Minute
)
timeout
:=
time
.
After
(
c
.
StartTimeout
)
// Start looking for the address
for
done
:=
false
;
!
done
;
{
...
...
packer/plugin/client_test.go
0 → 100644
View file @
e629eef9
package
plugin
import
(
"testing"
"time"
)
func
TestClient
(
t
*
testing
.
T
)
{
process
:=
helperProcess
(
"mock"
)
c
:=
NewClient
(
process
)
defer
c
.
Kill
()
// Test that it parses the proper address
addr
,
err
:=
c
.
Start
()
if
err
!=
nil
{
t
.
Fatalf
(
"err should be nil, got %s"
,
err
)
}
if
addr
!=
":1234"
{
t
.
Fatalf
(
"incorrect addr %s"
,
addr
)
}
// Test that it exits properly if killed
c
.
Kill
()
if
process
.
ProcessState
==
nil
{
t
.
Fatal
(
"should have process state"
)
}
// Test that it knows it is exited
if
!
c
.
Exited
()
{
t
.
Fatal
(
"should say client has exited"
)
}
}
func
TestClient_Start_Timeout
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
helperProcess
(
"start-timeout"
))
defer
c
.
Kill
()
// Set a shorter timeout
c
.
StartTimeout
=
50
*
time
.
Millisecond
_
,
err
:=
c
.
Start
()
if
err
==
nil
{
t
.
Fatal
(
"err should not be nil"
)
}
}
packer/plugin/plugin_test.go
View file @
e629eef9
...
...
@@ -56,6 +56,9 @@ func TestHelperProcess(*testing.T) {
ServeHook
(
new
(
helperHook
))
case
"invalid-rpc-address"
:
fmt
.
Println
(
"lolinvalid"
)
case
"mock"
:
fmt
.
Println
(
":1234"
)
<-
make
(
chan
int
)
case
"provisioner"
:
ServeProvisioner
(
new
(
helperProvisioner
))
case
"start-timeout"
:
...
...
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