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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.cane +2 -0
  3. data/.gitignore +4 -0
  4. data/CHANGELOG.md +45 -0
  5. data/Rakefile +15 -0
  6. data/features/kitchen_action_commands.feature +12 -9
  7. data/features/kitchen_defaults.feature +38 -0
  8. data/features/kitchen_init_command.feature +0 -1
  9. data/features/kitchen_list_command.feature +2 -2
  10. data/features/kitchen_login_command.feature +7 -1
  11. data/features/kitchen_test_command.feature +4 -4
  12. data/lib/kitchen.rb +40 -11
  13. data/lib/kitchen/cli.rb +38 -22
  14. data/lib/kitchen/command/list.rb +5 -2
  15. data/lib/kitchen/config.rb +45 -18
  16. data/lib/kitchen/configurable.rb +137 -1
  17. data/lib/kitchen/data_munger.rb +248 -17
  18. data/lib/kitchen/driver.rb +1 -1
  19. data/lib/kitchen/driver/base.rb +1 -83
  20. data/lib/kitchen/driver/dummy.rb +0 -5
  21. data/lib/kitchen/driver/ssh_base.rb +177 -22
  22. data/lib/kitchen/instance.rb +140 -20
  23. data/lib/kitchen/logger.rb +43 -8
  24. data/lib/kitchen/login_command.rb +14 -5
  25. data/lib/kitchen/platform.rb +19 -0
  26. data/lib/kitchen/provisioner.rb +5 -3
  27. data/lib/kitchen/provisioner/base.rb +46 -48
  28. data/lib/kitchen/provisioner/chef/common_sandbox.rb +322 -0
  29. data/lib/kitchen/provisioner/chef_base.rb +179 -286
  30. data/lib/kitchen/provisioner/chef_solo.rb +11 -5
  31. data/lib/kitchen/provisioner/chef_zero.rb +108 -94
  32. data/lib/kitchen/provisioner/dummy.rb +47 -0
  33. data/lib/kitchen/provisioner/shell.rb +45 -12
  34. data/lib/kitchen/rake_tasks.rb +1 -1
  35. data/lib/kitchen/ssh.rb +1 -1
  36. data/lib/kitchen/thor_tasks.rb +1 -1
  37. data/lib/kitchen/transport.rb +54 -0
  38. data/lib/kitchen/transport/base.rb +146 -0
  39. data/lib/kitchen/transport/dummy.rb +75 -0
  40. data/lib/kitchen/transport/ssh.rb +325 -0
  41. data/lib/kitchen/transport/winrm.rb +508 -0
  42. data/lib/kitchen/transport/winrm/command_executor.rb +188 -0
  43. data/lib/kitchen/transport/winrm/file_transporter.rb +454 -0
  44. data/lib/kitchen/transport/winrm/logging.rb +50 -0
  45. data/lib/kitchen/transport/winrm/template.rb +74 -0
  46. data/lib/kitchen/transport/winrm/tmp_zip.rb +187 -0
  47. data/lib/kitchen/verifier.rb +55 -0
  48. data/lib/kitchen/verifier/base.rb +191 -0
  49. data/lib/kitchen/verifier/busser.rb +266 -0
  50. data/lib/kitchen/verifier/dummy.rb +75 -0
  51. data/lib/kitchen/version.rb +1 -1
  52. data/spec/kitchen/cli_spec.rb +56 -0
  53. data/spec/kitchen/config_spec.rb +61 -20
  54. data/spec/kitchen/configurable_spec.rb +327 -1
  55. data/spec/kitchen/data_munger_spec.rb +777 -14
  56. data/spec/kitchen/driver/base_spec.rb +7 -38
  57. data/spec/kitchen/driver/dummy_spec.rb +0 -29
  58. data/spec/kitchen/driver/ssh_base_spec.rb +580 -236
  59. data/spec/kitchen/driver_spec.rb +1 -0
  60. data/spec/kitchen/instance_spec.rb +383 -83
  61. data/spec/kitchen/login_command_spec.rb +29 -10
  62. data/spec/kitchen/platform_spec.rb +58 -2
  63. data/spec/kitchen/provisioner/base_spec.rb +170 -18
  64. data/spec/kitchen/provisioner/chef_base_spec.rb +454 -104
  65. data/spec/kitchen/provisioner/chef_solo_spec.rb +307 -104
  66. data/spec/kitchen/provisioner/chef_zero_spec.rb +561 -230
  67. data/spec/kitchen/provisioner/dummy_spec.rb +91 -0
  68. data/spec/kitchen/provisioner/shell_spec.rb +158 -56
  69. data/spec/kitchen/provisioner_spec.rb +37 -0
  70. data/spec/kitchen/ssh_spec.rb +19 -19
  71. data/spec/kitchen/transport/base_spec.rb +89 -0
  72. data/spec/kitchen/transport/ssh_spec.rb +1147 -0
  73. data/spec/kitchen/transport/winrm/command_executor_spec.rb +400 -0
  74. data/spec/kitchen/transport/winrm/file_transporter_spec.rb +876 -0
  75. data/spec/kitchen/transport/winrm/logging_spec.rb +92 -0
  76. data/spec/kitchen/transport/winrm/template_spec.rb +51 -0
  77. data/spec/kitchen/transport/winrm/tmp_zip_spec.rb +132 -0
  78. data/spec/kitchen/transport/winrm_spec.rb +1069 -0
  79. data/spec/kitchen/transport_spec.rb +112 -0
  80. data/spec/kitchen/verifier/base_spec.rb +310 -0
  81. data/spec/kitchen/verifier/busser_spec.rb +540 -0
  82. data/spec/kitchen/verifier/dummy_spec.rb +91 -0
  83. data/spec/kitchen/verifier_spec.rb +120 -0
  84. data/spec/kitchen_spec.rb +7 -0
  85. data/spec/spec_helper.rb +8 -0
  86. data/spec/support/powershell_max_size_spec.rb +40 -0
  87. data/support/busser_install_command.ps1 +14 -0
  88. data/support/busser_install_command.sh +15 -0
  89. data/support/check_files.ps1.erb +48 -0
  90. data/support/chef_base_init_command.ps1 +18 -0
  91. data/support/chef_base_init_command.sh +2 -0
  92. data/support/chef_base_install_command.ps1 +76 -0
  93. data/support/chef_base_install_command.sh +137 -0
  94. data/support/chef_zero_prepare_command_legacy.ps1 +9 -0
  95. data/support/chef_zero_prepare_command_legacy.sh +10 -0
  96. data/support/decode_files.ps1.erb +61 -0
  97. data/test-kitchen.gemspec +2 -0
  98. metadata +97 -8
  99. data/lib/kitchen/busser.rb +0 -316
  100. data/spec/kitchen/busser_spec.rb +0 -490
  101. data/support/chef_helpers.sh +0 -16
