vagrant 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/Gemfile +4 -4
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/bin/vagrant +5 -13
  5. data/config/default.rb +1 -0
  6. data/keys/README.md +8 -1
  7. data/keys/vagrant.ppk +26 -0
  8. data/lib/vagrant.rb +3 -3
  9. data/lib/vagrant/actions/base.rb +15 -4
  10. data/lib/vagrant/actions/box/add.rb +1 -1
  11. data/lib/vagrant/actions/box/download.rb +72 -66
  12. data/lib/vagrant/actions/box/unpackage.rb +1 -4
  13. data/lib/vagrant/actions/runner.rb +1 -1
  14. data/lib/vagrant/actions/vm/boot.rb +5 -7
  15. data/lib/vagrant/actions/vm/customize.rb +2 -2
  16. data/lib/vagrant/actions/vm/destroy.rb +2 -2
  17. data/lib/vagrant/actions/vm/down.rb +7 -0
  18. data/lib/vagrant/actions/vm/export.rb +10 -4
  19. data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
  20. data/lib/vagrant/actions/vm/halt.rb +5 -3
  21. data/lib/vagrant/actions/vm/import.rb +10 -3
  22. data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
  23. data/lib/vagrant/actions/vm/package.rb +33 -10
  24. data/lib/vagrant/actions/vm/provision.rb +4 -4
  25. data/lib/vagrant/actions/vm/reload.rb +1 -1
  26. data/lib/vagrant/actions/vm/resume.rb +1 -1
  27. data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
  28. data/lib/vagrant/actions/vm/start.rb +3 -2
  29. data/lib/vagrant/actions/vm/suspend.rb +2 -2
  30. data/lib/vagrant/actions/vm/up.rb +7 -17
  31. data/lib/vagrant/active_list.rb +52 -45
  32. data/lib/vagrant/box.rb +18 -11
  33. data/lib/vagrant/busy.rb +7 -0
  34. data/lib/vagrant/command.rb +27 -0
  35. data/lib/vagrant/commands/base.rb +163 -0
  36. data/lib/vagrant/commands/box.rb +16 -0
  37. data/lib/vagrant/commands/box/add.rb +24 -0
  38. data/lib/vagrant/commands/box/list.rb +30 -0
  39. data/lib/vagrant/commands/box/remove.rb +31 -0
  40. data/lib/vagrant/commands/destroy.rb +23 -0
  41. data/lib/vagrant/commands/down.rb +16 -0
  42. data/lib/vagrant/commands/halt.rb +23 -0
  43. data/lib/vagrant/commands/init.rb +32 -0
  44. data/lib/vagrant/commands/package.rb +46 -0
  45. data/lib/vagrant/commands/reload.rb +22 -0
  46. data/lib/vagrant/commands/resume.rb +22 -0
  47. data/lib/vagrant/commands/ssh.rb +22 -0
  48. data/lib/vagrant/commands/ssh_config.rb +30 -0
  49. data/lib/vagrant/commands/status.rb +58 -0
  50. data/lib/vagrant/commands/suspend.rb +23 -0
  51. data/lib/vagrant/commands/up.rb +26 -0
  52. data/lib/vagrant/config.rb +21 -11
  53. data/lib/vagrant/downloaders/file.rb +5 -5
  54. data/lib/vagrant/downloaders/http.rb +10 -15
  55. data/lib/vagrant/environment.rb +259 -0
  56. data/lib/vagrant/provisioners/base.rb +7 -0
  57. data/lib/vagrant/provisioners/chef.rb +24 -9
  58. data/lib/vagrant/provisioners/chef_server.rb +23 -48
  59. data/lib/vagrant/provisioners/chef_solo.rb +48 -22
  60. data/lib/vagrant/ssh.rb +95 -46
  61. data/lib/vagrant/util.rb +2 -2
  62. data/lib/vagrant/util/errors.rb +36 -0
  63. data/lib/vagrant/util/platform.rb +12 -0
  64. data/lib/vagrant/util/progress_meter.rb +33 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +1 -0
  68. data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
  69. data/templates/chef_server_client.erb +16 -0
  70. data/templates/chef_solo_solo.erb +4 -0
  71. data/templates/errors.yml +157 -0
  72. data/templates/package_Vagrantfile.erb +11 -0
  73. data/templates/ssh_config.erb +7 -0
  74. data/test/test_helper.rb +12 -15
  75. data/test/vagrant/actions/box/add_test.rb +1 -2
  76. data/test/vagrant/actions/box/destroy_test.rb +0 -1
  77. data/test/vagrant/actions/box/download_test.rb +40 -15
  78. data/test/vagrant/actions/box/unpackage_test.rb +2 -3
  79. data/test/vagrant/actions/collection_test.rb +8 -5
  80. data/test/vagrant/actions/runner_test.rb +8 -6
  81. data/test/vagrant/actions/vm/boot_test.rb +12 -11
  82. data/test/vagrant/actions/vm/customize_test.rb +2 -3
  83. data/test/vagrant/actions/vm/destroy_test.rb +2 -3
  84. data/test/vagrant/actions/vm/down_test.rb +16 -3
  85. data/test/vagrant/actions/vm/export_test.rb +4 -5
  86. data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
  87. data/test/vagrant/actions/vm/halt_test.rb +8 -2
  88. data/test/vagrant/actions/vm/import_test.rb +5 -5
  89. data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
  90. data/test/vagrant/actions/vm/package_test.rb +60 -22
  91. data/test/vagrant/actions/vm/provision_test.rb +7 -16
  92. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  93. data/test/vagrant/actions/vm/resume_test.rb +0 -1
  94. data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
  95. data/test/vagrant/actions/vm/start_test.rb +10 -3
  96. data/test/vagrant/actions/vm/suspend_test.rb +1 -2
  97. data/test/vagrant/actions/vm/up_test.rb +19 -11
  98. data/test/vagrant/active_list_test.rb +148 -129
  99. data/test/vagrant/box_test.rb +26 -14
  100. data/test/vagrant/busy_test.rb +15 -6
  101. data/test/vagrant/command_test.rb +53 -0
  102. data/test/vagrant/commands/base_test.rb +118 -0
  103. data/test/vagrant/commands/box/add_test.rb +34 -0
  104. data/test/vagrant/commands/box/list_test.rb +32 -0
  105. data/test/vagrant/commands/box/remove_test.rb +41 -0
  106. data/test/vagrant/commands/destroy_test.rb +32 -0
  107. data/test/vagrant/commands/down_test.rb +17 -0
  108. data/test/vagrant/commands/halt_test.rb +28 -0
  109. data/test/vagrant/commands/init_test.rb +55 -0
  110. data/test/vagrant/commands/package_test.rb +84 -0
  111. data/test/vagrant/commands/reload_test.rb +28 -0
  112. data/test/vagrant/commands/resume_test.rb +33 -0
  113. data/test/vagrant/commands/ssh_config_test.rb +54 -0
  114. data/test/vagrant/commands/ssh_test.rb +32 -0
  115. data/test/vagrant/commands/status_test.rb +20 -0
  116. data/test/vagrant/commands/suspend_test.rb +33 -0
  117. data/test/vagrant/commands/up_test.rb +41 -0
  118. data/test/vagrant/config_test.rb +42 -17
  119. data/test/vagrant/downloaders/file_test.rb +7 -0
  120. data/test/vagrant/downloaders/http_test.rb +12 -0
  121. data/test/vagrant/environment_test.rb +595 -0
  122. data/test/vagrant/provisioners/base_test.rb +7 -1
  123. data/test/vagrant/provisioners/chef_server_test.rb +41 -51
  124. data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
  125. data/test/vagrant/provisioners/chef_test.rb +61 -15
  126. data/test/vagrant/ssh_test.rb +166 -38
  127. data/test/vagrant/util/errors_test.rb +57 -0
  128. data/test/vagrant/util/progress_meter_test.rb +33 -0
  129. data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
  130. data/test/vagrant/util/template_renderer_test.rb +138 -0
  131. data/test/vagrant/vm_test.rb +3 -2
  132. data/vagrant.gemspec +88 -33
  133. metadata +94 -51
  134. data/bin/vagrant-box +0 -34
  135. data/bin/vagrant-down +0 -27
  136. data/bin/vagrant-halt +0 -28
  137. data/bin/vagrant-init +0 -27
  138. data/bin/vagrant-package +0 -29
  139. data/bin/vagrant-reload +0 -29
  140. data/bin/vagrant-resume +0 -27
  141. data/bin/vagrant-ssh +0 -27
  142. data/bin/vagrant-status +0 -29
  143. data/bin/vagrant-suspend +0 -27
  144. data/bin/vagrant-up +0 -29
  145. data/lib/vagrant/commands.rb +0 -234
  146. data/lib/vagrant/env.rb +0 -189
  147. data/lib/vagrant/stacked_proc_runner.rb +0 -33
  148. data/test/vagrant/commands_test.rb +0 -269
  149. data/test/vagrant/env_test.rb +0 -418
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsDownTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Down
6
+
7
+ @env = mock_environment
8
+ @instance = @klass.new(@env)
9
+ end
10
+
11
+ context "executing" do
12
+ should "just error and exit" do
13
+ @instance.expects(:error_and_exit).with(:command_deprecation_down)
14
+ @instance.execute
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsHaltTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Halt
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ should "require a persisted VM" do
19
+ @env.expects(:require_persisted_vm).once
20
+ @instance.execute
21
+ end
22
+
23
+ should "call the `halt` action on the VM" do
24
+ @persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Halt).once
25
+ @instance.execute
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,55 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsInitTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Init
6
+
7
+ @env = mock_environment
8
+ @instance = @klass.new(@env)
9
+ end
10
+
11
+ context "execute" do
12
+ should "create the vagrantfile with the first arg" do
13
+ args = [:foo]
14
+ @instance.expects(:create_vagrantfile).with(args.first)
15
+ @instance.execute(args)
16
+ end
17
+ end
18
+
19
+ context "creating the vagrantfile" do
20
+ setup do
21
+ @file = mock("file")
22
+ @file.stubs(:write)
23
+ File.stubs(:open).yields(@file)
24
+ @rootfile_path = File.join(Dir.pwd, Vagrant::Environment::ROOTFILE_NAME)
25
+
26
+ Vagrant::Util::TemplateRenderer.stubs(:render)
27
+ end
28
+
29
+ should "error and exit if a rootfile already exists" do
30
+ File.expects(:exist?).with(@rootfile_path).returns(true)
31
+ @instance.expects(:error_and_exit).with(:rootfile_already_exists).once
32
+ @instance.create_vagrantfile
33
+ end
34
+
35
+ should "write to the rootfile path using the template renderer" do
36
+ result = "foo"
37
+ Vagrant::Util::TemplateRenderer.expects(:render).returns(result).once
38
+ @file.expects(:write).with(result).once
39
+ File.expects(:open).with(@rootfile_path, 'w+').yields(@file)
40
+
41
+ @instance.create_vagrantfile
42
+ end
43
+
44
+ should "use the given base box if given" do
45
+ box = "zooo"
46
+ Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => box)
47
+ @instance.create_vagrantfile(box)
48
+ end
49
+
50
+ should "use the default `base` if no box is given" do
51
+ Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => "base")
52
+ @instance.create_vagrantfile
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,84 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsPackageTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Package
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @persisted_vm.stubs(:package)
20
+ @persisted_vm.stubs(:powered_off?).returns(true)
21
+ end
22
+
23
+ context "with no base specified" do
24
+ should "require a persisted vm" do
25
+ @env.expects(:require_persisted_vm).once
26
+ @instance.execute
27
+ end
28
+ end
29
+
30
+ context "with base specified" do
31
+ setup do
32
+ @vm = mock("vm")
33
+
34
+ Vagrant::VM.stubs(:find).with(@name).returns(@vm)
35
+ @vm.stubs(:env=).with(@env)
36
+ @env.stubs(:vm=)
37
+
38
+ @name = "bar"
39
+ end
40
+
41
+ should "find the given base and set it on the env" do
42
+ Vagrant::VM.expects(:find).with(@name).returns(@vm)
43
+ @vm.expects(:env=).with(@env)
44
+ @env.expects(:vm=).with(@vm)
45
+
46
+ @instance.execute(["foo", "--base", @name])
47
+ end
48
+
49
+ should "error if the VM is not found" do
50
+ Vagrant::VM.expects(:find).with(@name).returns(nil)
51
+ @instance.expects(:error_and_exit).with(:vm_base_not_found, :name => @name).once
52
+
53
+ @instance.execute(["foo", "--base", @name])
54
+ end
55
+ end
56
+
57
+ context "shared (with and without base specified)" do
58
+ should "error and exit if the VM is not powered off" do
59
+ @persisted_vm.stubs(:powered_off?).returns(false)
60
+ @instance.expects(:error_and_exit).with(:vm_power_off_to_package).once
61
+ @persisted_vm.expects(:package).never
62
+ @instance.execute
63
+ end
64
+
65
+ should "call package on the persisted VM" do
66
+ @persisted_vm.expects(:package).once
67
+ @instance.execute
68
+ end
69
+
70
+ should "pass the out path and include_files to the package method" do
71
+ out_path = mock("out_path")
72
+ include_files = "foo"
73
+ @persisted_vm.expects(:package).with(out_path, [include_files]).once
74
+ @instance.execute([out_path, "--include", include_files])
75
+ end
76
+
77
+ should "default to an empty array when not include_files are specified" do
78
+ out_path = mock("out_path")
79
+ @persisted_vm.expects(:package).with(out_path, []).once
80
+ @instance.execute([out_path])
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsReloadTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Reload
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ should "require a persisted VM" do
19
+ @env.expects(:require_persisted_vm).once
20
+ @instance.execute
21
+ end
22
+
23
+ should "call the `reload` action on the VM" do
24
+ @persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once
25
+ @instance.execute
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsResumeTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Resume
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @persisted_vm.stubs(:resume)
20
+ @persisted_vm.stubs(:saved?).returns(true)
21
+ end
22
+
23
+ should "require a persisted VM" do
24
+ @env.expects(:require_persisted_vm).once
25
+ @instance.execute
26
+ end
27
+
28
+ should "save the state of the VM" do
29
+ @persisted_vm.expects(:resume).once
30
+ @instance.execute
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,54 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsSSHConfigTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::SSHConfig
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @ssh = mock("ssh")
20
+ @ssh.stubs(:port).returns(2197)
21
+ @env.stubs(:ssh).returns(@ssh)
22
+ @env.stubs(:require_root_path)
23
+
24
+ @instance.stubs(:puts)
25
+
26
+ @data = {
27
+ :host_key => "vagrant",
28
+ :ssh_user => @env.config.ssh.username,
29
+ :ssh_port => @env.ssh.port,
30
+ :private_key_path => @env.config.ssh.private_key_path
31
+ }
32
+ end
33
+
34
+ should "require root path" do
35
+ @env.expects(:require_root_path).once
36
+ @instance.execute
37
+ end
38
+
39
+ should "output rendered template" do
40
+ result = mock("result")
41
+ Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", @data).returns(result)
42
+
43
+ @instance.expects(:puts).with(result).once
44
+ @instance.execute
45
+ end
46
+
47
+ should "render with the given host name if given" do
48
+ host = "foo"
49
+ @data[:host_key] = host
50
+ Vagrant::Util::TemplateRenderer.expects(:render).with("ssh_config", @data)
51
+ @instance.execute(["--host", host])
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsSSHTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::SSH
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @env.ssh.stubs(:connect)
20
+ end
21
+
22
+ should "require a persisted VM" do
23
+ @env.expects(:require_persisted_vm).once
24
+ @instance.execute
25
+ end
26
+
27
+ should "connect to SSH" do
28
+ @env.ssh.expects(:connect).once
29
+ @instance.execute
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsStatusTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Status
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ # TODO
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsSuspendTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Suspend
6
+
7
+ @persisted_vm = mock("persisted_vm")
8
+ @persisted_vm.stubs(:execute!)
9
+
10
+ @env = mock_environment
11
+ @env.stubs(:require_persisted_vm)
12
+ @env.stubs(:vm).returns(@persisted_vm)
13
+
14
+ @instance = @klass.new(@env)
15
+ end
16
+
17
+ context "executing" do
18
+ setup do
19
+ @persisted_vm.stubs(:suspend)
20
+ @persisted_vm.stubs(:saved?).returns(false)
21
+ end
22
+
23
+ should "require a persisted VM" do
24
+ @env.expects(:require_persisted_vm).once
25
+ @instance.execute
26
+ end
27
+
28
+ should "suspend the VM" do
29
+ @persisted_vm.expects(:suspend).once
30
+ @instance.execute
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class CommandsUpTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Commands::Up
6
+
7
+ @env = mock_environment
8
+ @instance = @klass.new(@env)
9
+
10
+ @persisted_vm = mock("persisted_vm")
11
+ @persisted_vm.stubs(:execute!)
12
+ end
13
+
14
+ context "executing" do
15
+ setup do
16
+ @new_vm = mock("vm")
17
+ @new_vm.stubs(:execute!)
18
+
19
+ @env.stubs(:vm).returns(nil)
20
+ @env.stubs(:require_box)
21
+ @env.stubs(:create_vm).returns(@new_vm)
22
+ end
23
+
24
+ should "require a box" do
25
+ @env.expects(:require_box).once
26
+ @instance.execute
27
+ end
28
+
29
+ should "call the up action on VM if it doesn't exist" do
30
+ @new_vm.expects(:execute!).with(Vagrant::Actions::VM::Up).once
31
+ @instance.execute
32
+ end
33
+
34
+ should "call start on the persisted vm if it exists" do
35
+ @env.stubs(:vm).returns(@persisted_vm)
36
+ @persisted_vm.expects(:start).once
37
+ @env.expects(:create_vm).never
38
+ @instance.execute
39
+ end
40
+ end
41
+ end
@@ -2,10 +2,14 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class ConfigTest < Test::Unit::TestCase
4
4
  context "the ssh config" do
