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
ade37951
Commit
ade37951
authored
Jun 01, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: RemoteCommand.StderrChan
parent
3bdd74f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
packer/communicator.go
packer/communicator.go
+20
-0
packer/communicator_test.go
packer/communicator_test.go
+23
-0
No files found.
packer/communicator.go
View file @
ade37951
...
...
@@ -40,10 +40,30 @@ type RemoteCommand struct {
exitChans
[]
chan
<-
int
exitChanLock
sync
.
Mutex
errChans
[]
chan
<-
string
errChanLock
sync
.
Mutex
outChans
[]
chan
<-
string
outChanLock
sync
.
Mutex
}
// StderrStream returns a channel that will be sent all the
func
(
r
*
RemoteCommand
)
StderrChan
()
<-
chan
string
{
r
.
errChanLock
.
Lock
()
defer
r
.
errChanLock
.
Unlock
()
// If no channels have been made, make that slice and start
// the goroutine to read and send to them
if
r
.
errChans
==
nil
{
r
.
errChans
=
make
([]
chan
<-
string
,
0
,
5
)
go
r
.
channelReader
(
r
.
Stderr
,
&
r
.
errChans
,
&
r
.
errChanLock
)
}
// Create the channel, append it to the channels we care about
errChan
:=
make
(
chan
string
,
10
)
r
.
errChans
=
append
(
r
.
errChans
,
errChan
)
return
errChan
}
// 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.
...
...
packer/communicator_test.go
View file @
ade37951
...
...
@@ -31,6 +31,29 @@ func TestRemoteCommand_ExitChan(t *testing.T) {
}
}
func
TestRemoteCommand_StderrChan
(
t
*
testing
.
T
)
{
expected
:=
"DATA!!!"
stderrBuf
:=
new
(
bytes
.
Buffer
)
stderrBuf
.
WriteString
(
expected
)
rc
:=
&
RemoteCommand
{}
rc
.
Stderr
=
stderrBuf
errChan
:=
rc
.
StderrChan
()
results
:=
new
(
bytes
.
Buffer
)
for
data
:=
range
errChan
{
results
.
WriteString
(
data
)
}
if
results
.
String
()
!=
expected
{
t
.
Fatalf
(
"outputs didn't match:
\n
got:
\n
%s
\n
expected:
\n
%s"
,
results
.
String
(),
stderrBuf
.
String
())
}
}
func
TestRemoteCommand_StdoutChan
(
t
*
testing
.
T
)
{
expected
:=
"DATA!!!"
...
...
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