@@ -18,6 +18,7 @@
18
18
 
19
19
  require_relative "../spec_helper"
20
20
 
21
+ require "kitchen/configurable"
21
22
  require "kitchen/errors"
22
23
  require "kitchen/logging"
23
24
  require "kitchen/shell_out"
@@ -27,6 +27,8 @@ require "kitchen/platform"
27
27
  require "kitchen/provisioner"
28
28
  require "kitchen/provisioner/dummy"
29
29
  require "kitchen/suite"
30
+ require "kitchen/transport/dummy"
31
+ require "kitchen/verifier/dummy"
30
32
 
31
33
  class DummyStateFile
32
34
 
@@ -52,7 +54,7 @@ end
52
54
 
53
55
  class SerialDummyDriver < Kitchen::Driver::Dummy
54
56
 
55
- no_parallel_for :create, :verify, :destroy
57
+ no_parallel_for :create, :destroy
56
58
 
57
59
  attr_reader :action_in_mutex
58
60
 
@@ -66,24 +68,26 @@ class SerialDummyDriver < Kitchen::Driver::Dummy
66
68
  super
67
69
  end
68
70
 
69
- def converge(state)
70
- track_locked(:converge)
71
+ def destroy(state)
72
+ track_locked(:destroy)
71
73
  super
72
74
  end
75
+ end
73
76
 
74
- def setup(state)
75
- track_locked(:setup)
76
- super
77
+ class LegacyDriver < Kitchen::Driver::SSHBase
78
+
79
+ attr_reader :called_converge, :called_setup, :called_verify
80
+
81
+ def converge(_)
82
+ @called_converge
77
83
  end
