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
c9c294f1
Commit
c9c294f1
authored
May 07, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: More robust command exit detection + tests
parent
9219a19f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
8 deletions
+30
-8
packer/plugin/command.go
packer/plugin/command.go
+17
-8
packer/plugin/command_test.go
packer/plugin/command_test.go
+9
-0
packer/plugin/plugin_test.go
packer/plugin/plugin_test.go
+4
-0
No files found.
packer/plugin/command.go
View file @
c9c294f1
...
...
@@ -36,21 +36,30 @@ func Command(cmd *exec.Cmd) (result packer.Command, err error) {
select
{
case
<-
cmdExited
:
err
=
errors
.
New
(
"plugin exited before we could connect"
)
return
case
<-
time
.
After
(
10
*
time
.
Millisecond
)
:
if
line
,
err
:=
out
.
ReadBytes
(
'\n'
);
err
==
nil
{
address
=
strings
.
TrimSpace
(
string
(
line
))
done
=
true
}
done
=
true
default
:
}
// Make sure to reset err to nil
if
line
,
lerr
:=
out
.
ReadBytes
(
'\n'
);
lerr
==
nil
{
// Trim the address and reset the err since we were able
// to read some sort of address.
address
=
strings
.
TrimSpace
(
string
(
line
))
err
=
nil
break
}
// If error is nil from previously, return now
if
err
!=
nil
{
return
}
// Wait a bit
time
.
Sleep
(
10
*
time
.
Millisecond
)
}
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
if
err
!=
nil
{
panic
(
err
)
return
}
result
=
packrpc
.
Command
(
client
)
...
...
packer/plugin/command_test.go
View file @
c9c294f1
...
...
@@ -28,4 +28,13 @@ func TestCommand_CommandExited(t *testing.T) {
_
,
err
:=
Command
(
helperProcess
(
"im-a-command-that-doesnt-work"
))
assert
.
NotNil
(
err
,
"should have an error"
)
assert
.
Equal
(
err
.
Error
(),
"plugin exited before we could connect"
,
"be correct error"
)
}
func
TestCommand_BadRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
_
,
err
:=
Command
(
helperProcess
(
"invalid-rpc-address"
))
assert
.
NotNil
(
err
,
"should have an error"
)
assert
.
Equal
(
err
.
Error
(),
"missing port in address lolinvalid"
,
"be correct error"
)
}
packer/plugin/plugin_test.go
View file @
c9c294f1
...
...
@@ -40,6 +40,8 @@ func TestHelperProcess(*testing.T) {
return
}
defer
os
.
Exit
(
0
)
args
:=
os
.
Args
for
len
(
args
)
>
0
{
if
args
[
0
]
==
"--"
{
...
...
@@ -59,6 +61,8 @@ func TestHelperProcess(*testing.T) {
switch
cmd
{
case
"command"
:
ServeCommand
(
new
(
helperCommand
))
case
"invalid-rpc-address"
:
fmt
.
Println
(
"lolinvalid"
)
case
"start-timeout"
:
time
.
Sleep
(
1
*
time
.
Minute
)
os
.
Exit
(
1
)
...
...
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