5
+ setup do
6
+ @env = mock_environment
7
+ @env.stubs(:root_path).returns("foo")
8
+ end
9
+
5
10
  should "expand any path when requesting the value" do
6
- Vagrant::Env.stubs(:root_path).returns('foo')
7
- File.stubs(:expand_path).with(Vagrant.config.ssh[:private_key_path], 'foo').returns('success')
8
- assert Vagrant.config.ssh.private_key_path, 'success'
11
+ result = File.expand_path(@env.config.ssh[:private_key_path], @env.root_path)
12
+ assert_equal result, @env.config.ssh.private_key_path
9
13
  end
10
14
  end
11
15
 
@@ -40,6 +44,12 @@ class ConfigTest < Test::Unit::TestCase
40
44
  Vagrant::Config.reset!
41
45
  assert Vagrant::Config.proc_stack.empty?
42
46
  end
47
+
48
+ should "reload the config object based on the given environment" do
49
+ env = mock("env")
50
+ Vagrant::Config.expects(:config).with(env).once
51
+ Vagrant::Config.reset!(env)
52
+ end
43
53
  end
44
54
 
45
55
  context "accessing configuration" do
@@ -78,6 +88,12 @@ class ConfigTest < Test::Unit::TestCase
78
88
  Vagrant::Config.execute!