78
84
 
79
- def verify(state)
80
- track_locked(:verify)
81
- super
85
+ def setup(_)
86
+ @called_setup
82
87
  end
83
88
 
84
- def destroy(state)
85
- track_locked(:destroy)
86
- super
89
+ def verify(_)
90
+ @called_verify
87
91
  end
88
92
  end
89
93
 
@@ -95,12 +99,13 @@ describe Kitchen::Instance do
95
99
  let(:instance) { Kitchen::Instance.new(opts) }
96
100
  let(:provisioner) { Kitchen::Provisioner::Dummy.new({}) }
97
101
  let(:state_file) { DummyStateFile.new }
98
- let(:busser) { Kitchen::Busser.new(suite.name, {}) }
102
+ let(:transport) { Kitchen::Transport::Dummy.new({}) }
103
+ let(:verifier) { Kitchen::Verifier::Dummy.new({}) }
99
104
 
100
105
  let(:opts) do
101
106
  { :suite => suite, :platform => platform, :driver => driver,
102
- :provisioner => provisioner, :busser => busser,
103
- :logger => logger, :state_file => state_file }
107
+ :provisioner => provisioner, :verifier => verifier,
108
+ :logger => logger, :state_file => state_file, :transport => transport }
104
109
  end
105
110
 
106
111
  def suite(name = "suite")
@@ -234,16 +239,38 @@ describe Kitchen::Instance do
234
239
  end
235
240
  end
236
241
 
237
- describe "#busser" do
242
+ describe "#transport" do
243
+
244
+ it "returns its transport" do
245
+ instance.transport.must_equal transport
246
+ end
247
+
248
+ it "raises an ArgumentError if missing" do
249
+ opts.delete(:transport)
250
+ proc { Kitchen::Instance.new(opts) }.must_raise Kitchen::ClientError
251
+ end
252
+
253
+ it "sets Transport#instance to itself" do
254
+ # it's mind-bottling
255
+ instance.transport.instance.must_equal instance
256
+ end
257
+ end
258
+
259
+ describe "#verifier" do
238
260
 
239
- it "returns its busser" do
240
- instance.busser.must_equal busser
261
+ it "returns its verifier" do
262
+ instance.verifier.must_equal verifier
241
263
  end
242
264
 
243
265
  it "raises and ArgumentError if missing" do
244
- opts.delete(:busser)
266
+ opts.delete(:verifier)
245
267
  proc { Kitchen::Instance.new(opts) }.must_raise Kitchen::ClientError
246
268
  end
269
+
270
+ it "sets Verifier#instance to itself" do
271
+ # it's mind-bottling
272
+ instance.verifier.instance.must_equal instance
273
+ end
247
274
  end
248
275
 
249
276
  describe "#state_file" do
@@ -262,10 +289,13 @@ describe Kitchen::Instance do
262
289
  instance.to_str.must_equal "<suite-platform>"
263
290
  end
264
291
 
265
- it "#login executes the driver's login_command" do
292
+ it "#login executes the transport's login_command" do
293
+ conn = stub("connection")
266
294
  state_file.write(:last_action => "create")
267
- driver.stubs(:login_command).with(:last_action => "create").
268
- returns(Kitchen::LoginCommand.new(%w[echo hello], :purple => true))
295
+ transport.stubs(:connection).with(:last_action => "create").
296
+ returns(conn)
297
+ conn.stubs(:login_command).
298
+ returns(Kitchen::LoginCommand.new("echo", ["hello"], :purple => true))
269
299
  Kernel.expects(:exec).with("echo", "hello", :purple => true)
270
300
 
271
301
  instance.login
@@ -283,6 +313,20 @@ describe Kitchen::Instance do
283
313
  instance.diagnose.must_be_instance_of Hash
284
314
  end
285
315
 
316
+ it "sets :platform key to platform's diagnose info" do
317
+ platform.stubs(:diagnose).returns(:a => "b")
318
+
319
+ instance.diagnose[:platform].must_equal(:a => "b")
320
+ end
321
+
322
+ it "sets :platform key to :unknown if obj can't respond to #diagnose" do
323
+ opts[:platform] = Class.new(platform.class) {
324
+ undef_method :diagnose
325
+ }.new(:name => "whoop")
326
+
327
+ instance.diagnose[:platform].must_equal :unknown
328
+ end
329
+
286
330
  it "sets :state_file key to state_file's diganose info" do
