spec/symphony/tasks/sshscript_spec.rb
changeset 19 f31d60b04f8a
parent 11 ffa70066522c
equal deleted inserted replaced
18:d629b9939df4 19:f31d60b04f8a
    18 		it "can generate an appropriate tempfile name" do
    18 		it "can generate an appropriate tempfile name" do
    19 			instance = Class.new( described_class ).new( 'queue' )
    19 			instance = Class.new( described_class ).new( 'queue' )
    20 			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl" )
    20 			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl" )
    21 			expect( tmpname ).to match( %r|^/tmp/fancy-script-[[:xdigit:]]{6}| )
    21 			expect( tmpname ).to match( %r|^/tmp/fancy-script-[[:xdigit:]]{6}| )
    22 
    22 
    23 			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl", "/var/tmp" )
    23 			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl", "/var/tmp/" )
    24 			expect( tmpname ).to match( %r|/var/tmp/fancy-script-[[:xdigit:]]{6}| )
    24 			expect( tmpname ).to match( %r|/var/tmp/fancy-script-[[:xdigit:]]{6}| )
       
    25 
       
    26 			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl", '' )
       
    27 			expect( tmpname ).to match( %r|fancy-script-[[:xdigit:]]{6}| )
    25 		end
    28 		end
    26 	end
    29 	end
    27 
    30 
    28 
    31 
    29 	describe 'subclassed' do
    32 	describe 'subclassed' do
   106 				with( 'example.com', 'symphony', opts ).and_yield( conn )
   109 				with( 'example.com', 'symphony', opts ).and_yield( conn )
   107 
   110 
   108 			instance.work( payload, {} )
   111 			instance.work( payload, {} )
   109 		end
   112 		end
   110 
   113 
       
   114 		it "can override how it cleans the remote script up" do
       
   115 			payload[ 'delete_cmd' ] = 'del'
       
   116 
       
   117 			conn = double( :ssh_connection )
       
   118 			expect( instance ).to receive( :upload_script ).
       
   119 				with( conn, "Hi there, !", "/tmp/script_temp" )
       
   120 			expect( conn ).to receive( :exec! ).with( "/tmp/script_temp" )
       
   121 			expect( conn ).to receive( :exec! ).with( "del /tmp/script_temp" )
       
   122 
       
   123 			expect( Net::SSH ).to receive( :start ).
       
   124 				with( 'example.com', 'symphony', opts ).and_yield( conn )
       
   125 
       
   126 			instance.work( payload, {} )
       
   127 		end
       
   128 
       
   129 		it "can run the script with a specific interpreter" do
       
   130 			payload[ 'run_binary' ] = 'ruby'
       
   131 
       
   132 			conn = double( :ssh_connection )
       
   133 			expect( instance ).to receive( :upload_script ).
       
   134 				with( conn, "Hi there, !", "/tmp/script_temp" )
       
   135 			expect( conn ).to receive( :exec! ).with( "ruby /tmp/script_temp" )
       
   136 			expect( conn ).to receive( :exec! ).with( "rm /tmp/script_temp" )
       
   137 
       
   138 			expect( Net::SSH ).to receive( :start ).
       
   139 				with( 'example.com', 'symphony', opts ).and_yield( conn )
       
   140 
       
   141 			instance.work( payload, {} )
       
   142 		end
       
   143 
   111 		it "leaves the remote script in place if asked" do
   144 		it "leaves the remote script in place if asked" do
   112 			payload[ 'nocleanup' ] = true
   145 			payload[ 'nocleanup' ] = true
   113 
   146 
   114 			conn = double( :ssh_connection )
   147 			conn = double( :ssh_connection )
   115 			expect( instance ).to receive( :upload_script ).
   148 			expect( instance ).to receive( :upload_script ).