4
|
1 |
|
|
2 |
require_relative '../../helpers'
|
|
3 |
require 'symphony/tasks/ssh'
|
|
4 |
|
|
5 |
context Symphony::Task::SSH do
|
|
6 |
let( :ssh ) { (Pathname( __FILE__ ).dirname.parent.parent + 'fake_ssh').realpath }
|
|
7 |
|
|
8 |
before( :each ) do
|
|
9 |
described_class.configure(
|
|
10 |
path: ssh.to_s,
|
|
11 |
key: '/tmp/sekrit.rsa',
|
|
12 |
user: 'symphony'
|
|
13 |
)
|
|
14 |
end
|
|
15 |
|
|
16 |
it_should_behave_like "an object with Configurability"
|
|
17 |
|
|
18 |
describe 'subclassed' do
|
|
19 |
let( :instance ) { Class.new(described_class).new('queue') }
|
|
20 |
let( :payload ) {
|
|
21 |
{ 'command' => 'woohoo', 'host' => 'example.com' }
|
|
22 |
}
|
|
23 |
|
|
24 |
it "aborts if there is no command in the payload" do
|
|
25 |
expect {
|
|
26 |
instance.work( {}, {} )
|
|
27 |
}.to raise_exception( ArgumentError, /missing required option 'command'/i )
|
|
28 |
end
|
|
29 |
|
|
30 |
it "aborts if there is no host in the payload" do
|
|
31 |
expect {
|
|
32 |
instance.work({ 'command' => 'boop' }, {} )
|
|
33 |
}.to raise_exception( ArgumentError, /missing required option 'host'/i )
|
|
34 |
end
|
|
35 |
|
|
36 |
it "builds the proper command line" do
|
|
37 |
pipe = double( :fake_pipes ).as_null_object
|
|
38 |
allow( IO ).to receive( :pipe ).and_return([ pipe, pipe ])
|
|
39 |
|
|
40 |
args = [
|
|
41 |
'-p', '22', '-i', '/tmp/sekrit.rsa', '-l', 'symphony', 'example.com'
|
|
42 |
]
|
|
43 |
|
|
44 |
expect( Process ).to receive( :spawn ).with(
|
|
45 |
*[ ssh.to_s, described_class.opts, args ].flatten,
|
|
46 |
:out => pipe, :in => pipe, :close_others => true
|
|
47 |
).and_return( 12 )
|
|
48 |
|
|
49 |
expect( Process ).to receive( :waitpid2 ).with( 12 ).and_return([ 12, 1 ])
|
|
50 |
|
|
51 |
code = instance.work( payload, {} )
|
|
52 |
expect( code ).to eq( 1 )
|
|
53 |
end
|
|
54 |
|
|
55 |
it "execs and captures output" do
|
|
56 |
code = instance.work( payload, {} )
|
|
57 |
expect( code ).to eq( 0 )
|
|
58 |
|
|
59 |
output = instance.instance_variable_get( :@output )
|
|
60 |
expect( output ).to eq( 'Hi there!' )
|
|
61 |
end
|
|
62 |
end
|
|
63 |
end
|
|
64 |
|