287
331
  state_file.stubs(:diagnose).returns(:a => "b")
288
332
 
@@ -311,18 +355,32 @@ describe Kitchen::Instance do
311
355
  instance.diagnose[:provisioner].must_equal :unknown
312
356
  end
313
357
 
314
- it "sets :busser key to busser's diganose info" do
315
- busser.stubs(:diagnose).returns(:a => "b")
358
+ it "sets :verifier key to verifier's diganose info" do
359
+ verifier.stubs(:diagnose).returns(:a => "b")
360
+
361
+ instance.diagnose[:verifier].must_equal(:a => "b")
362
+ end
363
+
364
+ it "sets :verifier key to :unknown if obj can't respond to #diagnose" do
365
+ opts[:verifier] = Class.new(verifier.class) {
366
+ undef_method :diagnose
367
+ }.new({})
368
+
369
+ instance.diagnose[:verifier].must_equal :unknown
370
+ end
371
+
372
+ it "sets :transport key to transport's diganose info" do
373
+ transport.stubs(:diagnose).returns(:a => "b")
316
374
 
317
- instance.diagnose[:busser].must_equal(:a => "b")
375
+ instance.diagnose[:transport].must_equal(:a => "b")
318
376
  end
319
377
 
320
- it "sets :busser key to :unknown if obj can't respond to #diagnose" do
321
- opts[:busser] = Class.new(busser.class) {
378
+ it "sets :transport key to :unknown if obj can't respond to #diagnose" do
379
+ opts[:transport] = Class.new(transport.class) {
322
380
  undef_method :diagnose
323
- }.new(suite.name, {})
381
+ }.new
324
382
 
325
- instance.diagnose[:busser].must_equal :unknown
383
+ instance.diagnose[:transport].must_equal :unknown
326
384
  end
327
385
  end
328
386
 
@@ -382,9 +440,9 @@ describe Kitchen::Instance do
382
440
 
383
441
  describe "with no state" do
384
442
 
385
- it "calls Driver#create and converge with empty state hash" do
443
+ it "calls Driver#create and Provisioner#call with empty state hash" do
386
444
  driver.expects(:create).with(Hash.new)
387
- driver.expects(:converge).
445
+ provisioner.expects(:call).
388
446
  with { |state| state[:last_action] == "create" }
389
447
 
390
448
  instance.converge
@@ -414,8 +472,8 @@ describe Kitchen::Instance do
414
472
 
415
473
  before { state_file.write(:last_action => "create") }
416
474
 
417
- it "calls Driver#converge with state hash" do
418
- driver.expects(:converge).
475
+ it "calls Provisioner#call with state hash" do
476
+ provisioner.expects(:call).
419
477
  with { |state| state[:last_action] == "create" }
420
478
 
421
479
  instance.converge
@@ -432,8 +490,8 @@ describe Kitchen::Instance do
432
490
 
433
491
  before { state_file.write(:last_action => "converge") }
434
492
 
435
- it "calls Driver#converge with state hash" do
436
- driver.expects(:converge).
493
+ it "calls Provisioner#call with state hash" do
494
+ provisioner.expects(:call).
437
495
  with { |state| state[:last_action] == "converge" }
438
496
 
439
497
  instance.converge
@@ -451,12 +509,13 @@ describe Kitchen::Instance do
451
509
 
452
510
  describe "with no state" do
453
511
 
454
- it "calls Driver#create, converge, and setup with empty state hash" do
512
+ it "calls create and converge with empty state hash" do
455
513
  driver.expects(:create).with(Hash.new)
456
- driver.expects(:converge).
514
+ provisioner.expects(:call).
457
515
  with { |state| state[:last_action] == "create" }
458
516
  driver.expects(:setup).
459
- with { |state| state[:last_action] == "converge" }
517
+ with { |state| state[:last_action] == "converge" }.
518
+ never
460
519
 
461
520
  instance.setup
462
521
  end
