Forward standard error stream from remote execution
This commit is contained in:
@@ -19,6 +19,15 @@ module Producer::Core
|
||||
sh.apply
|
||||
expect(output).to eq "#{command_args}\n"
|
||||
end
|
||||
|
||||
context 'when content is written to standard error' do
|
||||
let(:command) { "echo #{command_args} >&2" }
|
||||
|
||||
it 'writes errors to given error stream' do
|
||||
sh.apply
|
||||
expect(error_output).to eq "#{command_args}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -12,7 +12,9 @@ module Producer::Core
|
||||
let(:stdout) { StringIO.new }
|
||||
let(:stderr) { StringIO.new }
|
||||
|
||||
subject(:cli) { CLI.new(arguments, stdin: stdin, stdout: stdout) }
|
||||
subject(:cli) { described_class.new(
|
||||
arguments,
|
||||
stdin: stdin, stdout: stdout, stderr: stderr) }
|
||||
|
||||
describe '.run!' do
|
||||
let(:cli) { double('cli').as_null_object }
|
||||
@@ -118,6 +120,10 @@ module Producer::Core
|
||||
it 'assigns CLI stdout as the env output' do
|
||||
expect(cli.env.output).to be stdout
|
||||
end
|
||||
|
||||
it 'assigns CLI stderr as the env error output' do
|
||||
expect(cli.env.error_output).to be stderr
|
||||
end
|
||||
end
|
||||
|
||||
describe '#parse_arguments!' do
|
||||
|
@@ -10,6 +10,10 @@ module Producer::Core
|
||||
expect(env.input).to be $stdin
|
||||
end
|
||||
|
||||
it 'assigns $stderr as the default error output' do
|
||||
expect(env.error_output).to be $stderr
|
||||
end
|
||||
|
||||
it 'assigns no default target' do
|
||||
expect(env.target).not_to be
|
||||
end
|
||||
@@ -51,6 +55,15 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
context 'when error output is given as argument' do
|
||||
let(:error_output) { StringIO.new }
|
||||
subject(:env) { described_class.new(error_output: error_output) }
|
||||
|
||||
it 'assigns the given error output' do
|
||||
expect(env.error_output).to be error_output
|
||||
end
|
||||
end
|
||||
|
||||
context 'when remote is given as argument' do
|
||||
let(:remote) { double 'remote' }
|
||||
subject(:env) { described_class.new(remote: remote) }
|
||||
|
@@ -106,6 +106,16 @@ module Producer::Core
|
||||
expect(output.string).to eq arguments
|
||||
end
|
||||
|
||||
it 'writes command error output to provided error output' do
|
||||
error_output = StringIO.new
|
||||
story_with_new_channel do |ch|
|
||||
ch.sends_exec command
|
||||
ch.gets_extended_data arguments
|
||||
end
|
||||
remote.execute command, output, error_output
|
||||
expect(error_output.string).to eq arguments
|
||||
end
|
||||
|
||||
context 'when command execution fails' do
|
||||
before do
|
||||
story_with_new_channel do |ch|
|
||||
|
@@ -29,6 +29,12 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
describe '#error_output' do
|
||||
it 'returns env error output' do
|
||||
expect(action.error_output).to be env.error_output
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remote' do
|
||||
it 'returns env remote' do
|
||||
expect(action.remote).to be env.remote
|
||||
|
@@ -9,6 +9,10 @@ module TestEnvHelpers
|
||||
env.output.string
|
||||
end
|
||||
|
||||
def error_output
|
||||
env.error_output.string
|
||||
end
|
||||
|
||||
def remote_fs
|
||||
env.remote.fs
|
||||
end
|
||||
@@ -17,14 +21,18 @@ module TestEnvHelpers
|
||||
opts = { expected_from: caller.first }
|
||||
RSpec::Mocks
|
||||
.expect_message(env.remote, :execute, opts)
|
||||
.with(command, env.output)
|
||||
.with(command, env.output, env.error_output)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def build_env
|
||||
Producer::Core::Env.new(output: StringIO.new, remote: build_remote)
|
||||
Producer::Core::Env.new(
|
||||
output: StringIO.new,
|
||||
error_output: StringIO.new,
|
||||
remote: build_remote
|
||||
)
|
||||
end
|
||||
|
||||
def build_remote
|
||||
|
Reference in New Issue
Block a user