train 1.5.11 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/lib/train/transports/winrm.rb +16 -4
  3. data/lib/train/version.rb +1 -1
  4. metadata +3 -165
  5. data/.rubocop.yml +0 -77
  6. data/CHANGELOG.md +0 -900
  7. data/Gemfile +0 -41
  8. data/README.md +0 -212
  9. data/Rakefile +0 -73
  10. data/test/fixtures/plugins/train-test-fixture/LICENSE +0 -201
  11. data/test/fixtures/plugins/train-test-fixture/README.md +0 -5
  12. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/connection.rb +0 -35
  13. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/platform.rb +0 -18
  14. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/transport.rb +0 -14
  15. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/version.rb +0 -5
  16. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture.rb +0 -4
  17. data/test/fixtures/plugins/train-test-fixture/pkg/train-test-fixture-0.1.0.gem +0 -0
  18. data/test/fixtures/plugins/train-test-fixture/train-test-fixture.gemspec +0 -35
  19. data/test/integration/.kitchen.yml +0 -43
  20. data/test/integration/Berksfile +0 -3
  21. data/test/integration/bootstrap.sh +0 -22
  22. data/test/integration/chefignore +0 -1
  23. data/test/integration/cookbooks/test/metadata.rb +0 -1
  24. data/test/integration/cookbooks/test/recipes/default.rb +0 -100
  25. data/test/integration/cookbooks/test/recipes/prep_files.rb +0 -56
  26. data/test/integration/docker_run.rb +0 -153
  27. data/test/integration/docker_test.rb +0 -24
  28. data/test/integration/docker_test_container.rb +0 -24
  29. data/test/integration/helper.rb +0 -61
  30. data/test/integration/sudo/customcommand.rb +0 -15
  31. data/test/integration/sudo/nopasswd.rb +0 -16
  32. data/test/integration/sudo/passwd.rb +0 -21
  33. data/test/integration/sudo/reqtty.rb +0 -17
  34. data/test/integration/sudo/run_as.rb +0 -12
  35. data/test/integration/test-travis-centos.yml +0 -6
  36. data/test/integration/test-travis-debian.yml +0 -6
  37. data/test/integration/test-travis-fedora.yml +0 -8
  38. data/test/integration/test-travis-oel.yml +0 -6
  39. data/test/integration/test-travis-ubuntu.yml +0 -8
  40. data/test/integration/test_local.rb +0 -19
  41. data/test/integration/test_ssh.rb +0 -39
  42. data/test/integration/tests/path_block_device_test.rb +0 -74
  43. data/test/integration/tests/path_character_device_test.rb +0 -74
  44. data/test/integration/tests/path_file_test.rb +0 -99
  45. data/test/integration/tests/path_folder_test.rb +0 -90
  46. data/test/integration/tests/path_missing_test.rb +0 -76
  47. data/test/integration/tests/path_pipe_test.rb +0 -62
  48. data/test/integration/tests/path_symlink_test.rb +0 -95
  49. data/test/integration/tests/run_command_test.rb +0 -35
  50. data/test/unit/extras/command_wrapper_test.rb +0 -110
  51. data/test/unit/extras/stat_test.rb +0 -210
  52. data/test/unit/file/local/unix_test.rb +0 -224
  53. data/test/unit/file/local/windows_test.rb +0 -101
  54. data/test/unit/file/local_test.rb +0 -121
  55. data/test/unit/file/remote/aix_test.rb +0 -81
  56. data/test/unit/file/remote/linux_test.rb +0 -221
  57. data/test/unit/file/remote/qnx_test.rb +0 -80
  58. data/test/unit/file/remote/unix_test.rb +0 -119
  59. data/test/unit/file/remote/windows_test.rb +0 -72
  60. data/test/unit/file/remote_test.rb +0 -62
  61. data/test/unit/file_test.rb +0 -129
  62. data/test/unit/helper.rb +0 -7
  63. data/test/unit/platforms/detect/os_common_test.rb +0 -85
  64. data/test/unit/platforms/detect/os_linux_test.rb +0 -132
  65. data/test/unit/platforms/detect/os_windows_test.rb +0 -107
  66. data/test/unit/platforms/detect/scanner_test.rb +0 -61
  67. data/test/unit/platforms/detect/uuid_test.rb +0 -133
  68. data/test/unit/platforms/family_test.rb +0 -32
  69. data/test/unit/platforms/os_detect_test.rb +0 -249
  70. data/test/unit/platforms/platform_test.rb +0 -405
  71. data/test/unit/platforms/platforms_test.rb +0 -52
  72. data/test/unit/plugins/connection_test.rb +0 -219
  73. data/test/unit/plugins/transport_test.rb +0 -111
  74. data/test/unit/plugins_test.rb +0 -22
  75. data/test/unit/train_test.rb +0 -247
  76. data/test/unit/transports/aws_test.rb +0 -120
  77. data/test/unit/transports/azure_test.rb +0 -145
  78. data/test/unit/transports/cisco_ios_connection.rb +0 -92
  79. data/test/unit/transports/gcp_test.rb +0 -266
  80. data/test/unit/transports/helpers/azure/file_credentials_test.rb +0 -129
  81. data/test/unit/transports/local_test.rb +0 -183
  82. data/test/unit/transports/mock_test.rb +0 -150
  83. data/test/unit/transports/ssh_test.rb +0 -330
  84. data/test/unit/transports/vmware_test.rb +0 -159
  85. data/test/unit/version_test.rb +0 -8
  86. data/test/windows/local_test.rb +0 -243
  87. data/test/windows/winrm_test.rb +0 -187
  88. data/train.gemspec +0 -45