@@ -485,11 +544,12 @@ describe Kitchen::Instance do
485
544
 
486
545
  before { state_file.write(:last_action => "create") }
487
546
 
488
- it "calls Driver#converge and setup with state hash" do
489
- driver.expects(:converge).
547
+ it "calls Provisioner#call with state hash" do
548
+ provisioner.expects(:call).
490
549
  with { |state| state[:last_action] == "create" }
491
550
  driver.expects(:setup).
492
- with { |state| state[:last_action] == "converge" }
551
+ with { |state| state[:last_action] == "converge" }.
552
+ never
493
553
 
494
554
  instance.setup
495
555
  end
@@ -505,9 +565,10 @@ describe Kitchen::Instance do
505
565
 
506
566
  before { state_file.write(:last_action => "converge") }
507
567
 
508
- it "calls Driver#setup with state hash" do
568
+ it "calls nothing with state hash" do
509
569
  driver.expects(:setup).
510
- with { |state| state[:last_action] == "converge" }
570
+ with { |state| state[:last_action] == "converge" }.
571
+ never
511
572
 
512
573
  instance.setup
513
574
  end
@@ -523,9 +584,10 @@ describe Kitchen::Instance do
523
584
 
524
585
  before { state_file.write(:last_action => "setup") }
525
586
 
526
- it "calls Driver#setup with state hash" do
587
+ it "calls nothing with state hash" do
527
588
  driver.expects(:setup).
528
- with { |state| state[:last_action] == "setup" }
589
+ with { |state| state[:last_action] == "setup" }.
590
+ never
529
591
 
530
592
  instance.setup
531
593
  end
@@ -542,13 +604,14 @@ describe Kitchen::Instance do
542
604
 
543
605
  describe "with no state" do
544
606
 
545
- it "calls Driver#create, converge, setup, and verify with empty state hash" do
607
+ it "calls create, converge, and verify with empty state hash" do
546
608
  driver.expects(:create).with(Hash.new)
547
- driver.expects(:converge).
609
+ provisioner.expects(:call).
548
610
  with { |state| state[:last_action] == "create" }
549
611
  driver.expects(:setup).
550
- with { |state| state[:last_action] == "converge" }
551
- driver.expects(:verify).
612
+ with { |state| state[:last_action] == "converge" }.
613
+ never
614
+ verifier.expects(:call).
552
615
  with { |state| state[:last_action] == "setup" }
553
616
 
554
617
  instance.verify
@@ -578,12 +641,13 @@ describe Kitchen::Instance do
578
641
 
579
642
  before { state_file.write(:last_action => "create") }
580
643
 
581
- it "calls Driver#converge, setup, and verify with state hash" do
582
- driver.expects(:converge).
644
+ it "calls converge, and verify with state hash" do
645
+ provisioner.expects(:call).
583
646
  with { |state| state[:last_action] == "create" }
584
647
  driver.expects(:setup).
585
- with { |state| state[:last_action] == "converge" }
586
- driver.expects(:verify).
648
+ with { |state| state[:last_action] == "converge" }.
649
+ never
650
+ verifier.expects(:call).
587
651
  with { |state| state[:last_action] == "setup" }
588
652
 
589
653
  instance.verify
@@ -600,10 +664,11 @@ describe Kitchen::Instance do
600
664
 
601
665
  before { state_file.write(:last_action => "converge") }
602
666
 
603
- it "calls Driver#setup, and verify with state hash" do
667
+ it "calls Verifier#call with state hash" do
604
668
  driver.expects(:setup).
605
- with { |state| state[:last_action] == "converge" }
606
- driver.expects(:verify).
669
+ with { |state| state[:last_action] == "converge" }.
670
+ never
671
+ verifier.expects(:call).
607
672
  with { |state| state[:last_action] == "setup" }
608
673
 
609
674
  instance.verify
@@ -620,8 +685,8 @@ describe Kitchen::Instance do
620
685
 
621
686
  before { state_file.write(:last_action => "setup") }
622
687
 
623
- it "calls Driver#verify with state hash" do
624
- driver.expects(:verify).
688
+ it "calls Verifier#call with state hash" do
689
+ verifier.expects(:call).
625
690
  with { |state| state[:last_action] == "setup" }
626
691
 
