spec/symphony/tasks/sshscript_spec.rb
author Mahlon E. Smith <mahlon@martini.nu>
Wed, 15 Jul 2020 15:35:06 -0700
changeset 19 f31d60b04f8a
parent 11 ffa70066522c
permissions -rw-r--r--
Multiple changes to help support Windows native ssh with sshscript workers. Defaults are to assume a non-hostile posix environment. - Don't hardcode the tempdir separator character. - Allow overrides in the payload of any exposed net-ssh options. - Allow setting of the "delete" command for script cleanup (ie, 'del') - Allow running the script via a specific interpreter. An example payload to make this work with Windows native ssh/powershell to execute a ruby script: payload = { 'compression' => false, 'delete_cmd' => 'del', 'run_binary' => 'ruby', 'tempdir' => '' }
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     1
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     2
require_relative '../../helpers'
11
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     3
require 'symphony/tasks/ssh'
4
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     4
require 'symphony/tasks/sshscript'
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     5
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     6
context Symphony::Task::SSHScript do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     7
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     8
	before( :each ) do
11
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     9
		Symphony::Task::SSH.configure(
4
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    10
			key:  '/tmp/sekrit.rsa',
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    11
			user: 'symphony'
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    12
		)
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    13
	end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    14
11
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    15
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    16
	describe 'utility' do
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    17
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    18
		it "can generate an appropriate tempfile name" do
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    19
			instance = Class.new( described_class ).new( 'queue' )
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    20
			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl" )
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    21
			expect( tmpname ).to match( %r|^/tmp/fancy-script-[[:xdigit:]]{6}| )
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    22
19
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
    23
			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl", "/var/tmp/" )
11
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    24
			expect( tmpname ).to match( %r|/var/tmp/fancy-script-[[:xdigit:]]{6}| )
19
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
    25
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
    26
			tmpname = instance.send( :make_remote_filename, "fancy-script.tmpl", '' )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
    27
			expect( tmpname ).to match( %r|fancy-script-[[:xdigit:]]{6}| )
11
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    28
		end
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    29
	end
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    30
4
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    31
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    32
	describe 'subclassed' do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    33
		let( :instance ) { Class.new(described_class).new('queue') }
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    34
		let( :payload ) {
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    35
			{ 'template' => 'script', 'host' => 'example.com' }
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    36
		}
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    37
		let( :opts ) {
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    38
			opts = described_class::DEFAULT_SSH_OPTIONS
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    39
			opts.merge!(
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    40
				:port    => 22,
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    41
				:keys    => ['/tmp/sekrit.rsa']
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    42
			)
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    43
			opts
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    44
		}
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    45
		let( :template ) { Inversion::Template.new("Hi there, <?attr name?>!") }
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    46
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    47
		before( :each ) do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    48
			allow( Inversion::Template ).to receive( :load ).and_return( template )
11
ffa70066522c Update for Ruby 2.5. Moderize configurability usage, update dependencies.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    49
			allow( instance ).to receive( :make_remote_filename ).and_return( "/tmp/script_temp" )