79
89
  assert Vagrant::Config.config.loaded?
80
90
  end
91
+
92
+ should "return the configuration on execute!" do
93
+ Vagrant::Config.run {}
94
+ result = Vagrant::Config.execute!
95
+ assert result.equal?(Vagrant.config)
96
+ end
81
97
  end
82
98
 
83
99
  context "base class" do
@@ -105,12 +121,20 @@ class ConfigTest < Test::Unit::TestCase
105
121
  end
106
122
  end
107
123
 
108
- should "convert instance variable hash to json" do
109
- @json = mock("json")
110
- @iv_hash = mock("iv_hash")
111
- @iv_hash.expects(:to_json).once.returns(@json)
112
- @base.expects(:instance_variables_hash).returns(@iv_hash)
113
- assert_equal @json, @base.to_json
124
+ context "converting to JSON" do
125
+ should "convert instance variable hash to json" do
126
+ @json = mock("json")
127
+ @iv_hash = mock("iv_hash")
128
+ @iv_hash.expects(:to_json).once.returns(@json)
129
+ @base.expects(:instance_variables_hash).returns(@iv_hash)
130
+ assert_equal @json, @base.to_json
131
+ end
132
+
133
+ should "not include env in the JSON hash" do
134
+ @base.env = "FOO"
135
+ hash = @base.instance_variables_hash
136
+ assert !hash.has_key?(:env)
137
+ end
114
138
  end