627
692
  instance.verify
@@ -638,8 +703,8 @@ describe Kitchen::Instance do
638
703
 
639
704
  before { state_file.write(:last_action => "verify") }
640
705
 
641
- it "calls Driver#verify with state hash" do
642
- driver.expects(:verify).
706
+ it "calls Verifier#call with state hash" do
707
+ verifier.expects(:call).
643
708
  with { |state| state[:last_action] == "verify" }
644
709
 
645
710
  instance.verify
@@ -710,12 +775,11 @@ describe Kitchen::Instance do
710
775
 
711
776
  describe "with no state" do
712
777
 
713
- it "calls Driver#destroy, create, converge, setup, verify, destroy" do
778
+ it "calls destroy, create, converge, setup, verify, destroy" do
714
779
  driver.expects(:destroy)
715
780
  driver.expects(:create)
716
- driver.expects(:converge)
717
- driver.expects(:setup)
718
- driver.expects(:verify)
781
+ provisioner.expects(:call)
782
+ verifier.expects(:call)
719
783
  driver.expects(:destroy)
720
784
 
721
785
  instance.test
@@ -741,12 +805,11 @@ describe Kitchen::Instance do
741
805
 
742
806
  before { state_file.write(:last_action => action) }
743
807
 
744
- it "calls Driver#destroy, create, converge, setup, verify, destroy" do
808
+ it "calls destroy, create, converge, setup, verify, destroy" do
745
809
  driver.expects(:destroy)
746
810
  driver.expects(:create)
747
- driver.expects(:converge)
748
- driver.expects(:setup)
749
- driver.expects(:verify)
811
+ provisioner.expects(:call)
812
+ verifier.expects(:call)
750
813
  driver.expects(:destroy)
751
814
 
752
815
  instance.test
@@ -756,12 +819,11 @@ describe Kitchen::Instance do
756
819
 
757
820
  describe "with destroy mode of never" do
758
821
 
759
- it "calls Driver#destroy, create, converge, setup, verify" do
822
+ it "calls destroy, create, converge, setup, verify" do
760
823
  driver.expects(:destroy).once
761
824
  driver.expects(:create)
762
- driver.expects(:converge)
763
- driver.expects(:setup)
764
- driver.expects(:verify)
825
+ provisioner.expects(:call)
826
+ verifier.expects(:call)
765
827
 
766
828
  instance.test(:never)
767
829
  end
@@ -769,10 +831,10 @@ describe Kitchen::Instance do
769
831
 
770
832
  describe "with destroy mode of always" do
771
833
 
772
- it "calls Driver#destroy at even when action fails" do
834
+ it "calls destroy at even when action fails" do
773
835
  driver.expects(:destroy)
774
836
  driver.expects(:create)
775
- driver.expects(:converge).raises(Kitchen::ActionFailed)
837
+ provisioner.expects(:call).raises(Kitchen::ActionFailed)
776
838
  driver.expects(:destroy)
777
839
 
778
840
  begin
@@ -801,11 +863,10 @@ describe Kitchen::Instance do
801
863
 
802
864
  before { state_file.write(:last_action => "create") }
803
865
 
804
- it "calls Driver#remote_command with state and command" do
805
- driver.expects(:remote_command).with do |state, command|
806
- state.must_equal(:last_action => "create")
807
- command.must_equal "uptime"
808
- end
866
+ it "calls Transport#execute with command" do
867
+ connection = mock("connection")
868
+ connection.expects(:execute).with("uptime")
869
+ transport.stubs(:connection).yields(connection)
809
870
 
810
871
  instance.remote_exec("uptime")
811
872
  end
@@ -901,7 +962,7 @@ describe Kitchen::Instance do
901
962
  describe "crashes preserve last action for desired verify action" do
902
963
 
903
964
  before do
904
- driver.stubs(:verify).raises(Kitchen::ActionFailed, "death")
965
+ verifier.stubs(:call).raises(Kitchen::ActionFailed, "death")
905
966
  end
906
967
 
907
968
  [:create, :converge, :setup].each do |action|
@@ -938,12 +999,251 @@ describe Kitchen::Instance do
938
999
  instance.test
939
1000
 
940
1001
  driver.action_in_mutex[:create].must_equal true
