spec/symphony/tasks/sshscript_spec.rb
changeset 11 ffa70066522c
parent 4 3972315383b3
child 19 f31d60b04f8a
equal deleted inserted replaced
10:7013280e62fa 11:ffa70066522c
     1 
     1 
     2 require_relative '../../helpers'
     2 require_relative '../../helpers'
       
     3 require 'symphony/tasks/ssh'
     3 require 'symphony/tasks/sshscript'
     4 require 'symphony/tasks/sshscript'
     4 
     5 
     5 context Symphony::Task::SSHScript do
     6 context Symphony::Task::SSHScript do
     6 
     7 
     7 	before( :each ) do
     8 	before( :each ) do
     8 		described_class.configure(
     9 		Symphony::Task::SSH.configure(
     9 			key:  '/tmp/sekrit.rsa',
    10 			key:  '/tmp/sekrit.rsa',
    10 			user: 'symphony'
    11 			user: 'symphony'
    11 		)
    12 		)
    12 	end
    13 	end
    13 
    14 
    14 	it_should_behave_like "an object with Configurability"
    15 
       
    16 	describe 'utility' do
       
    17 
       
    18 		it "can generate an appropriate tempfile name" do
       
    19 			instance = Class.new( described_class ).new( 'queue' )
       
    20 			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl" )
       
    21 			expect( tmpname ).to match( %r|^/tmp/fancy-script-[[:xdigit:]]{6}| )
       
    22 
       
    23 			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl", "/var/tmp" )
       
    24 			expect( tmpname ).to match( %r|/var/tmp/fancy-script-[[:xdigit:]]{6}| )
       
    25 		end
       
    26 	end
       
    27 
    15 
    28 
    16 	describe 'subclassed' do
    29 	describe 'subclassed' do
    17 		let( :instance ) { Class.new(described_class).new('queue') }
    30 		let( :instance ) { Class.new(described_class).new('queue') }
    18 		let( :payload ) {
    31 		let( :payload ) {
    19 			{ 'template' => 'script', 'host' => 'example.com' }
    32 			{ 'template' => 'script', 'host' => 'example.com' }
    28 		}
    41 		}
    29 		let( :template ) { Inversion::Template.new("Hi there, <?attr name?>!") }
    42 		let( :template ) { Inversion::Template.new("Hi there, <?attr name?>!") }
    30 
    43 
    31 		before( :each ) do
    44 		before( :each ) do
    32 			allow( Inversion::Template ).to receive( :load ).and_return( template )
    45 			allow( Inversion::Template ).to receive( :load ).and_return( template )
    33 			allow( Dir::Tmpname ).to receive( :make_tmpname ).and_return( "script_temp" )
    46 			allow( instance ).to receive( :make_remote_filename ).and_return( "/tmp/script_temp" )
    34 		end
    47 		end
    35 
    48 
    36 		it "aborts if there is no template in the payload" do
    49 		it "aborts if there is no template in the payload" do
    37 			expect {
    50 			expect {
    38 				instance.work( {}, {} )
    51 				instance.work( {}, {} )