115
139
  end
116
140
 
@@ -138,21 +162,25 @@ class ConfigTest < Test::Unit::TestCase
138
162
  end
139
163
 
140
164
  should "initialize each configurer and set it to its key" do
165
+ env = mock('env')
166
+
141
167
  5.times do |i|
142
168
  key = "key#{i}"
143
169
  klass = mock("klass#{i}")
144
170
  instance = mock("instance#{i}")
171
+ instance.expects(:env=).with(env)
145
172
  klass.expects(:new).returns(instance)
146
173
  @configures_list << [key, klass]
147
174
  end
148
175
 
149
- Vagrant::Config::Top.new
176
+ Vagrant::Config::Top.new(env)
150
177
  end
151
178
 
152
179
  should "allow reading via methods" do
153
180
  key = "my_foo_bar_key"
154
181
  klass = mock("klass")
155
182
  instance = mock("instance")
183
+ instance.stubs(:env=)
156
184
  klass.expects(:new).returns(instance)
157
185
  Vagrant::Config::Top.configures(key, klass)
158
186
 
@@ -196,16 +224,13 @@ class ConfigTest < Test::Unit::TestCase
196
224
 
197
225
  context "VM configuration" do
198
226
  setup do
199
- @config = Vagrant::Config::VMConfig.new
200
- @username = "bob"
201
-
202
- mock_config do |config|
203
- config.ssh.username = @username
204
- end
227
+ @env = mock_environment
228
+ @config = @env.config.vm
229
+ @env.config.ssh.username = @username
205
230
  end
206
231
 
207
232
  should "include the stacked proc runner module" do
208
- assert @config.class.included_modules.include?(Vagrant::StackedProcRunner)
233
+ assert @config.class.included_modules.include?(Vagrant::Util::StackedProcRunner)
209
234
  end
210
235
 
211
236
  should "add the customize proc to the proc stack" do