test-kitchen 1.3.1 → 1.4.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cane +2 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +45 -0
- data/Rakefile +15 -0
- data/features/kitchen_action_commands.feature +12 -9
- data/features/kitchen_defaults.feature +38 -0
- data/features/kitchen_init_command.feature +0 -1
- data/features/kitchen_list_command.feature +2 -2
- data/features/kitchen_login_command.feature +7 -1
- data/features/kitchen_test_command.feature +4 -4
- data/lib/kitchen.rb +40 -11
- data/lib/kitchen/cli.rb +38 -22
- data/lib/kitchen/command/list.rb +5 -2
- data/lib/kitchen/config.rb +45 -18
- data/lib/kitchen/configurable.rb +137 -1
- data/lib/kitchen/data_munger.rb +248 -17
- data/lib/kitchen/driver.rb +1 -1
- data/lib/kitchen/driver/base.rb +1 -83
- data/lib/kitchen/driver/dummy.rb +0 -5
- data/lib/kitchen/driver/ssh_base.rb +177 -22
- data/lib/kitchen/instance.rb +140 -20
- data/lib/kitchen/logger.rb +43 -8
- data/lib/kitchen/login_command.rb +14 -5
- data/lib/kitchen/platform.rb +19 -0
- data/lib/kitchen/provisioner.rb +5 -3
- data/lib/kitchen/provisioner/base.rb +46 -48
- data/lib/kitchen/provisioner/chef/common_sandbox.rb +322 -0
- data/lib/kitchen/provisioner/chef_base.rb +179 -286
- data/lib/kitchen/provisioner/chef_solo.rb +11 -5
- data/lib/kitchen/provisioner/chef_zero.rb +108 -94
- data/lib/kitchen/provisioner/dummy.rb +47 -0
- data/lib/kitchen/provisioner/shell.rb +45 -12
- data/lib/kitchen/rake_tasks.rb +1 -1
- data/lib/kitchen/ssh.rb +1 -1
- data/lib/kitchen/thor_tasks.rb +1 -1
- data/lib/kitchen/transport.rb +54 -0
- data/lib/kitchen/transport/base.rb +146 -0
- data/lib/kitchen/transport/dummy.rb +75 -0
- data/lib/kitchen/transport/ssh.rb +325 -0
- data/lib/kitchen/transport/winrm.rb +508 -0
- data/lib/kitchen/transport/winrm/command_executor.rb +188 -0
- data/lib/kitchen/transport/winrm/file_transporter.rb +454 -0
- data/lib/kitchen/transport/winrm/logging.rb +50 -0
- data/lib/kitchen/transport/winrm/template.rb +74 -0
- data/lib/kitchen/transport/winrm/tmp_zip.rb +187 -0
- data/lib/kitchen/verifier.rb +55 -0
- data/lib/kitchen/verifier/base.rb +191 -0
- data/lib/kitchen/verifier/busser.rb +266 -0
- data/lib/kitchen/verifier/dummy.rb +75 -0
- data/lib/kitchen/version.rb +1 -1
- data/spec/kitchen/cli_spec.rb +56 -0
- data/spec/kitchen/config_spec.rb +61 -20
- data/spec/kitchen/configurable_spec.rb +327 -1
- data/spec/kitchen/data_munger_spec.rb +777 -14
- data/spec/kitchen/driver/base_spec.rb +7 -38
- data/spec/kitchen/driver/dummy_spec.rb +0 -29
- data/spec/kitchen/driver/ssh_base_spec.rb +580 -236
- data/spec/kitchen/driver_spec.rb +1 -0
- data/spec/kitchen/instance_spec.rb +383 -83
- data/spec/kitchen/login_command_spec.rb +29 -10
- data/spec/kitchen/platform_spec.rb +58 -2
- data/spec/kitchen/provisioner/base_spec.rb +170 -18
- data/spec/kitchen/provisioner/chef_base_spec.rb +454 -104
- data/spec/kitchen/provisioner/chef_solo_spec.rb +307 -104
- data/spec/kitchen/provisioner/chef_zero_spec.rb +561 -230
- data/spec/kitchen/provisioner/dummy_spec.rb +91 -0
- data/spec/kitchen/provisioner/shell_spec.rb +158 -56
- data/spec/kitchen/provisioner_spec.rb +37 -0
- data/spec/kitchen/ssh_spec.rb +19 -19
- data/spec/kitchen/transport/base_spec.rb +89 -0
- data/spec/kitchen/transport/ssh_spec.rb +1147 -0
- data/spec/kitchen/transport/winrm/command_executor_spec.rb +400 -0
- data/spec/kitchen/transport/winrm/file_transporter_spec.rb +876 -0
- data/spec/kitchen/transport/winrm/logging_spec.rb +92 -0
- data/spec/kitchen/transport/winrm/template_spec.rb +51 -0
- data/spec/kitchen/transport/winrm/tmp_zip_spec.rb +132 -0
- data/spec/kitchen/transport/winrm_spec.rb +1069 -0
- data/spec/kitchen/transport_spec.rb +112 -0
- data/spec/kitchen/verifier/base_spec.rb +310 -0
- data/spec/kitchen/verifier/busser_spec.rb +540 -0
- data/spec/kitchen/verifier/dummy_spec.rb +91 -0
- data/spec/kitchen/verifier_spec.rb +120 -0
- data/spec/kitchen_spec.rb +7 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/powershell_max_size_spec.rb +40 -0
- data/support/busser_install_command.ps1 +14 -0
- data/support/busser_install_command.sh +15 -0
- data/support/check_files.ps1.erb +48 -0
- data/support/chef_base_init_command.ps1 +18 -0
- data/support/chef_base_init_command.sh +2 -0
- data/support/chef_base_install_command.ps1 +76 -0
- data/support/chef_base_install_command.sh +137 -0
- data/support/chef_zero_prepare_command_legacy.ps1 +9 -0
- data/support/chef_zero_prepare_command_legacy.sh +10 -0
- data/support/decode_files.ps1.erb +61 -0
- data/test-kitchen.gemspec +2 -0
- metadata +97 -8
- data/lib/kitchen/busser.rb +0 -316
- data/spec/kitchen/busser_spec.rb +0 -490
- data/support/chef_helpers.sh +0 -16
@@ -31,7 +31,7 @@ module Kitchen
|
|
31
31
|
|
32
32
|
class Dodgy < Base
|
33
33
|
|
34
|
-
no_parallel_for :
|
34
|
+
no_parallel_for :setup
|
35
35
|
end
|
36
36
|
|
37
37
|
class Slow < Base
|
@@ -70,27 +70,6 @@ describe Kitchen::Driver::Base do
|
|
70
70
|
driver.instance.must_equal instance
|
71
71
|
end
|
72
72
|
|
73
|
-
it "#name returns the name of the driver" do
|
74
|
-
driver.name.must_equal "Base"
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#logger" do
|
78
|
-
|
79
|
-
before { @klog = Kitchen.logger }
|
80
|
-
after { Kitchen.logger = @klog }
|
81
|
-
|
82
|
-
it "returns the instance's logger if defined" do
|
83
|
-
driver.send(:logger).must_equal logger
|
84
|
-
end
|
85
|
-
|
86
|
-
it "returns the default logger if instance's logger is not set" do
|
87
|
-
driver = Kitchen::Driver::Base.new(config)
|
88
|
-
Kitchen.logger = "yep"
|
89
|
-
|
90
|
-
driver.send(:logger).must_equal Kitchen.logger
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
73
|
it "#puts calls logger.info" do
|
95
74
|
driver.send(:puts, "yo")
|
96
75
|
|
@@ -105,26 +84,16 @@ describe Kitchen::Driver::Base do
|
|
105
84
|
logged_output.string.must_match(/yo\n/)
|
106
85
|
end
|
107
86
|
|
108
|
-
[:create, :
|
87
|
+
[:create, :setup, :verify, :destroy].each do |action|
|
109
88
|
|
110
89
|
it "has a #{action} method that takes state" do
|
111
|
-
|
112
|
-
|
90
|
+
# TODO: revert back
|
91
|
+
# state = Hash.new
|
92
|
+
# driver.public_send(action, state).must_be_nil
|
93
|
+
driver.respond_to?(action)
|
113
94
|
end
|
114
95
|
end
|
115
96
|
|
116
|
-
it "has a login command that raises ActionFailed by default" do
|
117
|
-
proc { driver.login_command(Hash.new) }.must_raise Kitchen::ActionFailed
|
118
|
-
end
|
119
|
-
|
120
|
-
it "has a default verify dependencies method" do
|
121
|
-
driver.verify_dependencies.must_be_nil
|
122
|
-
end
|
123
|
-
|
124
|
-
it "#busser returns the instance's busser" do
|
125
|
-
driver.send(:busser).must_equal busser
|
126
|
-
end
|
127
|
-
|
128
97
|
describe ".no_parallel_for" do
|
129
98
|
|
130
99
|
it "registers no serial actions when none are declared" do
|
@@ -132,7 +101,7 @@ describe Kitchen::Driver::Base do
|
|
132
101
|
end
|
133
102
|
|
134
103
|
it "registers a single serial action method" do
|
135
|
-
Kitchen::Driver::Dodgy.serial_actions.must_equal [:
|
104
|
+
Kitchen::Driver::Dodgy.serial_actions.must_equal [:setup]
|
136
105
|
end
|
137
106
|
|
138
107
|
it "registers multiple serial action methods" do
|
@@ -95,35 +95,6 @@ describe Kitchen::Driver::Dummy do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
describe "#converge" do
|
99
|
-
|
100
|
-
it "calls sleep if :sleep value is greater than 0" do
|
101
|
-
config[:sleep] = 12.5
|
102
|
-
driver.expects(:sleep).with(12.5).returns(true)
|
103
|
-
|
104
|
-
driver.create(state)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "raises ActionFailed if :fail_converge is set" do
|
108
|
-
config[:fail_converge] = true
|
109
|
-
|
110
|
-
proc { driver.converge(state) }.must_raise Kitchen::ActionFailed
|
111
|
-
end
|
112
|
-
|
113
|
-
it "randomly raises ActionFailed if :random_failure is set" do
|
114
|
-
config[:random_failure] = true
|
115
|
-
driver.stubs(:randomly_fail?).returns(true)
|
116
|
-
|
117
|
-
proc { driver.converge(state) }.must_raise Kitchen::ActionFailed
|
118
|
-
end
|
119
|
-
|
120
|
-
it "logs a converge event to INFO" do
|
121
|
-
driver.converge(state)
|
122
|
-
|
123
|
-
logged_output.string.must_match(/^.+ INFO .+ \[Dummy\] Converge on .+$/)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
98
|
describe "#setup" do
|
128
99
|
|
129
100
|
it "calls sleep if :sleep value is greater than 0" do
|
@@ -19,6 +19,41 @@
|
|
19
19
|
require_relative "../../spec_helper"
|
20
20
|
|
21
21
|
require "kitchen"
|
22
|
+
require "kitchen/transport/ssh"
|
23
|
+
require "kitchen/verifier/busser"
|
24
|
+
|
25
|
+
module Kitchen
|
26
|
+
|
27
|
+
module Driver
|
28
|
+
|
29
|
+
class BackCompat < Kitchen::Driver::SSHBase
|
30
|
+
|
31
|
+
def use_run_remote(state, command)
|
32
|
+
connection = Kitchen::SSH.new(*build_ssh_args(state))
|
33
|
+
run_remote(command, connection)
|
34
|
+
end
|
35
|
+
|
36
|
+
def use_transfer_path(state, locals, remote)
|
37
|
+
connection = Kitchen::SSH.new(*build_ssh_args(state))
|
38
|
+
transfer_path(locals, remote, connection)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class SpeedyCompat < Kitchen::Driver::SSHBase
|
43
|
+
end
|
44
|
+
|
45
|
+
class DodgyCompat < Kitchen::Driver::SSHBase
|
46
|
+
|
47
|
+
no_parallel_for :converge
|
48
|
+
end
|
49
|
+
|
50
|
+
class SlowCompat < Kitchen::Driver::SSHBase
|
51
|
+
|
52
|
+
no_parallel_for :create, :destroy
|
53
|
+
no_parallel_for :verify
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
22
57
|
|
23
58
|
describe Kitchen::Driver::SSHBase do
|
24
59
|
|
@@ -27,12 +62,18 @@ describe Kitchen::Driver::SSHBase do
|
|
27
62
|
let(:config) { Hash.new }
|
28
63
|
let(:state) { Hash.new }
|
29
64
|
|
30
|
-
let(:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
)
|
65
|
+
let(:verifier) do
|
66
|
+
v = mock("busser")
|
67
|
+
v.responds_like_instance_of(Kitchen::Verifier::Busser)
|
68
|
+
v.stubs(:install_command).returns("install")
|
69
|
+
v.stubs(:init_command).returns("init")
|
70
|
+
v.stubs(:prepare_command).returns("prepare")
|
71
|
+
v.stubs(:run_command).returns("run")
|
72
|
+
v.stubs(:create_sandbox).returns(true)
|
73
|
+
v.stubs(:cleanup_sandbox).returns(true)
|
74
|
+
v.stubs(:sandbox_path).returns("/tmp/sandbox")
|
75
|
+
v.stubs(:[]).with(:root_path).returns("/tmp/verifier")
|
76
|
+
v
|
36
77
|
end
|
37
78
|
|
38
79
|
let(:provisioner) do
|
@@ -47,12 +88,19 @@ describe Kitchen::Driver::SSHBase do
|
|
47
88
|
)
|
48
89
|
end
|
49
90
|
|
91
|
+
let(:transport) do
|
92
|
+
t = mock("transport")
|
93
|
+
t.responds_like_instance_of(Kitchen::Transport::Base)
|
94
|
+
t
|
95
|
+
end
|
96
|
+
|
50
97
|
let(:instance) do
|
51
98
|
stub(
|
52
99
|
:name => "coolbeans",
|
53
100
|
:logger => logger,
|
54
|
-
:
|
101
|
+
:verifier => verifier,
|
55
102
|
:provisioner => provisioner,
|
103
|
+
:transport => transport,
|
56
104
|
:to_str => "instance"
|
57
105
|
)
|
58
106
|
end
|
@@ -81,100 +129,48 @@ describe Kitchen::Driver::SSHBase do
|
|
81
129
|
end
|
82
130
|
|
83
131
|
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
84
|
-
def self.
|
85
|
-
describe "constructs an SSH
|
132
|
+
def self.constructs_an_ssh_connection
|
133
|
+
describe "constructs an SSH connection" do
|
86
134
|
|
87
135
|
it "with hostname set from state" do
|
88
|
-
|
89
|
-
hostname.must_equal "fizzy"
|
136
|
+
transport.expects(:connection).with { |state|
|
137
|
+
state[:hostname].must_equal "fizzy"
|
90
138
|
}.returns(stub(:login_command => stub))
|
91
139
|
|
92
140
|
cmd
|
93
141
|
end
|
94
142
|
|
95
143
|
it "with username set from state" do
|
96
|
-
|
97
|
-
username.must_equal "bork"
|
98
|
-
}.returns(stub(:login_command => stub))
|
99
|
-
|
100
|
-
cmd
|
101
|
-
end
|
102
|
-
|
103
|
-
it "with :user_known_hosts_file option set to /dev/null" do
|
104
|
-
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
105
|
-
opts[:user_known_hosts_file].must_equal "/dev/null"
|
106
|
-
}.returns(stub(:login_command => stub))
|
107
|
-
|
108
|
-
cmd
|
109
|
-
end
|
110
|
-
|
111
|
-
it "with :paranoid option set to false" do
|
112
|
-
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
113
|
-
opts[:paranoid].must_equal false
|
114
|
-
}.returns(stub(:login_command => stub))
|
115
|
-
|
116
|
-
cmd
|
117
|
-
end
|
118
|
-
|
119
|
-
it "with :keys_only option set to falsey by default" do
|
120
|
-
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
121
|
-
opts[:keys_only].nil?
|
122
|
-
}.returns(stub(:login_command => stub))
|
123
|
-
|
124
|
-
cmd
|
125
|
-
end
|
126
|
-
|
127
|
-
it "with :keys_only option set to true if :ssh_key is set in config" do
|
128
|
-
config[:ssh_key] = "wicked"
|
129
|
-
|
130
|
-
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
131
|
-
opts[:keys_only].must_equal true
|
144
|
+
transport.expects(:connection).with { |state|
|
145
|
+
state[:username].must_equal "bork"
|
132
146
|
}.returns(stub(:login_command => stub))
|
133
147
|
|
134
148
|
cmd
|
135
149
|
end
|
136
150
|
|
137
|
-
it "with :
|
138
|
-
state[:ssh_key] = "wicked"
|
139
|
-
|
140
|
-
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
141
|
-
opts[:keys_only].must_equal true
|
142
|
-
}.returns(stub(:login_command => stub))
|
143
|
-
|
144
|
-
cmd
|
145
|
-
end
|
146
|
-
|
147
|
-
it "with :keys option set to falsey by default" do
|
148
|
-
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
149
|
-
opts[:keys].nil?
|
150
|
-
}.returns(stub(:login_command => stub))
|
151
|
-
|
152
|
-
cmd
|
153
|
-
end
|
154
|
-
|
155
|
-
it "with :keys option set to an array if :ssh_key is set in config" do
|
151
|
+
it "with :ssh_key option set from config" do
|
156
152
|
config[:ssh_key] = "wicked"
|
157
153
|
|
158
|
-
|
159
|
-
|
154
|
+
transport.expects(:connection).with { |state|
|
155
|
+
state[:ssh_key].must_equal "wicked"
|
160
156
|
}.returns(stub(:login_command => stub))
|
161
157
|
|
162
158
|
cmd
|
163
159
|
end
|
164
160
|
|
165
|
-
it "with :
|
161
|
+
it "with :ssh_key option set from state" do
|
166
162
|
state[:ssh_key] = "wicked"
|
167
163
|
|
168
|
-
|
169
|
-
|
164
|
+
transport.expects(:connection).with { |state|
|
165
|
+
state[:ssh_key].must_equal "wicked"
|
170
166
|
}.returns(stub(:login_command => stub))
|
171
167
|
|
172
168
|
cmd
|
173
169
|
end
|
174
170
|
|
175
171
|
it "with :password option set to falsey by default" do
|
176
|
-
|
177
|
-
|
172
|
+
transport.expects(:connection).with { |state|
|
173
|
+
state[:password].nil?
|
178
174
|
}.returns(stub(:login_command => stub))
|
179
175
|
|
180
176
|
cmd
|
@@ -183,8 +179,8 @@ describe Kitchen::Driver::SSHBase do
|
|
183
179
|
it "with :password option set if given in config" do
|
184
180
|
config[:password] = "psst"
|
185
181
|
|
186
|
-
|
187
|
-
|
182
|
+
transport.expects(:connection).with { |state|
|
183
|
+
state[:password].must_equal "psst"
|
188
184
|
}.returns(stub(:login_command => stub))
|
189
185
|
|
190
186
|
cmd
|
@@ -193,16 +189,16 @@ describe Kitchen::Driver::SSHBase do
|
|
193
189
|
it "with :password option set if given in state" do
|
194
190
|
state[:password] = "psst"
|
195
191
|
|
196
|
-
|
197
|
-
|
192
|
+
transport.expects(:connection).with { |state|
|
193
|
+
state[:password].must_equal "psst"
|
198
194
|
}.returns(stub(:login_command => stub))
|
199
195
|
|
200
196
|
cmd
|
201
197
|
end
|
202
198
|
|
203
199
|
it "with :forward_agent option set to falsey by default" do
|
204
|
-
|
205
|
-
|
200
|
+
transport.expects(:connection).with { |state|
|
201
|
+
state[:forward_agent].nil?
|
206
202
|
}.returns(stub(:login_command => stub))
|
207
203
|
|
208
204
|
cmd
|
@@ -211,8 +207,8 @@ describe Kitchen::Driver::SSHBase do
|
|
211
207
|
it "with :forward_agent option set if given in config" do
|
212
208
|
config[:forward_agent] = "yeah?"
|
213
209
|
|
214
|
-
|
215
|
-
|
210
|
+
transport.expects(:connection).with { |state|
|
211
|
+
state[:forward_agent].must_equal "yeah?"
|
216
212
|
}.returns(stub(:login_command => stub))
|
217
213
|
|
218
214
|
cmd
|
@@ -221,16 +217,16 @@ describe Kitchen::Driver::SSHBase do
|
|
221
217
|
it "with :forward_agent option set if given in state" do
|
222
218
|
state[:forward_agent] = "yeah?"
|
223
219
|
|
224
|
-
|
225
|
-
|
220
|
+
transport.expects(:connection).with { |state|
|
221
|
+
state[:forward_agent].must_equal "yeah?"
|
226
222
|
}.returns(stub(:login_command => stub))
|
227
223
|
|
228
224
|
cmd
|
229
225
|
end
|
230
226
|
|
231
227
|
it "with :port option set to 22 by default" do
|
232
|
-
|
233
|
-
|
228
|
+
transport.expects(:connection).with { |state|
|
229
|
+
state[:port].must_equal 22
|
234
230
|
}.returns(stub(:login_command => stub))
|
235
231
|
|
236
232
|
cmd
|
@@ -239,8 +235,8 @@ describe Kitchen::Driver::SSHBase do
|
|
239
235
|
it "with :port option set if customized in config" do
|
240
236
|
config[:port] = 1234
|
241
237
|
|
242
|
-
|
243
|
-
|
238
|
+
transport.expects(:connection).with { |state|
|
239
|
+
state[:port].must_equal 1234
|
244
240
|
}.returns(stub(:login_command => stub))
|
245
241
|
|
246
242
|
cmd
|
@@ -249,16 +245,8 @@ describe Kitchen::Driver::SSHBase do
|
|
249
245
|
it "with :port option set if customized in state" do
|
250
246
|
state[:port] = 9999
|
251
247
|
|
252
|
-
|
253
|
-
|
254
|
-
}.returns(stub(:login_command => stub))
|
255
|
-
|
256
|
-
cmd
|
257
|
-
end
|
258
|
-
|
259
|
-
it "with :logger option set to driver's logger" do
|
260
|
-
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
261
|
-
opts[:logger].must_equal logger
|
248
|
+
transport.expects(:connection).with { |state|
|
249
|
+
state[:port].must_equal 9999
|
262
250
|
}.returns(stub(:login_command => stub))
|
263
251
|
|
264
252
|
cmd
|
@@ -277,16 +265,18 @@ describe Kitchen::Driver::SSHBase do
|
|
277
265
|
end
|
278
266
|
|
279
267
|
it "returns a LoginCommand" do
|
280
|
-
|
268
|
+
transport.stubs(:connection).returns(stub(:login_command => "command"))
|
269
|
+
|
270
|
+
cmd.must_equal "command"
|
281
271
|
end
|
282
272
|
|
283
|
-
|
273
|
+
constructs_an_ssh_connection
|
284
274
|
end
|
285
275
|
|
286
276
|
describe "#converge" do
|
287
277
|
|
288
278
|
let(:cmd) { driver.converge(state) }
|
289
|
-
let(:connection) { stub(:
|
279
|
+
let(:connection) { stub(:execute => true, :upload => true) }
|
290
280
|
|
291
281
|
before do
|
292
282
|
state[:hostname] = "fizzy"
|
@@ -301,17 +291,17 @@ describe Kitchen::Driver::SSHBase do
|
|
301
291
|
FakeFS::FileSystem.clear
|
302
292
|
end
|
303
293
|
|
304
|
-
|
294
|
+
constructs_an_ssh_connection
|
305
295
|
|
306
296
|
it "creates the sandbox" do
|
307
|
-
|
297
|
+
transport.stubs(:connection).yields(connection)
|
308
298
|
provisioner.expects(:create_sandbox)
|
309
299
|
|
310
300
|
cmd
|
311
301
|
end
|
312
302
|
|
313
303
|
it "ensures that the sandbox is cleaned up" do
|
314
|
-
|
304
|
+
transport.stubs(:connection).raises
|
315
305
|
provisioner.expects(:cleanup_sandbox)
|
316
306
|
|
317
307
|
begin
|
@@ -321,28 +311,28 @@ describe Kitchen::Driver::SSHBase do
|
|
321
311
|
end
|
322
312
|
|
323
313
|
it "invokes the provisioner commands over ssh" do
|
324
|
-
|
314
|
+
transport.stubs(:connection).yields(connection)
|
325
315
|
order = sequence("order")
|
326
|
-
connection.expects(:
|
327
|
-
connection.expects(:
|
328
|
-
connection.expects(:
|
329
|
-
connection.expects(:
|
316
|
+
connection.expects(:execute).with("install").in_sequence(order)
|
317
|
+
connection.expects(:execute).with("init").in_sequence(order)
|
318
|
+
connection.expects(:execute).with("prepare").in_sequence(order)
|
319
|
+
connection.expects(:execute).with("run").in_sequence(order)
|
330
320
|
|
331
321
|
cmd
|
332
322
|
end
|
333
323
|
|
334
324
|
it "invokes the #install_command with :http_proxy set in config" do
|
335
325
|
config[:http_proxy] = "http://proxy"
|
336
|
-
|
337
|
-
connection.expects(:
|
326
|
+
transport.stubs(:connection).yields(connection)
|
327
|
+
connection.expects(:execute).with("env http_proxy=http://proxy install")
|
338
328
|
|
339
329
|
cmd
|
340
330
|
end
|
341
331
|
|
342
332
|
it "invokes the #install_command with :https_proxy set in config" do
|
343
333
|
config[:https_proxy] = "https://proxy"
|
344
|
-
|
345
|
-
connection.expects(:
|
334
|
+
transport.stubs(:connection).yields(connection)
|
335
|
+
connection.expects(:execute).with("env https_proxy=https://proxy install")
|
346
336
|
|
347
337
|
cmd
|
348
338
|
end
|
@@ -350,8 +340,8 @@ describe Kitchen::Driver::SSHBase do
|
|
350
340
|
it "invokes the #install_command with :http_proxy & :https_proxy set" do
|
351
341
|
config[:http_proxy] = "http://proxy"
|
352
342
|
config[:https_proxy] = "https://proxy"
|
353
|
-
|
354
|
-
connection.expects(:
|
343
|
+
transport.stubs(:connection).yields(connection)
|
344
|
+
connection.expects(:execute).with(
|
355
345
|
"env http_proxy=http://proxy https_proxy=https://proxy install")
|
356
346
|
|
357
347
|
cmd
|
@@ -360,13 +350,13 @@ describe Kitchen::Driver::SSHBase do
|
|
360
350
|
describe "transferring files" do
|
361
351
|
|
362
352
|
before do
|
363
|
-
|
364
|
-
connection.stubs(:
|
353
|
+
transport.stubs(:connection).yields(connection)
|
354
|
+
connection.stubs(:upload)
|
365
355
|
FileUtils.mkdir_p "/tmp/sandbox/stuff"
|
366
356
|
end
|
367
357
|
|
368
358
|
it "uploads files" do
|
369
|
-
connection.expects(:
|
359
|
+
connection.expects(:upload).with(["/tmp/sandbox/stuff"], "/rooty")
|
370
360
|
|
371
361
|
cmd
|
372
362
|
end
|
@@ -384,29 +374,16 @@ describe Kitchen::Driver::SSHBase do
|
|
384
374
|
logged_output.string.must_match(/DEBUG -- : Transfer complete$/)
|
385
375
|
end
|
386
376
|
|
387
|
-
it "raises an ActionFailed on transfer when
|
388
|
-
connection.stubs(:
|
389
|
-
|
390
|
-
proc { cmd }.must_raise Kitchen::ActionFailed
|
391
|
-
end
|
392
|
-
|
393
|
-
it "raises an ActionFailed on exec when Net::SSH:Exception is raised" do
|
394
|
-
connection.stubs(:upload_path!).raises(Net::SSH::Exception.new("dang"))
|
377
|
+
it "raises an ActionFailed on transfer when SshFailed is raised" do
|
378
|
+
connection.stubs(:upload).raises(Kitchen::Transport::SshFailed.new("dang"))
|
395
379
|
|
396
380
|
proc { cmd }.must_raise Kitchen::ActionFailed
|
397
381
|
end
|
398
382
|
end
|
399
383
|
|
400
|
-
it "raises an ActionFailed on
|
401
|
-
|
402
|
-
connection.stubs(:
|
403
|
-
|
404
|
-
proc { cmd }.must_raise Kitchen::ActionFailed
|
405
|
-
end
|
406
|
-
|
407
|
-
it "raises an ActionFailed on exec when Net::SSH:Exception is raised" do
|
408
|
-
Kitchen::SSH.stubs(:new).yields(connection)
|
409
|
-
connection.stubs(:exec).raises(Net::SSH::Exception.new("dang"))
|
384
|
+
it "raises an ActionFailed on execute when SshFailed is raised" do
|
385
|
+
transport.stubs(:connection).yields(connection)
|
386
|
+
connection.stubs(:execute).raises(Kitchen::Transport::SshFailed.new("dang"))
|
410
387
|
|
411
388
|
proc { cmd }.must_raise Kitchen::ActionFailed
|
412
389
|
end
|
@@ -422,58 +399,44 @@ describe Kitchen::Driver::SSHBase do
|
|
422
399
|
state[:username] = "bork"
|
423
400
|
end
|
424
401
|
|
425
|
-
|
426
|
-
|
427
|
-
it "doesn't invoke an ssh command if busser#setup_cmd is nil" do
|
428
|
-
busser.stubs(:setup_cmd).returns(nil)
|
429
|
-
Kitchen::SSH.stubs(:new).yields(connection)
|
430
|
-
|
431
|
-
cmd
|
432
|
-
end
|
402
|
+
constructs_an_ssh_connection
|
433
403
|
|
434
|
-
it "invokes the
|
435
|
-
|
436
|
-
connection.expects(:
|
404
|
+
it "invokes the Verifier#install_command over ssh" do
|
405
|
+
transport.stubs(:connection).yields(connection)
|
406
|
+
connection.expects(:execute).with("install")
|
437
407
|
|
438
408
|
cmd
|
439
409
|
end
|
440
410
|
|
441
|
-
it "invokes the
|
411
|
+
it "invokes the Verifier#install_command with :http_proxy set in config" do
|
442
412
|
config[:http_proxy] = "http://proxy"
|
443
|
-
|
444
|
-
connection.expects(:
|
413
|
+
transport.stubs(:connection).yields(connection)
|
414
|
+
connection.expects(:execute).with("env http_proxy=http://proxy install")
|
445
415
|
|
446
416
|
cmd
|
447
417
|
end
|
448
418
|
|
449
|
-
it "invokes the
|
419
|
+
it "invokes the Verifier#install_command with :https_proxy set in config" do
|
450
420
|
config[:https_proxy] = "https://proxy"
|
451
|
-
|
452
|
-
connection.expects(:
|
421
|
+
transport.stubs(:connection).yields(connection)
|
422
|
+
connection.expects(:execute).with("env https_proxy=https://proxy install")
|
453
423
|
|
454
424
|
cmd
|
455
425
|
end
|
456
426
|
|
457
|
-
it "invokes the
|
427
|
+
it "invokes the Verifier#install_command with :http_proxy & :https_proxy set" do
|
458
428
|
config[:http_proxy] = "http://proxy"
|
459
429
|
config[:https_proxy] = "https://proxy"
|
460
|
-
|
461
|
-
connection.expects(:
|
462
|
-
"env http_proxy=http://proxy https_proxy=https://proxy
|
430
|
+
transport.stubs(:connection).yields(connection)
|
431
|
+
connection.expects(:execute).with(
|
432
|
+
"env http_proxy=http://proxy https_proxy=https://proxy install")
|
463
433
|
|
464
434
|
cmd
|
465
435
|
end
|
466
436
|
|
467
|
-
it "raises an ActionFailed when
|
468
|
-
|
469
|
-
connection.stubs(:
|
470
|
-
|
471
|
-
proc { cmd }.must_raise Kitchen::ActionFailed
|
472
|
-
end
|
473
|
-
|
474
|
-
it "raises an ActionFailed when Net::SSH:Exception is raised" do
|
475
|
-
Kitchen::SSH.stubs(:new).yields(connection)
|
476
|
-
connection.stubs(:exec).raises(Net::SSH::Exception.new("dang"))
|
437
|
+
it "raises an ActionFailed when SshFailed is raised" do
|
438
|
+
transport.stubs(:connection).yields(connection)
|
439
|
+
connection.stubs(:execute).raises(Kitchen::Transport::SshFailed.new("dang"))
|
477
440
|
|
478
441
|
proc { cmd }.must_raise Kitchen::ActionFailed
|
479
442
|
end
|
@@ -482,86 +445,100 @@ describe Kitchen::Driver::SSHBase do
|
|
482
445
|
describe "#verify" do
|
483
446
|
|
484
447
|
let(:cmd) { driver.verify(state) }
|
485
|
-
let(:connection) {
|
448
|
+
let(:connection) { stub(:execute => true, :upload => true) }
|
486
449
|
|
487
450
|
before do
|
488
451
|
state[:hostname] = "fizzy"
|
489
452
|
state[:username] = "bork"
|
453
|
+
transport.stubs(:connection).yields(connection)
|
490
454
|
end
|
491
455
|
|
492
|
-
|
456
|
+
constructs_an_ssh_connection
|
493
457
|
|
494
|
-
it "
|
495
|
-
|
496
|
-
busser.stubs(:run_cmd).returns(nil)
|
497
|
-
Kitchen::SSH.stubs(:new).yields(connection)
|
458
|
+
it "creates the sandbox" do
|
459
|
+
verifier.expects(:create_sandbox)
|
498
460
|
|
499
461
|
cmd
|
500
462
|
end
|
501
463
|
|
502
|
-
it "
|
503
|
-
|
504
|
-
|
505
|
-
connection.expects(:exec).with("run")
|
464
|
+
it "ensures that the sandbox is cleanup up" do
|
465
|
+
transport.stubs(:connection).raises
|
466
|
+
verifier.expects(:cleanup_sandbox)
|
506
467
|
|
507
|
-
|
468
|
+
begin
|
469
|
+
cmd
|
470
|
+
rescue # rubocop:disable Lint/HandleExceptions
|
471
|
+
end
|
508
472
|
end
|
509
473
|
|
510
|
-
it "
|
511
|
-
|
512
|
-
|
513
|
-
connection.expects(:
|
474
|
+
it "invokes the verifier commands over the transport" do
|
475
|
+
order = sequence("order")
|
476
|
+
connection.expects(:execute).with("init").in_sequence(order)
|
477
|
+
connection.expects(:execute).with("prepare").in_sequence(order)
|
478
|
+
connection.expects(:execute).with("run").in_sequence(order)
|
514
479
|
|
515
480
|
cmd
|
516
481
|
end
|
517
482
|
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
connection.expects(:exec).with("run")
|
483
|
+
%W[init prepare run].each do |phase|
|
484
|
+
it "invokes Verifier##{phase}_command over ssh" do
|
485
|
+
connection.expects(:execute).with(phase)
|
522
486
|
|
523
|
-
|
524
|
-
|
487
|
+
cmd
|
488
|
+
end
|
525
489
|
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
Kitchen::SSH.stubs(:new).yields(connection)
|
530
|
-
connection.expects(:exec).with("env http_proxy=http://proxy sync")
|
490
|
+
it "invokes Verifier##{phase}_command with :http_proxy set in config" do
|
491
|
+
config[:http_proxy] = "http://proxy"
|
492
|
+
connection.expects(:execute).with("env http_proxy=http://proxy #{phase}")
|
531
493
|
|
494
|
+
cmd
|
495
|
+
end
|
496
|
+
|
497
|
+
it "invokes Verifier##{phase}_command with :https_proxy set in config" do
|
498
|
+
config[:https_proxy] = "https://proxy"
|
499
|
+
connection.expects(:execute).with("env https_proxy=https://proxy #{phase}")
|
500
|
+
|
501
|
+
cmd
|
502
|
+
end
|
503
|
+
|
504
|
+
it "invokes Verifier##{phase}_command with :http_proxy & :https_proxy set" do
|
505
|
+
config[:http_proxy] = "http://proxy"
|
506
|
+
config[:https_proxy] = "https://proxy"
|
507
|
+
connection.expects(:execute).with(
|
508
|
+
"env http_proxy=http://proxy https_proxy=https://proxy #{phase}")
|
509
|
+
|
510
|
+
cmd
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
it "logs to info" do
|
532
515
|
cmd
|
516
|
+
|
517
|
+
logged_output.string.
|
518
|
+
must_match(/INFO -- : Transferring files to instance$/)
|
533
519
|
end
|
534
520
|
|
535
|
-
it "
|
536
|
-
|
537
|
-
config[:https_proxy] = "https://proxy"
|
538
|
-
Kitchen::SSH.stubs(:new).yields(connection)
|
539
|
-
connection.expects(:exec).with("env https_proxy=https://proxy sync")
|
521
|
+
it "uploads sandbox files" do
|
522
|
+
connection.expects(:upload).with([], "/tmp/verifier")
|
540
523
|
|
541
524
|
cmd
|
542
525
|
end
|
543
526
|
|
544
|
-
it "
|
545
|
-
busser.stubs(:run_cmd).returns(nil)
|
546
|
-
config[:http_proxy] = "http://proxy"
|
547
|
-
config[:https_proxy] = "https://proxy"
|
548
|
-
Kitchen::SSH.stubs(:new).yields(connection)
|
549
|
-
connection.expects(:exec).with(
|
550
|
-
"env http_proxy=http://proxy https_proxy=https://proxy sync")
|
551
|
-
|
527
|
+
it "logs to debug" do
|
552
528
|
cmd
|
529
|
+
|
530
|
+
logged_output.string.must_match(/DEBUG -- : Transfer complete$/)
|
553
531
|
end
|
554
532
|
|
555
|
-
it "raises an ActionFailed when
|
556
|
-
|
557
|
-
|
533
|
+
it "raises an ActionFailed on transfer when TransportFailed is raised" do
|
534
|
+
connection.stubs(:upload).
|
535
|
+
raises(Kitchen::Transport::TransportFailed.new("dang"))
|
558
536
|
|
559
537
|
proc { cmd }.must_raise Kitchen::ActionFailed
|
560
538
|
end
|
561
539
|
|
562
|
-
it "raises an ActionFailed when
|
563
|
-
|
564
|
-
connection.stubs(:exec).raises(Net::SSH::Exception.new("dang"))
|
540
|
+
it "raises an ActionFailed when SSHFailed is raised" do
|
541
|
+
connection.stubs(:execute).raises(Kitchen::Transport::SshFailed.new("dang"))
|
565
542
|
|
566
543
|
proc { cmd }.must_raise Kitchen::ActionFailed
|
567
544
|
end
|
@@ -572,19 +549,21 @@ describe Kitchen::Driver::SSHBase do
|
|
572
549
|
let(:cmd) { driver.ssh(["host", "user", { :one => "two" }], "go") }
|
573
550
|
let(:connection) { mock }
|
574
551
|
|
575
|
-
it "creates an SSH
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
552
|
+
it "creates an SSH connection" do
|
553
|
+
connection.stubs(:execute)
|
554
|
+
transport.expects(:connection).with(
|
555
|
+
:hostname => "host",
|
556
|
+
:username => "user",
|
557
|
+
:port => 22,
|
558
|
+
:one => "two"
|
559
|
+
).yields(connection)
|
581
560
|
|
582
561
|
cmd
|
583
562
|
end
|
584
563
|
|
585
564
|
it "invokes the command over ssh" do
|
586
|
-
|
587
|
-
connection.expects(:
|
565
|
+
transport.expects(:connection).yields(connection)
|
566
|
+
connection.expects(:execute).with("go")
|
588
567
|
|
589
568
|
cmd
|
590
569
|
end
|
@@ -600,18 +579,19 @@ describe Kitchen::Driver::SSHBase do
|
|
600
579
|
state[:username] = "bork"
|
601
580
|
end
|
602
581
|
|
603
|
-
it "creates an SSH
|
604
|
-
|
605
|
-
hostname
|
606
|
-
username
|
607
|
-
|
582
|
+
it "creates an SSH connection" do
|
583
|
+
transport.expects(:connection).with(
|
584
|
+
:hostname => "fizzy",
|
585
|
+
:username => "bork",
|
586
|
+
:port => 22
|
587
|
+
)
|
608
588
|
|
609
589
|
cmd
|
610
590
|
end
|
611
591
|
|
612
592
|
it "invokes the command over ssh" do
|
613
|
-
|
614
|
-
connection.expects(:
|
593
|
+
transport.expects(:connection).yields(connection)
|
594
|
+
connection.expects(:execute).with("shipit")
|
615
595
|
|
616
596
|
cmd
|
617
597
|
end
|
@@ -623,22 +603,386 @@ describe Kitchen::Driver::SSHBase do
|
|
623
603
|
driver.send(:wait_for_sshd, "host", "user", :one => "two")
|
624
604
|
end
|
625
605
|
|
626
|
-
it "creates an SSH
|
627
|
-
|
628
|
-
hostname
|
629
|
-
username
|
630
|
-
|
631
|
-
|
606
|
+
it "creates an SSH connection with merged options" do
|
607
|
+
transport.expects(:connection).with(
|
608
|
+
:hostname => "host",
|
609
|
+
:username => "user",
|
610
|
+
:port => 22,
|
611
|
+
:one => "two"
|
612
|
+
).returns(stub(:wait_until_ready => true))
|
632
613
|
|
633
614
|
cmd
|
634
615
|
end
|
635
616
|
|
636
|
-
it "calls wait on the SSH
|
637
|
-
|
638
|
-
|
639
|
-
|
617
|
+
it "calls wait on the SSH connection" do
|
618
|
+
connection = mock
|
619
|
+
transport.expects(:connection).returns(connection)
|
620
|
+
connection.expects(:wait_until_ready)
|
640
621
|
|
641
622
|
cmd
|
642
623
|
end
|
643
624
|
end
|
625
|
+
|
626
|
+
describe "to maintain backwards compatibility" do
|
627
|
+
|
628
|
+
let(:driver) do
|
629
|
+
Kitchen::Driver::BackCompat.new(config).finalize_config!(instance)
|
630
|
+
end
|
631
|
+
|
632
|
+
it "#instance returns its instance" do
|
633
|
+
driver.instance.must_equal instance
|
634
|
+
end
|
635
|
+
|
636
|
+
it "#name returns the name of the driver" do
|
637
|
+
driver.name.must_equal "BackCompat"
|
638
|
+
end
|
639
|
+
|
640
|
+
describe "#logger" do
|
641
|
+
|
642
|
+
before { @klog = Kitchen.logger }
|
643
|
+
after { Kitchen.logger = @klog }
|
644
|
+
|
645
|
+
it "returns the instance's logger if defined" do
|
646
|
+
driver.send(:logger).must_equal logger
|
647
|
+
end
|
648
|
+
|
649
|
+
it "returns the default logger if instance's logger is not set" do
|
650
|
+
driver = Kitchen::Driver::BackCompat.new(config)
|
651
|
+
Kitchen.logger = "yep"
|
652
|
+
|
653
|
+
driver.send(:logger).must_equal Kitchen.logger
|
654
|
+
end
|
655
|
+
end
|
656
|
+
|
657
|
+
it "#puts calls logger.info" do
|
658
|
+
driver.send(:puts, "yo")
|
659
|
+
|
660
|
+
logged_output.string.must_match(/I, /)
|
661
|
+
logged_output.string.must_match(/yo\n/)
|
662
|
+
end
|
663
|
+
|
664
|
+
it "#print calls logger.info" do
|
665
|
+
driver.send(:print, "yo")
|
666
|
+
|
667
|
+
logged_output.string.must_match(/I, /)
|
668
|
+
logged_output.string.must_match(/yo\n/)
|
669
|
+
end
|
670
|
+
|
671
|
+
it "has a default verify dependencies method" do
|
672
|
+
driver.verify_dependencies.must_be_nil
|
673
|
+
end
|
674
|
+
|
675
|
+
it "#busser returns the instance's verifier" do
|
676
|
+
driver.send(:busser).must_equal verifier
|
677
|
+
end
|
678
|
+
|
679
|
+
describe ".no_parallel_for" do
|
680
|
+
|
681
|
+
it "registers no serial actions when none are declared" do
|
682
|
+
Kitchen::Driver::SpeedyCompat.serial_actions.must_equal nil
|
683
|
+
end
|
684
|
+
|
685
|
+
it "registers a single serial action method" do
|
686
|
+
Kitchen::Driver::DodgyCompat.serial_actions.must_equal [:converge]
|
687
|
+
end
|
688
|
+
|
689
|
+
it "registers multiple serial action methods" do
|
690
|
+
actions = Kitchen::Driver::SlowCompat.serial_actions
|
691
|
+
|
692
|
+
actions.must_include :create
|
693
|
+
actions.must_include :verify
|
694
|
+
actions.must_include :destroy
|
695
|
+
end
|
696
|
+
|
697
|
+
it "raises a ClientError if value is not an action method" do
|
698
|
+
proc {
|
699
|
+
Class.new(Kitchen::Driver::BackCompat) {
|
700
|
+
no_parallel_for :telling_stories
|
701
|
+
}
|
702
|
+
}.must_raise Kitchen::ClientError
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
707
|
+
def self.constructs_an_ssh_object
|
708
|
+
it "with hostname set from state" do
|
709
|
+
Kitchen::SSH.expects(:new).with { |hostname, _username, _opts|
|
710
|
+
hostname.must_equal "fizzy"
|
711
|
+
}.returns(connection)
|
712
|
+
|
713
|
+
cmd
|
714
|
+
end
|
715
|
+
|
716
|
+
it "with username set from state" do
|
717
|
+
Kitchen::SSH.expects(:new).with { |_hostname, username, _opts|
|
718
|
+
username.must_equal "bork"
|
719
|
+
}.returns(connection)
|
720
|
+
|
721
|
+
cmd
|
722
|
+
end
|
723
|
+
|
724
|
+
it "with :user_known_hosts_file option set to /dev/null" do
|
725
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
726
|
+
opts[:user_known_hosts_file].must_equal "/dev/null"
|
727
|
+
}.returns(connection)
|
728
|
+
|
729
|
+
cmd
|
730
|
+
end
|
731
|
+
|
732
|
+
it "with :paranoid option set to false" do
|
733
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
734
|
+
opts[:paranoid].must_equal false
|
735
|
+
}.returns(connection)
|
736
|
+
|
737
|
+
cmd
|
738
|
+
end
|
739
|
+
|
740
|
+
it "with :keys_only option set to falsey by default" do
|
741
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
742
|
+
opts[:keys_only].nil?
|
743
|
+
}.returns(connection)
|
744
|
+
|
745
|
+
cmd
|
746
|
+
end
|
747
|
+
|
748
|
+
it "with :keys_only option set to true if :ssh_key is set in config" do
|
749
|
+
config[:ssh_key] = "wicked"
|
750
|
+
|
751
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
752
|
+
opts[:keys_only].must_equal true
|
753
|
+
}.returns(connection)
|
754
|
+
|
755
|
+
cmd
|
756
|
+
end
|
757
|
+
|
758
|
+
it "with :keys_only option set to true if :ssh_key is set in state" do
|
759
|
+
state[:ssh_key] = "wicked"
|
760
|
+
|
761
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
762
|
+
opts[:keys_only].must_equal true
|
763
|
+
}.returns(connection)
|
764
|
+
|
765
|
+
cmd
|
766
|
+
end
|
767
|
+
|
768
|
+
it "with :keys option set to falsey by default" do
|
769
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
770
|
+
opts[:keys].nil?
|
771
|
+
}.returns(connection)
|
772
|
+
|
773
|
+
cmd
|
774
|
+
end
|
775
|
+
|
776
|
+
it "with :keys option set to an array if :ssh_key is set in config" do
|
777
|
+
config[:ssh_key] = "wicked"
|
778
|
+
|
779
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
780
|
+
opts[:keys].must_equal ["wicked"]
|
781
|
+
}.returns(connection)
|
782
|
+
|
783
|
+
cmd
|
784
|
+
end
|
785
|
+
|
786
|
+
it "with :keys option set to an array if :ssh_key is set in state" do
|
787
|
+
state[:ssh_key] = "wicked"
|
788
|
+
|
789
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
790
|
+
opts[:keys].must_equal ["wicked"]
|
791
|
+
}.returns(connection)
|
792
|
+
|
793
|
+
cmd
|
794
|
+
end
|
795
|
+
|
796
|
+
it "with :password option set to falsey by default" do
|
797
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
798
|
+
opts[:password].nil?
|
799
|
+
}.returns(connection)
|
800
|
+
|
801
|
+
cmd
|
802
|
+
end
|
803
|
+
|
804
|
+
it "with :password option set if given in config" do
|
805
|
+
config[:password] = "psst"
|
806
|
+
|
807
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
808
|
+
opts[:password].must_equal "psst"
|
809
|
+
}.returns(connection)
|
810
|
+
|
811
|
+
cmd
|
812
|
+
end
|
813
|
+
|
814
|
+
it "with :password option set if given in state" do
|
815
|
+
state[:password] = "psst"
|
816
|
+
|
817
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
818
|
+
opts[:password].must_equal "psst"
|
819
|
+
}.returns(connection)
|
820
|
+
|
821
|
+
cmd
|
822
|
+
end
|
823
|
+
|
824
|
+
it "with :forward_agent option set to falsey by default" do
|
825
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
826
|
+
opts[:forward_agent].nil?
|
827
|
+
}.returns(connection)
|
828
|
+
|
829
|
+
cmd
|
830
|
+
end
|
831
|
+
|
832
|
+
it "with :forward_agent option set if given in config" do
|
833
|
+
config[:forward_agent] = "yeah?"
|
834
|
+
|
835
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
836
|
+
opts[:forward_agent].must_equal "yeah?"
|
837
|
+
}.returns(connection)
|
838
|
+
|
839
|
+
cmd
|
840
|
+
end
|
841
|
+
|
842
|
+
it "with :forward_agent option set if given in state" do
|
843
|
+
state[:forward_agent] = "yeah?"
|
844
|
+
|
845
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
846
|
+
opts[:forward_agent].must_equal "yeah?"
|
847
|
+
}.returns(connection)
|
848
|
+
|
849
|
+
cmd
|
850
|
+
end
|
851
|
+
|
852
|
+
it "with :port option set to 22 by default" do
|
853
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
854
|
+
opts[:port].must_equal 22
|
855
|
+
}.returns(connection)
|
856
|
+
|
857
|
+
cmd
|
858
|
+
end
|
859
|
+
|
860
|
+
it "with :port option set if customized in config" do
|
861
|
+
config[:port] = 1234
|
862
|
+
|
863
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
864
|
+
opts[:port].must_equal 1234
|
865
|
+
}.returns(connection)
|
866
|
+
|
867
|
+
cmd
|
868
|
+
end
|
869
|
+
|
870
|
+
it "with :port option set if customized in state" do
|
871
|
+
state[:port] = 9999
|
872
|
+
|
873
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
874
|
+
opts[:port].must_equal 9999
|
875
|
+
}.returns(connection)
|
876
|
+
|
877
|
+
cmd
|
878
|
+
end
|
879
|
+
|
880
|
+
it "with :logger option set to driver's logger" do
|
881
|
+
Kitchen::SSH.expects(:new).with { |_hostname, _username, opts|
|
882
|
+
opts[:logger].must_equal logger
|
883
|
+
}.returns(connection)
|
884
|
+
|
885
|
+
cmd
|
886
|
+
end
|
887
|
+
end
|
888
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
889
|
+
|
890
|
+
describe "#run_remote" do
|
891
|
+
|
892
|
+
let(:cmd) { driver.use_run_remote(state, "huh") }
|
893
|
+
let(:connection) { stub(:exec => true) }
|
894
|
+
|
895
|
+
before do
|
896
|
+
state[:hostname] = "fizzy"
|
897
|
+
state[:username] = "bork"
|
898
|
+
end
|
899
|
+
|
900
|
+
constructs_an_ssh_object
|
901
|
+
|
902
|
+
it "invokes the #install_command with :http_proxy set in config" do
|
903
|
+
config[:http_proxy] = "http://proxy"
|
904
|
+
Kitchen::SSH.stubs(:new).returns(connection)
|
905
|
+
connection.expects(:exec).with("env http_proxy=http://proxy huh")
|
906
|
+
|
907
|
+
cmd
|
908
|
+
end
|
909
|
+
|
910
|
+
it "invokes the #install_command with :https_proxy set in config" do
|
911
|
+
config[:https_proxy] = "https://proxy"
|
912
|
+
Kitchen::SSH.stubs(:new).returns(connection)
|
913
|
+
connection.expects(:exec).with("env https_proxy=https://proxy huh")
|
914
|
+
|
915
|
+
cmd
|
916
|
+
end
|
917
|
+
|
918
|
+
it "invokes the #install_command with :http_proxy & :https_proxy set" do
|
919
|
+
config[:http_proxy] = "http://proxy"
|
920
|
+
config[:https_proxy] = "https://proxy"
|
921
|
+
Kitchen::SSH.stubs(:new).returns(connection)
|
922
|
+
connection.expects(:exec).with(
|
923
|
+
"env http_proxy=http://proxy https_proxy=https://proxy huh")
|
924
|
+
|
925
|
+
cmd
|
926
|
+
end
|
927
|
+
|
928
|
+
it "doesn't invoke an ssh command if command is nil" do
|
929
|
+
Kitchen::SSH.stubs(:new).returns(mock)
|
930
|
+
|
931
|
+
driver.use_run_remote(state, nil)
|
932
|
+
end
|
933
|
+
|
934
|
+
it "raises an ActionFailed on transfer when SSHFailed is raised" do
|
935
|
+
Kitchen::SSH.stubs(:new).returns(connection)
|
936
|
+
connection.stubs(:exec).raises(Kitchen::SSHFailed.new("dang"))
|
937
|
+
|
938
|
+
proc { cmd }.must_raise Kitchen::ActionFailed
|
939
|
+
end
|
940
|
+
|
941
|
+
it "raises an ActionFailed on exec when Net::SSH:Exception is raised" do
|
942
|
+
Kitchen::SSH.stubs(:new).returns(connection)
|
943
|
+
connection.stubs(:exec).raises(Net::SSH::Exception.new("dang"))
|
944
|
+
|
945
|
+
proc { cmd }.must_raise Kitchen::ActionFailed
|
946
|
+
end
|
947
|
+
end
|
948
|
+
|
949
|
+
describe "#transfer_path" do
|
950
|
+
|
951
|
+
let(:cmd) { driver.use_transfer_path(state, ["nope"], "nadda") }
|
952
|
+
let(:connection) { stub(:upload_path! => true) }
|
953
|
+
|
954
|
+
before do
|
955
|
+
state[:hostname] = "fizzy"
|
956
|
+
state[:username] = "bork"
|
957
|
+
end
|
958
|
+
|
959
|
+
constructs_an_ssh_object
|
960
|
+
|
961
|
+
it "doesn't invoke an scp command if locals is nil" do
|
962
|
+
Kitchen::SSH.stubs(:new).returns(mock)
|
963
|
+
|
964
|
+
driver.use_transfer_path(state, nil, "nope")
|
965
|
+
end
|
966
|
+
|
967
|
+
it "doesn't invoke an scp command if locals is an empty array" do
|
968
|
+
Kitchen::SSH.stubs(:new).returns(mock)
|
969
|
+
|
970
|
+
driver.use_transfer_path(state, [], "nope")
|
971
|
+
end
|
972
|
+
|
973
|
+
it "raises an ActionFailed on transfer when SSHFailed is raised" do
|
974
|
+
Kitchen::SSH.stubs(:new).returns(connection)
|
975
|
+
connection.stubs(:upload_path!).raises(Kitchen::SSHFailed.new("dang"))
|
976
|
+
|
977
|
+
proc { cmd }.must_raise Kitchen::ActionFailed
|
978
|
+
end
|
979
|
+
|
980
|
+
it "raises an ActionFailed on exec when Net::SSH:Exception is raised" do
|
981
|
+
Kitchen::SSH.stubs(:new).returns(connection)
|
982
|
+
connection.stubs(:upload_path!).raises(Net::SSH::Exception.new("dang"))
|
983
|
+
|
984
|
+
proc { cmd }.must_raise Kitchen::ActionFailed
|
985
|
+
end
|
986
|
+
end
|
987
|
+
end
|
644
988
|
end
|