@@ -1,405 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'helper'
4
-
5
- describe 'platform' do
6
- def mock_platform(x)
7
- plat = Train::Platforms.name(x)
8
- plat.family_hierarchy = mock_os_hierarchy(plat).flatten
9
- plat.platform[:family] = plat.family_hierarchy[0]
10
- plat.add_platform_methods
11
- plat
12
- end
13
-
14
- def mock_platform_family(x)
15
- Train::Platforms.list[x] = nil if x == 'mock'
16
- plat = Train::Platforms.name(x).in_family(x)
17
- plat.family_hierarchy = mock_os_hierarchy(plat).flatten
18
- plat.platform[:family] = plat.family_hierarchy[0]
19
- plat.add_platform_methods
20
- plat
21
- end
22
-
23
- def mock_os_hierarchy(plat)
24
- plat.families.each_with_object([]) do |(k, _v), memo|
25
- memo << k.name
26
- memo << mock_os_hierarchy(k) unless k.families.empty?
27
- end
28
- end
29
-
30
- it 'set platform title' do
31
- plat = mock_platform_family('mock')
32
- plat.title.must_equal('Mock')
33
- plat.title('The Best Mock')
34
- plat.title.must_equal('The Best Mock')
35
- end
36
-
37
- it 'clean init name' do
38
- plat = mock_platform_family('Mo ck')
39
- plat.name.must_equal('mo_ck')
40
- end
41
-
42
- it 'set name and name override' do
43
- plat = mock_platform_family('mock')
44
- plat.name.must_equal('mock')
45
- plat[:name].must_equal('mock')
46
- plat.platform[:name] = 'Mock 2020'
47
- plat.add_platform_methods
48
- plat.name.must_equal('mock_2020')
49
- plat[:name].must_equal('mock_2020')
50
- end
51
-
52
- it 'check families' do
53
- plat = mock_platform_family('mock')
54
- plat.families.keys[0].name.must_equal('mock')
55
- end
56
-
57
- it 'check families with condition' do
58
- Train::Platforms.list['mock'] = nil
59
- plat = Train::Platforms.name('mock', arch: '= x86_64').in_family('linux')
60
- plat.families.keys[0].name.must_equal('linux')
61
- plat.families.values[0].must_equal({ arch: '= x86_64' })
62
- end
63
-
64
- it 'finds family hierarchy' do
65
- plat = Train::Platforms.name('linux')
66
- plat.find_family_hierarchy
67
- plat.family_hierarchy.must_equal ['linux', 'unix', 'os']
68
- end
69
-
70
- it 'return direct families' do
71
- plat = mock_platform_family('mock')
72
- plat.in_family('mock2')
73
- plat.in_family('mock3')
74
- plat.direct_families.must_equal(["mock", "mock2", "mock3"])
75
- end
76
-
77
- it 'return to_hash' do
78
- plat = mock_platform_family('mock')
79
- plat.to_hash.must_equal({ family: "mock" })
80
- end
81
-
82
- it 'return unknown release' do
83
- plat = mock_platform_family('mock')
84
- plat[:release].must_equal('unknown')
85
- end
86
-
87
- it 'return name?' do
88
- plat = Train::Platforms.name('windows_rc1')
89
- defined?(plat.windows_rc1?).must_be_nil
90
- plat.add_platform_methods
91
- plat.windows_rc1?.must_equal(true)
92
- end
93
-
94
- it 'add platform methods' do
95
- Train::Platforms.list['mock'] = nil
96
- plat = Train::Platforms.name('mock').in_family('linux')
97
- defined?(plat.linux?).must_be_nil
98
- plat.family_hierarchy = mock_os_hierarchy(plat).flatten
99
- plat.add_platform_methods
100
- plat.linux?.must_equal(true)
101
- end
102
-
103
- it 'provides a method to access platform data' do
104
- family = 'test-os'
105
- os = mock_platform_family(family)
106
- os[:family].must_equal family
107
- end
108
-
109
- it 'provides an accessor for the full hash' do
110
- x = 'test-os'
111
- os = mock_platform_family(x)
112
- os.to_hash.must_equal({ family: x })
113
- end
114
-
115
- describe 'with platform set to redhat' do
116
- let(:os) { mock_platform('redhat') }
117
- it { os.redhat?.must_equal(true) }
118
- it { os.debian?.must_equal(false) }
119
- it { os.suse?.must_equal(false) }
120
- it { os.linux?.must_equal(true) }
121
- it { os.unix?.must_equal(true) }
122
- end
123
-
124
- describe 'with platform set to oracle' do
125
- let(:os) { mock_platform('oracle') }
126
- it { os.redhat?.must_equal(true) }
127
- it { os.debian?.must_equal(false) }
128
- it { os.suse?.must_equal(false) }
129
- it { os.linux?.must_equal(true) }
130
- it { os.unix?.must_equal(true) }
131
- end
132
-
133
- describe 'with platform set to centos' do
134
- let(:os) { mock_platform('centos') }
135
- it { os.redhat?.must_equal(true) }
136
- it { os.debian?.must_equal(false) }
137
- it { os.suse?.must_equal(false) }
138
- it { os.linux?.must_equal(true) }
139
- it { os.unix?.must_equal(true) }
140
- end
141
-
142
- describe 'with platform set to cloudlinux' do
143
- let(:os) { mock_platform('cloudlinux') }
144
- it { os.redhat?.must_equal(true) }
145
- it { os.debian?.must_equal(false) }
146
- it { os.suse?.must_equal(false) }
147
- it { os.linux?.must_equal(true) }
148
- it { os.unix?.must_equal(true) }
149
- end
150
-
151
- describe 'with platform set to fedora' do
152
- let(:os) { mock_platform('fedora') }
153
- it { os.fedora?.must_equal(true) }
154
- it { os.redhat?.must_equal(false) }
155
- it { os.debian?.must_equal(false) }
156
- it { os.suse?.must_equal(false) }
157
- it { os.linux?.must_equal(true) }
158
- it { os.unix?.must_equal(true) }
159
- end
160
-
161
- describe 'with platform set to amazon' do
162
- let(:os) { mock_platform('amazon') }
163
- it { os.fedora?.must_equal(false) }
164
- it { os.redhat?.must_equal(true) }
165
- it { os.debian?.must_equal(false) }
166
- it { os.suse?.must_equal(false) }
167
- it { os.linux?.must_equal(true) }
168
- it { os.unix?.must_equal(true) }
169
- end
170
-
171
- describe 'with platform set to debian' do
172
- let(:os) { mock_platform('debian') }
173
- it { os.redhat?.must_equal(false) }
174
- it { os.debian?.must_equal(true) }
175
- it { os.suse?.must_equal(false) }
176
- it { os.linux?.must_equal(true) }
177
- it { os.unix?.must_equal(true) }
178
- end
179
-
180
- describe 'with platform set to ubuntu' do
181
- let(:os) { mock_platform('ubuntu') }
182
- it { os.redhat?.must_equal(false) }
183
- it { os.debian?.must_equal(true) }
184
- it { os.suse?.must_equal(false) }
185
- it { os.linux?.must_equal(true) }
186
- it { os.unix?.must_equal(true) }
187
- end
188
-
189
- describe 'with platform set to linuxmint' do
190
- let(:os) { mock_platform('linuxmint') }
191
- it { os.redhat?.must_equal(false) }
192
- it { os.debian?.must_equal(true) }
193
- it { os.suse?.must_equal(false) }
194
- it { os.linux?.must_equal(true) }
195
- it { os.unix?.must_equal(true) }
196
- end
197
-
198
- describe 'with platform set to raspbian' do
199
- let(:os) { mock_platform('raspbian') }
200
- it { os.redhat?.must_equal(false) }
201
- it { os.debian?.must_equal(true) }
202
- it { os.suse?.must_equal(false) }
203
- it { os.linux?.must_equal(true) }
204
- it { os.unix?.must_equal(true) }
205
- end
206
-
207
- describe 'with platform set to suse' do
208
- let(:os) { mock_platform('suse') }
209
- it { os.redhat?.must_equal(false) }
210
- it { os.debian?.must_equal(false) }
211
- it { os.suse?.must_equal(true) }
212
- it { os.linux?.must_equal(true) }
213
- it { os.unix?.must_equal(true) }
214
- end
215
-
216
- describe 'with platform set to opensuse' do
217
- let(:os) { mock_platform('opensuse') }
218
- it { os.redhat?.must_equal(false) }
219
- it { os.debian?.must_equal(false) }
220
- it { os.suse?.must_equal(true) }
221
- it { os.linux?.must_equal(true) }
222
- it { os.unix?.must_equal(true) }
223
- end
224
-
225
- describe 'with platform set to alpine' do
226
- let(:os) { mock_platform('alpine') }
227
- it { os.redhat?.must_equal(false) }
228
- it { os.debian?.must_equal(false) }
229
- it { os.suse?.must_equal(false) }
230
- it { os.linux?.must_equal(true) }
231
- it { os.unix?.must_equal(true) }
232
- end
233
-
234
- describe 'with platform set to arch' do
235
- let(:os) { mock_platform('arch') }
236
- it { os.redhat?.must_equal(false) }
237
- it { os.debian?.must_equal(false) }
238
- it { os.suse?.must_equal(false) }
239
- it { os.linux?.must_equal(true) }
240
- it { os.unix?.must_equal(true) }
241
- end
242
-
243
- describe 'with platform set to coreos' do
244
- let(:os) { mock_platform('coreos') }
245
- it { os.redhat?.must_equal(false) }
246
- it { os.debian?.must_equal(false) }
247
- it { os.suse?.must_equal(false) }
248
- it { os.linux?.must_equal(true) }
249
- it { os.unix?.must_equal(true) }
250
- end
251
-
252
- describe 'with platform set to exherbo' do
253
- let(:os) { mock_platform('exherbo') }
254
- it { os.redhat?.must_equal(false) }
255
- it { os.debian?.must_equal(false) }
256
- it { os.suse?.must_equal(false) }
257
- it { os.linux?.must_equal(true) }
258
- it { os.unix?.must_equal(true) }
259
- end
260
-
261
- describe 'with platform set to gentoo' do
262
- let(:os) { mock_platform('gentoo') }
263
- it { os.redhat?.must_equal(false) }
264
- it { os.debian?.must_equal(false) }
265
- it { os.suse?.must_equal(false) }
266
- it { os.linux?.must_equal(true) }
267
- it { os.unix?.must_equal(true) }
268
- end
269
-
270
- describe 'with platform set to slackware' do
271
- let(:os) { mock_platform('slackware') }
272
- it { os.redhat?.must_equal(false) }
273
- it { os.debian?.must_equal(false) }
274
- it { os.suse?.must_equal(false) }
275
- it { os.linux?.must_equal(true) }
276
- it { os.unix?.must_equal(true) }
277
- end
278
-
279
- describe 'with platform set to wrlinux' do
280
- let(:os) { mock_platform('wrlinux') }
281
- it { os.redhat?.must_equal(true) }
282
- it { os.debian?.must_equal(false) }
283
- it { os.suse?.must_equal(false) }
284
- it { os.linux?.must_equal(true) }
285
- it { os.unix?.must_equal(true) }
286
- end
287
-
288
- describe 'with platform set to linux' do
289
- let(:os) { mock_platform('linux') }
290
- it { os.linux?.must_equal(true) }
291
- it { os.unix?.must_equal(true) }
292
- end
293
-
294
- describe 'with platform set to freebsd' do
295
- let(:os) { mock_platform('freebsd') }
296
- it { os.bsd?.must_equal(true) }
297
- it { os.linux?.must_equal(false) }
298
- it { os.unix?.must_equal(true) }
299
- end
300
-
301
- describe 'with platform set to netbsd' do
302
- let(:os) { mock_platform('netbsd') }
303
- it { os.bsd?.must_equal(true) }
304
- it { os.linux?.must_equal(false) }
305
- it { os.unix?.must_equal(true) }
306
- end
307
-
308
- describe 'with platform set to openbsd' do
309
- let(:os) { mock_platform('openbsd') }
310
- it { os.bsd?.must_equal(true) }
311
- it { os.linux?.must_equal(false) }
312
- it { os.unix?.must_equal(true) }
313
- end
314
-
315
- describe 'with platform set to darwin' do
316
- let(:os) { mock_platform('darwin') }
317
- it { os.bsd?.must_equal(true) }
318
- it { os.linux?.must_equal(false) }
319
- it { os.unix?.must_equal(true) }
320
- end
321
-
322
- describe 'with platform set to solaris' do
323
- let(:os) { mock_platform('solaris') }
324
- it { os.solaris?.must_equal(true) }
325
- it { os.linux?.must_equal(false) }
326
- it { os.unix?.must_equal(true) }
327
- end
328
-
329
- describe 'with platform set to smartos' do
330
- let(:os) { mock_platform('smartos') }
331
- it { os.solaris?.must_equal(true) }
332
- it { os.linux?.must_equal(false) }
333
- it { os.unix?.must_equal(true) }
334
- end
335
-
336
- describe 'with platform set to openindiana' do
337
- let(:os) { mock_platform('openindiana') }
338
- it { os.solaris?.must_equal(true) }
339
- it { os.linux?.must_equal(false) }
340
- it { os.unix?.must_equal(true) }
341
- end
342
-
343
- describe 'with platform set to opensolaris' do
344
- let(:os) { mock_platform('opensolaris') }
345
- it { os.solaris?.must_equal(true) }
346
- it { os.linux?.must_equal(false) }
347
- it { os.unix?.must_equal(true) }
348
- end
349
-
350
- describe 'with platform set to nexentacore' do
351
- let(:os) { mock_platform('nexentacore') }
352
- it { os.solaris?.must_equal(true) }
353
- it { os.linux?.must_equal(false) }
354
- it { os.unix?.must_equal(true) }
355
- end
356
-
357
- describe 'with platform set to windows' do
358
- let(:os) { mock_platform('windows') }
359
- it { os.solaris?.must_equal(false) }
360
- it { os.bsd?.must_equal(false) }
361
- it { os.linux?.must_equal(false) }
362
- it { os.unix?.must_equal(false) }
363
- end
364
-
365
- describe 'with platform set to hpux' do
366
- let(:os) { mock_platform('hpux') }
367
- it { os.solaris?.must_equal(false) }
368
- it { os.linux?.must_equal(false) }
369
- it { os.unix?.must_equal(true) }
370
- it { os.hpux?.must_equal(true) }
371
- end
372
-
373
- describe 'with platform set to esx' do
374
- let(:os) { mock_platform('vmkernel') }
375
- it { os.solaris?.must_equal(false) }
376
- it { os.linux?.must_equal(false) }
377
- it { os[:family].must_equal('esx') }
378
- it { os.unix?.must_equal(false) }
379
- it { os.esx?.must_equal(true) }
380
- end
381
-
382
- describe 'with platform set to darwin' do
383
- let(:os) { mock_platform('darwin') }
384
- it { os.solaris?.must_equal(false) }
385
- it { os.linux?.must_equal(false) }
386
- it { os[:family].must_equal('darwin') }
387
- it { os.bsd?.must_equal(true) }
388
- it { os.darwin?.must_equal(true) }
389
- it { os.unix?.must_equal(true) }
390
- it { os.bsd?.must_equal(true) }
391
- it { os.esx?.must_equal(false) }
392
- end
393
-
394
- describe 'with platform set to mac_os_x' do
395
- let(:os) { mock_platform('mac_os_x') }
396
- it { os.solaris?.must_equal(false) }
397
- it { os.linux?.must_equal(false) }
398
- it { os[:family].must_equal('darwin') }
399
- it { os.bsd?.must_equal(true) }
400
- it { os.darwin?.must_equal(true) }
401
- it { os.unix?.must_equal(true) }
402
- it { os.bsd?.must_equal(true) }
403
- it { os.esx?.must_equal(false) }
404
- end
405
- end
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'helper'
4
-
5
- describe 'platforms' do
6
-
7
- it 'create platform' do
8
- Train::Platforms.list['mock'] = nil
9
- plat = Train::Platforms.name('mock')
10
- Train::Platforms.name('mock').in_family('test')
11
- Train::Platforms.name('mock').detect { true }
12
- plat.title.must_equal('Mock')
13
- plat.detect.call.must_equal(true)
14
- plat.families.keys[0].name.must_equal('test')
15
- end
16
-
17
- it 'create family' do
18
- Train::Platforms.families['mock'] = nil
19
- fam = Train::Platforms.family('mock')
20
- Train::Platforms.family('mock').in_family('test')
21
- Train::Platforms.family('mock').detect { true }
22
- fam.title.must_equal('Mock Family')
23
- fam.detect.call.must_equal(true)
24
- fam.families.keys[0].name.must_equal('test')
25
- end
26
-
27
- it 'return top platforms empty' do
28
- Train::Platforms.stubs(:list).returns({})
29
- Train::Platforms.stubs(:families).returns({})
30
- top = Train::Platforms.top_platforms
31
- top.count.must_equal(0)
32
- end
33
-
34
- it 'return top platforms with data' do
35
- plat = Train::Platforms.name('linux')
36
- plat.stubs(:families).returns({})
37
- Train::Platforms.stubs(:list).returns({ 'linux' => plat })
38
- Train::Platforms.stubs(:families).returns({})
39
- top = Train::Platforms.top_platforms
40
- top.count.must_equal(1)
41
- end
42
-
43
- it 'return platforms export with data' do
44
- Train::Platforms.__reset
45
- Train::Platforms::Detect::Specifications::OS.load
46
- export = Train::Platforms.export
47
- export.size.must_be :>, 10
48
- export[0][:name].must_equal 'aix'
49
- expected_families = ['aix', 'unix', 'os']
50
- export[0][:families].must_equal expected_families
51
- end
52
- end
@@ -1,219 +0,0 @@
1
- # encoding: utf-8
2
- require 'helper'
3
-
4
- describe 'v1 Connection Plugin' do
5
- describe 'empty v1 connection plugin' do
6
- let(:cls) { Train::Plugins::Transport::BaseConnection }
7
- let(:connection) { cls.new({}) }
8
-
9
- it 'provides a close method' do
10
- connection.close # wont raise
11
- end
12
-
13
- it 'raises an exception for run_command' do
14
- proc { connection.run_command('') }.must_raise NotImplementedError
15
- end
16
-
17
- it 'raises an exception for run_command_via_connection' do
18
- proc { connection.send(:run_command_via_connection, '') }.must_raise NotImplementedError
19
- end
20
-
21
- it 'raises an exception for os method' do
22
- proc { connection.os }.must_raise NotImplementedError
23
- end
24
-
25
- it 'raises an exception for file method' do
26
- proc { connection.file('') }.must_raise NotImplementedError
27
- end
28
-
29
- it 'raises an exception for file_via_connection method' do
30
- proc { connection.send(:file_via_connection, '') }.must_raise NotImplementedError
31
- end
32
-
33
- it 'raises an exception for login command method' do
34
- proc { connection.login_command }.must_raise NotImplementedError
35
- end
36
-
37
- it 'can wait until ready' do
38
- connection.wait_until_ready # wont raise
39
- end
40
-
41
- it 'provides a default logger' do
42
- connection.method(:logger).call
43
- .must_be_instance_of(Logger)
44
- end
45
-
46
- it 'provides direct platform' do
47
- plat = connection.force_platform!('mac_os_x')
48
- plat.name.must_equal 'mac_os_x'
49
- plat.linux?.must_equal false
50
- plat.cloud?.must_equal false
51
- plat.unix?.must_equal true
52
- plat.family.must_equal 'darwin'
53
- plat.family_hierarchy.must_equal ['darwin', 'bsd', 'unix', 'os']
54
- end
55
-
56
- it 'provides api direct platform' do
57
- plat = connection.force_platform!('aws')
58
- plat.name.must_equal 'aws'
59
- plat.linux?.must_equal false
60
- plat.cloud?.must_equal true
61
- plat.family.must_equal 'cloud'
62
- plat.family_hierarchy.must_equal ['cloud', 'api']
63
- end
64
-
65
- it 'provides api direct platform with platform options' do
66
- aws_version = Gem.loaded_specs['aws-sdk'].version
67
- aws_version = "aws-sdk-v#{aws_version}"
68
- details = { release: aws_version }
69
- plat = connection.force_platform!('aws', details)
70
- plat.name.must_equal 'aws'
71
- plat.release.must_equal aws_version
72
- plat[:release].must_equal aws_version
73
- end
74
-
75
- it 'must use the user-provided logger' do
76
- l = rand
77
- cls.new({logger: l})
78
- .method(:logger).call.must_equal(l)
79
- end
80
-
81
- describe 'cached_client helper' do
82
- class DemoConnection < Train::Plugins::Transport::BaseConnection
83
- def initialize(options = {})
84
- super(options)
85
- @cache_enabled[:api_call] = true
86
- @cache[:api_call] = {}
87
- end
88
-
89
- def demo_client
90
- cached_client(:api_call, :demo_client) do
91
- DemoClient.new
92
- end
93
- end
94
-
95
- class DemoClient
96
- end
97
- end
98
-
99
- it 'returns a new connection when cached disabled' do
100
- conn = DemoConnection.new
101
- conn.disable_cache(:api_call)
102
-
103
- client1 = conn.demo_client
104
- client2 = conn.demo_client
105
-
106
- client1.wont_be_same_as client2
107
- end
108
-
109
- it 'returns a new connection when cache enabled and not hydrated' do
110
- conn = DemoConnection.new
111
- conn.enable_cache(:api_call)
112
-
113
- client1 = conn.demo_client
114
-
115
- client1.must_be_instance_of DemoConnection::DemoClient
116
- end
117
-
118
- it 'returns a cached connection when cache enabled and hydrated' do
119
- conn = DemoConnection.new
120
- conn.enable_cache(:api_call)
121
-
122
- client1 = conn.demo_client
123
- client2 = conn.demo_client
124
-
125
- client1.must_be_same_as client2
126
- end
127
- end
128
-
129
- describe 'create cache connection' do
130
- it 'default connection cache settings' do
131
- connection.cache_enabled?(:file).must_equal true
132
- connection.cache_enabled?(:command).must_equal false
133
- end
134
- end
135
-
136
- describe 'disable/enable caching' do
137
- it 'disable file cache via connection' do
138
- connection.disable_cache(:file)
139
- connection.cache_enabled?(:file).must_equal false
140
- end
141
-
142
- it 'enable command cache via cache_connection' do
143
- connection.enable_cache(:command)
144
- connection.cache_enabled?(:command).must_equal true
145
- end
146
-
147
- it 'raises an exception for unknown cache type' do
148
- proc { connection.enable_cache(:fake) }.must_raise Train::UnknownCacheType
149
- proc { connection.disable_cache(:fake) }.must_raise Train::UnknownCacheType
150
- end
151
- end
152
-
153
- describe 'cache enable check' do
154
- it 'returns true when cache is enabled' do
155
- cache_enabled = connection.instance_variable_get(:@cache_enabled)
156
- cache_enabled[:test] = true
157
- connection.cache_enabled?(:test).must_equal true
158
- end
159
-
160
- it 'returns false when cache is disabled' do
161
- cache_enabled = connection.instance_variable_get(:@cache_enabled)
162
- cache_enabled[:test] = false
163
- connection.cache_enabled?(:test).must_equal false
164
- end
165
- end
166
-
167
- describe 'clear cache' do
168
- it 'clear file cache' do
169
- cache = connection.instance_variable_get(:@cache)
170
- cache[:file]['/tmp'] = 'test'
171
- connection.send(:clear_cache, :file)
172
- cache = connection.instance_variable_get(:@cache)
173
- cache[:file].must_equal({})
174
- end
175
- end
176
-
177
- describe 'load file' do
178
- it 'with caching' do
179
- connection.enable_cache(:file)
180
- connection.expects(:file_via_connection).once.returns('test_file')
181
- connection.file('/tmp/test').must_equal('test_file')
182
- connection.file('/tmp/test').must_equal('test_file')
183
- assert = { '/tmp/test' => 'test_file' }
184
- cache = connection.instance_variable_get(:@cache)
185
- cache[:file].must_equal(assert)
186
- end
187
-
188
- it 'without caching' do
189
- connection.disable_cache(:file)
190
- connection.expects(:file_via_connection).twice.returns('test_file')
191
- connection.file('/tmp/test').must_equal('test_file')
192
- connection.file('/tmp/test').must_equal('test_file')
193
- cache = connection.instance_variable_get(:@cache)
194
- cache[:file].must_equal({})
195
- end
196
- end
197
-
198
- describe 'run command' do
199
- it 'with caching' do
200
- connection.enable_cache(:command)
201
- connection.expects(:run_command_via_connection).once.returns('test_user')
202
- connection.run_command('whoami').must_equal('test_user')
203
- connection.run_command('whoami').must_equal('test_user')
204
- assert = { 'whoami' => 'test_user' }
205
- cache = connection.instance_variable_get(:@cache)
206
- cache[:command].must_equal(assert)
207
- end
208
-
209
- it 'without caching' do
210
- connection.disable_cache(:command)
211
- connection.expects(:run_command_via_connection).twice.returns('test_user')
212
- connection.run_command('whoami').must_equal('test_user')
213
- connection.run_command('whoami').must_equal('test_user')
214
- cache = connection.instance_variable_get(:@cache)
215
- cache[:command].must_equal({})
216
- end
217
- end
218
- end
219
- end