beaker 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,30 @@ module Beaker
45
45
  expect(options[:key]).to be === nil
46
46
  end
47
47
 
48
+ describe '#get_type' do
49
+ let(:options) { Beaker::Options::OptionsHash.new }
50
+
51
+ it 'returns pe as expected in the normal case' do
52
+ newhash = options.merge({:type => 'pe'})
53
+ expect(newhash.get_type).to be === :pe
54
+ end
55
+
56
+ it 'returns foss as expected in the normal case' do
57
+ newhash = options.merge({:type => 'foss'})
58
+ expect(newhash.get_type).to be === :foss
59
+ end
60
+
61
+ it 'returns aio as expected in the normal case' do
62
+ newhash = options.merge({:type => 'aio'})
63
+ expect(newhash.get_type).to be === :aio
64
+ end
65
+
66
+ it 'returns foss as the default' do
67
+ newhash = options.merge({:type => 'git'})
68
+ expect(newhash.get_type).to be === :foss
69
+ end
70
+ end
71
+
48
72
  context 'pretty prints itself' do
49
73
 
50
74
  it 'in valid JSON' do
@@ -57,13 +57,191 @@ module Beaker
57
57
  connection.close
58
58
  end
59
59
 
60
- it 'execute'
61
- it 'request_terminal_for'
62
- it 'register_stdout_for'
63
- it 'register_stderr_for'
64
- it 'register_exit_code_for'
65
- it 'process_stdin_for'
66
- it 'scp'
60
+ describe '#execute' do
61
+ it 'retries if failed with a retryable exception' do
62
+ mock_ssh = Object.new
63
+ expect( Net::SSH ).to receive( :start ).with( host, user, ssh_opts) { mock_ssh }
64
+ connection.connect
65
+
66
+ allow( subject ).to receive( :close )
67
+ expect( subject ).to receive( :try_to_execute ).ordered.once { raise Timeout::Error }
68
+ expect( subject ).to receive( :try_to_execute ).ordered.once { Beaker::Result.new('name', 'ls') }
69
+ expect( subject ).to_not receive( :try_to_execute )
70
+ connection.execute('ls')
71
+ end
72
+
73
+ it 'raises an error if it fails both times' do
74
+ mock_ssh = Object.new
75
+ expect( Net::SSH ).to receive( :start ).with( host, user, ssh_opts) { mock_ssh }
76
+ connection.connect
77
+
78
+ allow( subject ).to receive( :close )
79
+ allow( subject ).to receive( :try_to_execute ) { raise Timeout::Error }
80
+
81
+ expect{ connection.execute('ls') }.to raise_error
82
+ end
83
+ end
84
+
85
+ describe '#request_terminal_for' do
86
+ it 'fails correctly by calling the abort method' do
87
+ mock_ssh = Object.new
88
+ expect( Net::SSH ).to receive( :start ).with( host, user, ssh_opts) { mock_ssh }
89
+ connection.connect
90
+
91
+ mock_channel = Object.new
92
+ allow( mock_channel ).to receive( :request_pty ).and_yield(nil, false)
93
+
94
+ expect( subject ).to receive( :abort ).once
95
+ connection.request_terminal_for mock_channel, 'ls'
96
+ end
97
+ end
98
+
99
+ describe '#register_stdout_for' do
100
+ before :each do
101
+ @mock_ssh = Object.new
102
+ expect( Net::SSH ).to receive( :start ).with( host, user, ssh_opts) { @mock_ssh }
103
+ connection.connect
104
+
105
+ @data = '7 of clubs'
106
+ @mock_channel = Object.new
107
+ allow( @mock_channel ).to receive( :on_data ).and_yield(nil, @data)
108
+
109
+ @mock_output = Object.new
110
+ @mock_output_stdout = Object.new
111
+ @mock_output_output = Object.new
112
+ allow( @mock_output ).to receive( :stdout ) { @mock_output_stdout }
113
+ allow( @mock_output ).to receive( :output ) { @mock_output_output }
114
+ allow( @mock_output_stdout ).to receive( :<< )
115
+ allow( @mock_output_output ).to receive( :<< )
116
+ end
117
+
118
+ it 'puts data into stdout & output correctly' do
119
+ expect( @mock_output_stdout ).to receive( :<< ).with(@data)
120
+ expect( @mock_output_output ).to receive( :<< ).with(@data)
121
+
122
+ connection.register_stdout_for @mock_channel, @mock_output
123
+ end
124
+
125
+ it 'calls the callback if given' do
126
+ @mock_callback = Object.new
127
+ expect( @mock_callback ).to receive( :[] ).with(@data)
128
+
129
+ connection.register_stdout_for @mock_channel, @mock_output, @mock_callback
130
+ end
131
+ end
132
+
133
+ describe '#register_stderr_for' do
134
+ let( :result ) { Beaker::Result.new('hostname', 'command') }
135
+
136
+ before :each do
137
+ @mock_ssh = Object.new
138
+ expect( Net::SSH ).to receive( :start ).with( host, user, ssh_opts) { @mock_ssh }
139
+ connection.connect
140
+
141
+ @data = '3 of spades'
142
+ @mock_channel = Object.new
143
+ allow( @mock_channel ).to receive( :on_extended_data ).and_yield(nil, 1, @data)
144
+ end
145
+
146
+ it 'puts data into stderr & output correctly' do
147
+ expect( result.stderr ).to receive( :<< ).with(@data)
148
+ expect( result.output ).to receive( :<< ).with(@data)
149
+
150
+ connection.register_stderr_for @mock_channel, result
151
+ end
152
+
153
+ it 'calls the callback if given' do
154
+ @mock_callback = Object.new
155
+ expect( @mock_callback ).to receive( :[] ).with(@data)
156
+
157
+ connection.register_stderr_for @mock_channel, result, @mock_callback
158
+ end
159
+
160
+ it 'skips everything if type is not 1' do
161
+ allow( @mock_channel ).to receive( :on_extended_data ).and_yield(nil, '1', @data)
162
+
163
+ @mock_callback = Object.new
164
+ expect( @mock_callback ).to_not receive( :[] )
165
+ expect( result.stderr ).to_not receive( :<< )
166
+ expect( result.output ).to_not receive( :<< )
167
+
168
+ connection.register_stderr_for @mock_channel, result, @mock_callback
169
+ end
170
+ end
171
+
172
+ describe '#register_exit_code_for' do
173
+ let( :result ) { Beaker::Result.new('hostname', 'command') }
174
+
175
+ it 'assigns the output\'s exit code correctly from the data' do
176
+ mock_ssh = Object.new
177
+ expect( Net::SSH ).to receive( :start ).with( host, user, ssh_opts) { mock_ssh }
178
+ connection.connect
179
+
180
+ data = '10 of jeromes'
181
+ mock_data = Object.new
182
+ allow( mock_data ).to receive( :read_long ) { data }
183
+ mock_channel = Object.new
184
+ allow( mock_channel ).to receive( :on_request ).with('exit-status').and_yield(nil, mock_data)
185
+
186
+ connection.register_exit_code_for mock_channel, result
187
+ expect( result.exit_code ).to be === data
188
+ end
189
+ end
190
+
191
+ describe 'process_stdin_for' do
192
+ it 'calls the correct channel methods in order' do
193
+ stdin = 'jean shorts'
194
+ mock_channel = Object.new
195
+
196
+ expect( mock_channel ).to receive( :send_data ).with(stdin).ordered.once
197
+ expect( mock_channel ).to receive( :process ).ordered.once
198
+ expect( mock_channel ).to receive( :eof! ).ordered.once
199
+
200
+ connection.process_stdin_for mock_channel, stdin
201
+ end
202
+ end
203
+
204
+ describe '#scp_to' do
205
+ before :each do
206
+ @mock_ssh = Object.new
207
+ @mock_scp = Object.new
208
+ allow( @mock_scp ).to receive( :upload! )
209
+ allow( @mock_ssh ).to receive( :scp ).and_return( @mock_scp )
210
+ expect( Net::SSH ).to receive( :start ).with( host, user, ssh_opts) { @mock_ssh }
211
+ connection.connect
212
+ end
213
+
214
+ it 'calls scp.upload!' do
215
+ expect( @mock_scp ).to receive( :upload! ).once
216
+ connection.scp_to '', ''
217
+ end
218
+
219
+ it 'returns a result object' do
220
+ expect( connection.scp_to '', '' ).to be_a_kind_of Beaker::Result
221
+ end
222
+
223
+ end
224
+
225
+ describe '#scp_from' do
226
+ before :each do
227
+ @mock_ssh = Object.new
228
+ @mock_scp = Object.new
229
+ allow( @mock_scp ).to receive( :download! )
230
+ allow( @mock_ssh ).to receive( :scp ).and_return( @mock_scp )
231
+ expect( Net::SSH ).to receive( :start ).with( host, user, ssh_opts) { @mock_ssh }
232
+ connection.connect
233
+ end
234
+
235
+ it 'calls scp.download!' do
236
+ expect( @mock_scp ).to receive( :download! ).once
237
+ connection.scp_from '', ''
238
+ end
239
+
240
+ it 'returns a result object' do
241
+ expect( connection.scp_from '', '' ).to be_a_kind_of Beaker::Result
242
+ end
243
+
244
+ end
67
245
 
68
246
  end
69
247
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppetlabs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-17 00:00:00.000000000 Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec