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
24237da3
Commit
24237da3
authored
May 28, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: RemoteCommand.ExitChan() and tests
parent
97ba1527
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
0 deletions
+52
-0
TODO.md
TODO.md
+1
-0
packer/communicator.go
packer/communicator.go
+26
-0
packer/communicator_test.go
packer/communicator_test.go
+25
-0
No files found.
TODO.md
View file @
24237da3
...
...
@@ -4,6 +4,7 @@
*
communicator/ssh: Ability to re-establish connection
*
communicator/ssh: Download()
*
packer: Communicator should have Close() method
*
packer: RemoteCommand.ExitChan() should be more efficient
*
packer: Ui input
*
packer/plugin: Better error messages/detection if plugin crashes
*
packer/plugin: Testing of client struct/methods
...
...
packer/communicator.go
View file @
24237da3
...
...
@@ -36,6 +36,32 @@ type RemoteCommand struct {
ExitStatus
int
}
// StdoutStream returns a channel that will be sent all the output
// of stdout as it comes. The output isn't guaranteed to be a full line.
// When the channel is closed, the process is exited.
func
(
r
*
RemoteCommand
)
StdoutChan
()
(
<-
chan
string
)
{
return
nil
}
// ExitChan returns a channel that will be sent the exit status once
// the process exits. This can be used in cases such a select statement
// waiting on the process to end.
func
(
r
*
RemoteCommand
)
ExitChan
()
(
<-
chan
int
)
{
// TODO(mitchellh): lock
// TODO(mitchellh): Something more efficient than multiple Wait() calls
// Make a single buffered channel so that the send doesn't block.
exitChan
:=
make
(
chan
int
,
1
)
go
func
()
{
defer
close
(
exitChan
)
r
.
Wait
()
exitChan
<-
r
.
ExitStatus
}()
return
exitChan
}
// Wait waits for the command to exit.
func
(
r
*
RemoteCommand
)
Wait
()
{
// Busy wait on being exited. We put a sleep to be kind to the
...
...
packer/communicator_test.go
View file @
24237da3
...
...
@@ -5,6 +5,31 @@ import (
"time"
)
func
TestRemoteCommand_ExitChan
(
t
*
testing
.
T
)
{
t
.
Parallel
()
rc
:=
&
RemoteCommand
{}
exitChan
:=
rc
.
ExitChan
()
// Set the exit data so that it is sent
rc
.
ExitStatus
=
42
rc
.
Exited
=
true
select
{
case
exitCode
:=
<-
exitChan
:
if
exitCode
!=
42
{
t
.
Fatal
(
"invalid exit code"
)
}
_
,
ok
:=
<-
exitChan
if
ok
{
t
.
Fatal
(
"exit channel should be closed"
)
}
case
<-
time
.
After
(
500
*
time
.
Millisecond
)
:
t
.
Fatal
(
"exit channel never sent"
)
}
}
func
TestRemoteCommand_WaitBlocks
(
t
*
testing
.
T
)
{
t
.
Parallel
()
...
...
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