941
- driver.action_in_mutex[:converge].must_equal false
942
- driver.action_in_mutex[:setup].must_equal false
943
- driver.action_in_mutex[:verify].must_equal true
944
1002
  driver.action_in_mutex[:destroy].must_equal true
945
1003
  end
946
1004
  end
1005
+
1006
+ describe "with legacy Driver::SSHBase subclasses" do
1007
+
1008
+ let(:driver) { LegacyDriver.new({}) }
1009
+
1010
+ describe "#converge" do
1011
+
1012
+ describe "with no state" do
1013
+
1014
+ it "calls Driver#create and Driver#converge with empty state hash" do
1015
+ driver.expects(:create).with(Hash.new)
1016
+ driver.expects(:converge).
1017
+ with { |state| state[:last_action] == "create" }
1018
+
1019
+ instance.converge
1020
+ end
1021
+ end
1022
+
1023
+ describe "with last action of create" do
1024
+
1025
+ before { state_file.write(:last_action => "create") }
1026
+
1027
+ it "calls Driver#converge with state hash" do
1028
+ driver.expects(:converge).
1029
+ with { |state| state[:last_action] == "create" }
1030
+
1031
+ instance.converge
1032
+ end
1033
+ end
1034
+
1035
+ describe "with last action of converge" do
1036
+
1037
+ before { state_file.write(:last_action => "converge") }
1038
+
1039
+ it "calls Driver#converge with state hash" do
1040
+ driver.expects(:converge).
1041
+ with { |state| state[:last_action] == "converge" }
1042
+
1043
+ instance.converge
1044
+ end
1045
+ end
1046
+ end
1047
+
1048
+ describe "#setup" do
1049
+
1050
+ describe "with no state" do
1051
+
1052
+ it "calls create, converge, and setup with empty state hash" do
1053
+ driver.expects(:create).with(Hash.new)
1054
+ driver.expects(:converge).
1055
+ with { |state| state[:last_action] == "create" }
1056
+ driver.expects(:setup).
1057
+ with { |state| state[:last_action] == "converge" }
1058
+
1059
+ instance.setup
1060
+ end
1061
+ end
1062
+
1063
+ describe "with last action of create" do
1064
+
1065
+ before { state_file.write(:last_action => "create") }
1066
+
1067
+ it "calls Provisioner#call and setup with state hash" do
1068
+ driver.expects(:converge).
1069
+ with { |state| state[:last_action] == "create" }
1070
+ driver.expects(:setup).
1071
+ with { |state| state[:last_action] == "converge" }
1072
+
1073
+ instance.setup
1074
+ end
1075
+ end
1076
+
1077
+ describe "with last action of converge" do
1078
+
1079
+ before { state_file.write(:last_action => "converge") }
1080
+
1081
+ it "calls Driver#setup with state hash" do
1082
+ driver.expects(:setup).
1083
+ with { |state| state[:last_action] == "converge" }
1084
+
1085
+ instance.setup
1086
+ end
1087
+ end
1088
+
1089
+ describe "with last action of setup" do
1090
+
1091
+ before { state_file.write(:last_action => "setup") }
1092
+
1093
+ it "calls Driver#setup with state hash" do
1094
+ driver.expects(:setup).
1095
+ with { |state| state[:last_action] == "setup" }
1096
+
1097
+ instance.setup
1098
+ end
1099
+ end
1100
+ end
1101
+
1102
+ describe "#verify" do
1103
+
1104
+ describe "with no state" do
1105
+
1106
+ it "calls create, converge, setup, and verify with empty state hash" do
1107
+ driver.expects(:create).with(Hash.new)
1108
+ driver.expects(:converge).
1109
+ with { |state| state[:last_action] == "create" }
1110
+ driver.expects(:setup).
1111
+ with { |state| state[:last_action] == "converge" }
1112
+ driver.expects(:verify).
1113
+ with { |state| state[:last_action] == "setup" }
1114
+
1115
+ instance.verify
1116
+ end
1117
+ end
1118
+
1119
+ describe "with last of create" do
1120
+
1121
+ before { state_file.write(:last_action => "create") }
1122
+
1123
+ it "calls converge, setup, and verify with state hash" do
1124
+ driver.expects(:converge).
1125
+ with { |state| state[:last_action] == "create" }
1126
+ driver.expects(:setup).
1127
+ with { |state| state[:last_action] == "converge" }
1128
+ driver.expects(:verify).
1129
+ with { |state| state[:last_action] == "setup" }
1130
+
1131
+ instance.verify
1132
+ end
1133
+ end
1134
+
1135
+ describe "with last of converge" do
1136
+
1137
+ before { state_file.write(:last_action => "converge") }
1138
+
1139
+ it "calls Driver#setup, and verify with state hash" do
1140
+ driver.expects(:setup).
1141
+ with { |state| state[:last_action] == "converge" }
1142
+ driver.expects(:verify).
1143
+ with { |state| state[:last_action] == "setup" }
1144
+
1145
+ instance.verify
1146
+ end
1147
+ end
1148
+
1149
+ describe "with last of setup" do
1150
+
1151
+ before { state_file.write(:last_action => "setup") }
1152
+
1153
+ it "calls Driver#verify with state hash" do
1154
+ driver.expects(:verify).
1155
+ with { |state| state[:last_action] == "setup" }
1156
+
1157
+ instance.verify
1158
+ end
1159
+ end
1160
+
1161
+ describe "with last of verify" do
1162
+
1163
+ before { state_file.write(:last_action => "verify") }
1164
+
1165
+ it "calls Driver#verify with state hash" do
1166
+ driver.expects(:verify).
1167
+ with { |state| state[:last_action] == "verify" }
1168
+
1169
+ instance.verify
1170
+ end
1171
+ end
1172
+ end
1173
+
1174
+ describe "#test" do
1175
+
1176
+ describe "with no state" do
1177
+
1178
+ it "calls destroy, create, converge, setup, verify, destroy" do
1179
+ driver.expects(:destroy)
1180
+ driver.expects(:create)
1181
+ driver.expects(:converge)
1182
+ driver.expects(:setup)
1183
+ driver.expects(:verify)
1184
+ driver.expects(:destroy)
1185
+
1186
+ instance.test
1187
+ end
1188
+ end
1189
+
1190
+ [:create, :converge, :setup, :verify].each do |action|
1191
+
1192
+ describe "with last action of #{action}" do
1193
+
1194
+ before { state_file.write(:last_action => action) }
1195
+
1196
+ it "calls destroy, create, converge, setup, verify, destroy" do
1197
+ driver.expects(:destroy)
1198
+ driver.expects(:create)
1199
+ driver.expects(:converge)
1200
+ driver.expects(:setup)
1201
+ driver.expects(:verify)
1202
+ driver.expects(:destroy)
1203
+
1204
+ instance.test
1205
+ end
1206
+ end
1207
+ end
1208
+
1209
+ describe "with destroy mode of never" do
1210
+
1211
+ it "calls destroy, create, converge, setup, verify" do
1212
+ driver.expects(:destroy).once
1213
+ driver.expects(:create)
1214
+ driver.expects(:converge)
1215
+ driver.expects(:setup)
1216
+ driver.expects(:verify)
1217
+
1218
+ instance.test(:never)
1219
+ end
1220
+ end
1221
+
1222
+ describe "with destroy mode of always" do
1223
+
1224
+ it "calls destroy at even when action fails" do
1225
+ driver.expects(:destroy)
1226
+ driver.expects(:create)
1227
+ driver.expects(:converge).raises(Kitchen::ActionFailed)
1228
+ driver.expects(:destroy)
1229
+
1230
+ begin
1231
+ instance.test(:always)
1232
+ rescue # rubocop:disable Lint/HandleExceptions
1233
+ end
1234
+ end
1235
+ end
1236
+ end
1237
+
1238
+ it "#login executes the driver's login_command" do
1239
+ state_file.write(:last_action => "create")
1240
+ driver.stubs(:login_command).with(:last_action => "create").
1241
+ returns(Kitchen::LoginCommand.new("echo", ["hello"], :purple => true))
1242
+ Kernel.expects(:exec).with("echo", "hello", :purple => true)
1243
+
1244
+ instance.login
1245
+ end
1246
+ end
947
1247
  end
948
1248
 
949
1249
  describe Kitchen::Instance::FSM do