4
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    50
		end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    51
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    52
		it "aborts if there is no template in the payload" do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    53
			expect {
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    54
				instance.work( {}, {} )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    55
			}.to raise_exception( ArgumentError, /missing required option 'template'/i )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    56
		end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    57
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    58
		it "aborts if there is no host in the payload" do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    59
			expect {
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    60
				instance.work({ 'template' => 'boop' }, {} )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    61
			}.to raise_exception( ArgumentError, /missing required option 'host'/i )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    62
		end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    63
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    64
		it "adds debugging output if specified in the payload" do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    65
			payload[ 'debug' ] = true
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    66
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    67
			options = opts.dup
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    68
			options.merge!(
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    69
				:logger  => Loggability[ Net::SSH ],
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    70
				:verbose => :debug
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    71
			)
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    72
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    73
			expect( Net::SSH ).to receive( :start ).with( 'example.com', 'symphony', options )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    74
			instance.work( payload, {} )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    75
		end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    76
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    77
		it "attaches attributes to the scripts from the payload" do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    78
			payload[ 'attributes' ] = { :name => 'Handsome' }
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    79
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    80
			conn = double( :ssh_connection )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    81
			expect( instance ).to receive( :upload_script ).
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    82
				with( conn, "Hi there, Handsome!", "/tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    83
			expect( conn ).to receive( :exec! ).with( "/tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    84
			expect( conn ).to receive( :exec! ).with( "rm /tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    85
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    86
			expect( Net::SSH ).to receive( :start ).
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    87
				with( 'example.com', 'symphony', opts ).and_yield( conn )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    88
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    89
			instance.work( payload, {} )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    90
		end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    91
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    92
		it "uploads the file and sets it executable" do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    93
			conn = double( :ssh_connection )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    94
			sftp = double( :sftp_connection )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    95
			file = double( :remote_file_obj )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    96
			fh   = double( :remote_filehandle )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    97
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    98
			expect( conn ).to receive( :sftp ).and_return( sftp )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    99
			expect( sftp ).to receive( :file ).and_return( file )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   100
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   101
			expect( file ).to receive( :open ).
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   102
				with( "/tmp/script_temp", "w", 0755 ).and_yield( fh )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   103
			expect( fh ).to receive( :print ).with( "Hi there, !" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   104
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   105
			expect( conn ).to receive( :exec! ).with( "/tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   106
			expect( conn ).to receive( :exec! ).with( "rm /tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   107
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   108
			expect( Net::SSH ).to receive( :start ).
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   109
				with( 'example.com', 'symphony', opts ).and_yield( conn )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   110
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   111
			instance.work( payload, {} )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   112
		end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   113
19
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   114
		it "can override how it cleans the remote script up" do
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   115
			payload[ 'delete_cmd' ] = 'del'
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   116
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   117
			conn = double( :ssh_connection )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   118
			expect( instance ).to receive( :upload_script ).
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   119
				with( conn, "Hi there, !", "/tmp/script_temp" )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   120
			expect( conn ).to receive( :exec! ).with( "/tmp/script_temp" )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   121
			expect( conn ).to receive( :exec! ).with( "del /tmp/script_temp" )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   122
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   123
			expect( Net::SSH ).to receive( :start ).
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   124
				with( 'example.com', 'symphony', opts ).and_yield( conn )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   125
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   126
			instance.work( payload, {} )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   127
		end
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   128
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   129
		it "can run the script with a specific interpreter" do
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   130
			payload[ 'run_binary' ] = 'ruby'
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   131
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   132
			conn = double( :ssh_connection )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   133
			expect( instance ).to receive( :upload_script ).
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   134
				with( conn, "Hi there, !", "/tmp/script_temp" )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   135
			expect( conn ).to receive( :exec! ).with( "ruby /tmp/script_temp" )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   136
			expect( conn ).to receive( :exec! ).with( "rm /tmp/script_temp" )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   137
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   138
			expect( Net::SSH ).to receive( :start ).
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   139
				with( 'example.com', 'symphony', opts ).and_yield( conn )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   140
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   141
			instance.work( payload, {} )
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   142
		end
f31d60b04f8a Multiple changes to help support Windows native ssh with sshscript workers.
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   143
4
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   144
		it "leaves the remote script in place if asked" do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   145
			payload[ 'nocleanup' ] = true
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   146
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   147
			conn = double( :ssh_connection )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   148
			expect( instance ).to receive( :upload_script ).
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   149
				with( conn, "Hi there, !", "/tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   150
			expect( conn ).to receive( :exec! ).with( "/tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   151
			expect( conn ).to_not receive( :exec! ).with( "rm /tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   152
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   153
			expect( Net::SSH ).to receive( :start ).
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   154
				with( 'example.com', 'symphony', opts ).and_yield( conn )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   155
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   156
			instance.work( payload, {} )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   157
		end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   158
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   159
		it "remembers the output of the remote script" do
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   160
			conn = double( :ssh_connection )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   161
			expect( instance ).to receive( :upload_script ).
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   162
				with( conn, "Hi there, !", "/tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   163
			expect( conn ).to receive( :exec! ).with( "/tmp/script_temp" ).and_return( "Hi there, !" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   164
			expect( conn ).to receive( :exec! ).with( "rm /tmp/script_temp" )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   165
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   166
			expect( Net::SSH ).to receive( :start ).
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   167
				with( 'example.com', 'symphony', opts ).and_yield( conn )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   168
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   169
			instance.work( payload, {} )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   170
			output = instance.instance_variable_get( :@output )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   171
			expect( output ).to eq( 'Hi there, !' )
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   172
		end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   173
	end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   174
end
3972315383b3 Small cleanups, add tests.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   175