vagrantup 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (235) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.yardopts +1 -0
  4. data/CHANGELOG.md +56 -0
  5. data/Gemfile +14 -3
  6. data/Gemfile.lock +38 -11
  7. data/README.md +1 -1
  8. data/bin/vagrant +20 -5
  9. data/config/default.rb +6 -8
  10. data/lib/vagrant.rb +40 -13
  11. data/lib/vagrant/action.rb +56 -16
  12. data/lib/vagrant/action/box/destroy.rb +3 -1
  13. data/lib/vagrant/action/box/download.rb +8 -13
  14. data/lib/vagrant/action/box/unpackage.rb +8 -11
  15. data/lib/vagrant/action/box/verify.rb +3 -3
  16. data/lib/vagrant/action/builder.rb +3 -30
  17. data/lib/vagrant/action/builtin.rb +6 -1
  18. data/lib/vagrant/action/environment.rb +14 -62
  19. data/lib/vagrant/action/general/package.rb +29 -22
  20. data/lib/vagrant/action/vm/boot.rb +5 -12
  21. data/lib/vagrant/action/vm/check_box.rb +4 -4
  22. data/lib/vagrant/action/vm/check_guest_additions.rb +4 -6
  23. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +2 -2
  24. data/lib/vagrant/action/vm/clear_nfs_exports.rb +1 -1
  25. data/lib/vagrant/action/vm/clear_shared_folders.rb +1 -1
  26. data/lib/vagrant/action/vm/customize.rb +1 -1
  27. data/lib/vagrant/action/vm/destroy.rb +1 -2
  28. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +1 -1
  29. data/lib/vagrant/action/vm/disable_networks.rb +11 -9
  30. data/lib/vagrant/action/vm/discard_state.rb +2 -2
  31. data/lib/vagrant/action/vm/export.rb +10 -11
  32. data/lib/vagrant/action/vm/forward_ports.rb +21 -9
  33. data/lib/vagrant/action/vm/halt.rb +3 -8
  34. data/lib/vagrant/action/vm/import.rb +16 -14
  35. data/lib/vagrant/action/vm/match_mac_address.rb +1 -1
  36. data/lib/vagrant/action/vm/network.rb +9 -16
  37. data/lib/vagrant/action/vm/nfs.rb +14 -18
  38. data/lib/vagrant/action/vm/provision.rb +5 -5
  39. data/lib/vagrant/action/vm/resume.rb +1 -1
  40. data/lib/vagrant/action/vm/share_folders.rb +6 -44
  41. data/lib/vagrant/action/vm/suspend.rb +1 -1
  42. data/lib/vagrant/action/warden.rb +74 -0
  43. data/lib/vagrant/box.rb +18 -82
  44. data/lib/vagrant/box_collection.rb +47 -0
  45. data/lib/vagrant/cli.rb +55 -0
  46. data/lib/vagrant/command/base.rb +106 -0
  47. data/lib/vagrant/command/box.rb +33 -0
  48. data/lib/vagrant/command/destroy.rb +17 -0
  49. data/lib/vagrant/command/group_base.rb +99 -0
  50. data/lib/vagrant/command/halt.rb +18 -0
  51. data/lib/vagrant/command/helpers.rb +33 -0
  52. data/lib/vagrant/command/init.rb +14 -0
  53. data/lib/vagrant/command/named_base.rb +14 -0
  54. data/lib/vagrant/command/package.rb +41 -0
  55. data/lib/vagrant/command/provision.rb +17 -0
  56. data/lib/vagrant/command/reload.rb +17 -0
  57. data/lib/vagrant/command/resume.rb +17 -0
  58. data/lib/vagrant/command/ssh.rb +41 -0
  59. data/lib/vagrant/command/ssh_config.rb +21 -0
  60. data/lib/vagrant/command/status.rb +23 -0
  61. data/lib/vagrant/command/suspend.rb +17 -0
  62. data/lib/vagrant/command/up.rb +20 -0
  63. data/lib/vagrant/command/upgrade_to_060.rb +45 -0
  64. data/lib/vagrant/command/version.rb +13 -0
  65. data/lib/vagrant/config.rb +107 -189
  66. data/lib/vagrant/config/base.rb +67 -0
  67. data/lib/vagrant/config/error_recorder.rb +19 -0
  68. data/lib/vagrant/config/nfs.rb +10 -0
  69. data/lib/vagrant/config/package.rb +9 -0
  70. data/lib/vagrant/config/ssh.rb +28 -0
  71. data/lib/vagrant/config/vagrant.rb +21 -0
  72. data/lib/vagrant/config/vm.rb +111 -0
  73. data/lib/vagrant/data_store.rb +68 -0
  74. data/lib/vagrant/downloaders/file.rb +3 -3
  75. data/lib/vagrant/downloaders/http.rb +5 -5
  76. data/lib/vagrant/environment.rb +246 -243
  77. data/lib/vagrant/errors.rb +306 -0
  78. data/lib/vagrant/hosts/base.rb +1 -1
  79. data/lib/vagrant/hosts/bsd.rb +3 -9
  80. data/lib/vagrant/hosts/linux.rb +3 -9
  81. data/lib/vagrant/plugin.rb +50 -0
  82. data/lib/vagrant/provisioners/base.rb +0 -6
  83. data/lib/vagrant/provisioners/chef.rb +63 -58
  84. data/lib/vagrant/provisioners/chef_server.rb +9 -11
  85. data/lib/vagrant/provisioners/chef_solo.rb +2 -2
  86. data/lib/vagrant/ssh.rb +34 -37
  87. data/lib/vagrant/systems/base.rb +0 -13
  88. data/lib/vagrant/systems/linux.rb +10 -33
  89. data/lib/vagrant/systems/solaris.rb +59 -0
  90. data/lib/vagrant/test_helpers.rb +109 -0
  91. data/lib/vagrant/ui.rb +65 -0
  92. data/lib/vagrant/util.rb +9 -19
  93. data/lib/vagrant/util/glob_loader.rb +19 -17
  94. data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
  95. data/lib/vagrant/util/plain_logger.rb +2 -0
  96. data/lib/vagrant/util/platform.rb +2 -0
  97. data/lib/vagrant/util/resource_logger.rb +5 -70
  98. data/lib/vagrant/util/retryable.rb +25 -0
  99. data/lib/vagrant/util/template_renderer.rb +1 -1
  100. data/lib/vagrant/version.rb +1 -1
  101. data/lib/vagrant/vm.rb +27 -13
  102. data/templates/commands/init/Vagrantfile.erb +13 -0
  103. data/templates/config/validation_failed.erb +7 -0
  104. data/templates/locales/en.yml +402 -0
  105. data/templates/package_Vagrantfile.erb +1 -1
  106. data/test/locales/en.yml +8 -0
  107. data/test/test_helper.rb +19 -103
  108. data/test/vagrant/action/box/destroy_test.rb +7 -19
  109. data/test/vagrant/action/box/download_test.rb +9 -25
  110. data/test/vagrant/action/box/package_test.rb +2 -2
  111. data/test/vagrant/action/box/unpackage_test.rb +8 -34
  112. data/test/vagrant/action/box/verify_test.rb +10 -19
  113. data/test/vagrant/action/builder_test.rb +0 -15
  114. data/test/vagrant/action/env/set_test.rb +1 -1
  115. data/test/vagrant/action/environment_test.rb +8 -26
  116. data/test/vagrant/action/general/package_test.rb +53 -53
  117. data/test/vagrant/action/vm/boot_test.rb +5 -22
  118. data/test/vagrant/action/vm/check_box_test.rb +35 -25
  119. data/test/vagrant/action/vm/clean_machine_folder_test.rb +1 -1
  120. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +1 -1
  121. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +1 -1
  122. data/test/vagrant/action/vm/clear_shared_folders_test.rb +1 -1
  123. data/test/vagrant/action/vm/customize_test.rb +2 -1
  124. data/test/vagrant/action/vm/destroy_test.rb +1 -2
  125. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +1 -1
  126. data/test/vagrant/action/vm/disable_networks_test.rb +10 -1
  127. data/test/vagrant/action/vm/discard_state_test.rb +10 -1
  128. data/test/vagrant/action/vm/export_test.rb +9 -37
  129. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +2 -2
  130. data/test/vagrant/action/vm/forward_ports_test.rb +19 -16
  131. data/test/vagrant/action/vm/halt_test.rb +11 -1
  132. data/test/vagrant/action/vm/import_test.rb +37 -21
  133. data/test/vagrant/action/vm/match_mac_address_test.rb +1 -1
  134. data/test/vagrant/action/vm/network_test.rb +8 -7
  135. data/test/vagrant/action/vm/nfs_helpers_test.rb +6 -3
  136. data/test/vagrant/action/vm/nfs_test.rb +20 -45
  137. data/test/vagrant/action/vm/package_test.rb +1 -1
  138. data/test/vagrant/action/vm/package_vagrantfile_test.rb +1 -1
  139. data/test/vagrant/action/vm/provision_test.rb +10 -17
  140. data/test/vagrant/action/vm/resume_test.rb +1 -1
  141. data/test/vagrant/action/vm/share_folders_test.rb +25 -106
  142. data/test/vagrant/action/vm/suspend_test.rb +1 -1
  143. data/test/vagrant/action/warden_test.rb +105 -0
  144. data/test/vagrant/action_test.rb +5 -27
  145. data/test/vagrant/box_collection_test.rb +44 -0
  146. data/test/vagrant/box_test.rb +5 -105
  147. data/test/vagrant/cli_test.rb +35 -0
  148. data/test/vagrant/command/base_test.rb +23 -0
  149. data/test/vagrant/command/group_base_test.rb +15 -0
  150. data/test/vagrant/command/helpers_test.rb +88 -0
  151. data/test/vagrant/config/base_test.rb +52 -0
  152. data/test/vagrant/config/error_recorder_test.rb +18 -0
  153. data/test/vagrant/config/ssh_test.rb +12 -0
  154. data/test/vagrant/config/vagrant_test.rb +11 -0
  155. data/test/vagrant/config/vm_test.rb +70 -0
  156. data/test/vagrant/config_test.rb +113 -206
  157. data/test/vagrant/data_store_test.rb +68 -0
  158. data/test/vagrant/downloaders/base_test.rb +1 -1
  159. data/test/vagrant/downloaders/file_test.rb +4 -3
  160. data/test/vagrant/downloaders/http_test.rb +14 -4
  161. data/test/vagrant/environment_test.rb +290 -590
  162. data/test/vagrant/errors_test.rb +42 -0
  163. data/test/vagrant/hosts/base_test.rb +1 -1
  164. data/test/vagrant/hosts/bsd_test.rb +3 -6
  165. data/test/vagrant/hosts/linux_test.rb +3 -5
  166. data/test/vagrant/plugin_test.rb +9 -0
  167. data/test/vagrant/provisioners/base_test.rb +1 -1
  168. data/test/vagrant/provisioners/chef_server_test.rb +31 -35
  169. data/test/vagrant/provisioners/chef_solo_test.rb +1 -1
  170. data/test/vagrant/provisioners/chef_test.rb +7 -7
  171. data/test/vagrant/ssh_session_test.rb +3 -10
  172. data/test/vagrant/ssh_test.rb +25 -33
  173. data/test/vagrant/systems/linux_test.rb +6 -71
  174. data/test/vagrant/ui_test.rb +29 -0
  175. data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
  176. data/test/vagrant/util/resource_logger_test.rb +14 -81
  177. data/test/vagrant/util/retryable_test.rb +38 -0
  178. data/test/vagrant/util/template_renderer_test.rb +4 -4
  179. data/test/vagrant/vm_test.rb +47 -26
  180. data/vagrant.gemspec +14 -12
  181. metadata +121 -89
  182. data/bin/.gitignore +0 -0
  183. data/lib/vagrant/action/action_exception.rb +0 -16
  184. data/lib/vagrant/action/env/error_halt.rb +0 -16
  185. data/lib/vagrant/action/exception_catcher.rb +0 -14
  186. data/lib/vagrant/action/vm/persist.rb +0 -22
  187. data/lib/vagrant/active_list.rb +0 -83
  188. data/lib/vagrant/command.rb +0 -27
  189. data/lib/vagrant/commands/base.rb +0 -181
  190. data/lib/vagrant/commands/box.rb +0 -16
  191. data/lib/vagrant/commands/box/add.rb +0 -30
  192. data/lib/vagrant/commands/box/list.rb +0 -30
  193. data/lib/vagrant/commands/box/remove.rb +0 -30
  194. data/lib/vagrant/commands/box/repackage.rb +0 -35
  195. data/lib/vagrant/commands/destroy.rb +0 -37
  196. data/lib/vagrant/commands/halt.rb +0 -43
  197. data/lib/vagrant/commands/init.rb +0 -36
  198. data/lib/vagrant/commands/package.rb +0 -81
  199. data/lib/vagrant/commands/provision.rb +0 -31
  200. data/lib/vagrant/commands/reload.rb +0 -36
  201. data/lib/vagrant/commands/resume.rb +0 -35
  202. data/lib/vagrant/commands/ssh.rb +0 -78
  203. data/lib/vagrant/commands/ssh_config.rb +0 -45
  204. data/lib/vagrant/commands/status.rb +0 -125
  205. data/lib/vagrant/commands/suspend.rb +0 -36
  206. data/lib/vagrant/commands/up.rb +0 -44
  207. data/lib/vagrant/exceptions/uncallable_action.rb +0 -17
  208. data/lib/vagrant/util/translator.rb +0 -35
  209. data/templates/strings.yml +0 -341
  210. data/templates/unison/crontab_entry.erb +0 -1
  211. data/templates/unison/script.erb +0 -71
  212. data/test/vagrant/action/env/error_halt_test.rb +0 -21
  213. data/test/vagrant/action/exception_catcher_test.rb +0 -30
  214. data/test/vagrant/action/vm/persist_test.rb +0 -50
  215. data/test/vagrant/active_list_test.rb +0 -173
  216. data/test/vagrant/command_test.rb +0 -53
  217. data/test/vagrant/commands/base_test.rb +0 -139
  218. data/test/vagrant/commands/box/add_test.rb +0 -34
  219. data/test/vagrant/commands/box/list_test.rb +0 -32
  220. data/test/vagrant/commands/box/remove_test.rb +0 -41
  221. data/test/vagrant/commands/box/repackage_test.rb +0 -52
  222. data/test/vagrant/commands/destroy_test.rb +0 -44
  223. data/test/vagrant/commands/halt_test.rb +0 -50
  224. data/test/vagrant/commands/init_test.rb +0 -71
  225. data/test/vagrant/commands/package_test.rb +0 -97
  226. data/test/vagrant/commands/provision_test.rb +0 -60
  227. data/test/vagrant/commands/reload_test.rb +0 -47
  228. data/test/vagrant/commands/resume_test.rb +0 -44
  229. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  230. data/test/vagrant/commands/ssh_test.rb +0 -129
  231. data/test/vagrant/commands/status_test.rb +0 -40
  232. data/test/vagrant/commands/suspend_test.rb +0 -44
  233. data/test/vagrant/commands/up_test.rb +0 -49
  234. data/test/vagrant/util/translator_test.rb +0 -61
  235. data/test/vagrant/util_test.rb +0 -27
@@ -4,7 +4,7 @@ class LinuxSystemTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Systems::Linux
6
6
  @ssh = mock("ssh")
7
- @mock_env = mock_environment
7
+ @mock_env = vagrant_env
8
8
  @vm = mock("vm")
9
9
  @vm.stubs(:env).returns(@mock_env)
10
10
  @instance = @klass.new(@vm)
@@ -43,71 +43,6 @@ class LinuxSystemTest < Test::Unit::TestCase
43
43
  end
44
44
  end
45
45
 
46
- context "preparing unison" do
47
- setup do
48
- @ssh.stubs(:exec!)
49
- @ssh.stubs(:upload!)
50
- @vm.stubs(:ssh).returns(@ssh)
51
- end
52
-
53
- should "upload the script" do
54
- @vm.ssh.expects(:upload!).with do |script, path|
55
- assert_equal @mock_env.config.unison.script, path
56
- true
57
- end
58
-
59
- @instance.prepare_unison(@ssh)
60
- end
61
-
62
- should "make the script executable" do
63
- @ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.unison.script}").once
64
- @instance.prepare_unison(@ssh)
65
- end
66
-
67
- should "remove old crontab entry file" do
68
- @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.unison.crontab_entry_file}", :error_check => false).once
69
- @instance.prepare_unison(@ssh)
70
- end
71
- end
72
-
73
- context "creating unison entry" do
74
- setup do
75
- @ssh.stubs(:exec!)
76
- @options = {
77
- :guestpath => "foo",
78
- :original => { :guestpath => "bar!" }
79
- }
80
- end
81
-
82
- should "render the crontab entry with proper variables" do
83
- variables = {
84
- :from => @options[:guestpath],
85
- :to => @options[:original][:guestpath],
86
- :options => @mock_env.config.unison.options,
87
- :script => @mock_env.config.unison.script,
88
- :log_file => @mock_env.config.unison.log_file % "bar-"
89
- }
90
- Vagrant::Util::TemplateRenderer.expects(:render).with('/unison/crontab_entry',
91
- variables).once
92
- @instance.create_unison(@ssh, @options)
93
- end
94
-
95
- should "remove the .unison directory" do
96
- @ssh.expects(:exec!).with("sudo rm -rf ~/.unison")
97
- @instance.create_unison(@ssh, @options)
98
- end
99
-
100
- should "remove the original guestpath" do
101
- @ssh.expects(:exec!).with("sudo rm -rf #{@options[:original][:guestpath]}")
102
- @instance.create_unison(@ssh, @options)
103
- end
104
-
105
- should "enable the crontab file" do
106
- @ssh.expects(:exec!).with("crontab #{@mock_env.config.unison.crontab_entry_file}")
107
- @instance.create_unison(@ssh, @options)
108
- end
109
- end
110
-
111
46
  #-------------------------------------------------------------------
112
47
  # "Private" methods tests
113
48
  #-------------------------------------------------------------------
@@ -149,7 +84,7 @@ class LinuxSystemTest < Test::Unit::TestCase
149
84
  should "raise an ActionException if the command fails constantly" do
150
85
  @ssh.expects(:exec!).times(@limit).returns(!@success_return)
151
86
 
152
- assert_raises(Vagrant::Action::ActionException) {
87
+ assert_raises(Vagrant::Systems::Linux::LinuxError) {
153
88
  mount_folder
154
89
  }
155
90
  end
@@ -165,10 +100,10 @@ class LinuxSystemTest < Test::Unit::TestCase
165
100
  should "add uid AND gid to mount" do
166
101
  uid = "foo"
167
102
  gid = "bar"
168
- env = mock_environment do |config|
169
- config.vm.shared_folder_uid = uid
170
- config.vm.shared_folder_gid = gid
171
- end
103
+ env = vagrant_env(vagrantfile(<<-vf))
104
+ config.vm.shared_folder_uid = "#{uid}"
105
+ config.vm.shared_folder_gid = "#{gid}"
106
+ vf
172
107
 
173
108
  @vm.stubs(:env).returns(env)
174
109
 
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class ShellUITest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::UI::Shell
6
+ @shell = mock("shell")
7
+ @instance = @klass.new(vagrant_env, @shell)
8
+ end
9
+
10
+ context "prefixing with resource" do
11
+ should "prefix message with environment resource" do
12
+ @shell.expects(:say).with() do |message, color|
13
+ assert message =~ /\[#{@instance.env.resource}\]/
14
+ true
15
+ end
16
+
17
+ @instance.info("vagrant.errors.test_key")
18
+ end
19
+
20
+ should "not prefix the message if given false" do
21
+ @shell.expects(:say).with() do |message, color|
22
+ assert message !~ /\[#{@instance.env.resource}\]/
23
+ true
24
+ end
25
+
26
+ @instance.info("vagrant.errors.test_key", :prefix => false)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ class HashWithIndifferentAccessUtilTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Util::HashWithIndifferentAccess
6
+ @instance = @klass.new
7
+ end
8
+
9
+ should "be a hash" do
10
+ assert @instance.is_a?(Hash)
11
+ end
12
+
13
+ should "allow indifferent access when setting with a string" do
14
+ @instance["foo"] = "bar"
15
+ assert_equal "bar", @instance[:foo]
16
+ end
17
+
18
+ should "allow indifferent access when setting with a symbol" do
19
+ @instance[:foo] = "bar"
20
+ assert_equal "bar", @instance["foo"]
21
+ end
22
+
23
+ should "allow indifferent key lookup" do
24
+ @instance["foo"] = "bar"
25
+ assert @instance.key?(:foo)
26
+ assert @instance.has_key?(:foo)
27
+ assert @instance.include?(:foo)
28
+ assert @instance.member?(:foo)
29
+ end
30
+
31
+ should "forward up block to Hash if given to initializer" do
32
+ instance = @klass.new do |h,k|
33
+ h[k] = "foo"
34
+ end
35
+
36
+ assert_equal "foo", instance[:foo]
37
+ assert_equal "foo", instance["foo"]
38
+ end
39
+ end
@@ -12,34 +12,29 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase
12
12
  @result = mock("result")
13
13
  end
14
14
 
15
- should "return a nil plain logger if no environment is given" do
16
- Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result)
17
- assert_equal @result, @klass.singleton_logger
18
- end
19
-
20
- should "return a nil plain logger if the config is not loaded" do
21
- env = mock_environment
22
- env.config.stubs(:loaded?).returns(false)
15
+ should "return a nil plain logger if the environment is not loaded" do
16
+ env = vagrant_env
17
+ env.stubs(:loaded?).returns(false)
23
18
 
24
19
  Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result)
25
20
  assert_equal @result, @klass.singleton_logger(env)
26
21
  end
27
22
 
28
- should "return a logger with the specified output if environment is ready" do
29
- output = mock("output")
30
- env = mock_environment
31
- env.config.vagrant.log_output = output
23
+ should "return a logger with the output file set if environment is ready" do
24
+ env = vagrant_env
25
+
26
+ Vagrant::Util::PlainLogger.expects(:new).returns(@result).with() do |path|
27
+ assert path.to_s =~ /logs/
28
+ true
29
+ end
32
30
 
33
- Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result)
34
31
  assert_equal @result, @klass.singleton_logger(env)
35
32
  end
36
33
 
37
34
  should "only load the logger once" do
38
- output = mock("output")
39
- env = mock_environment
40
- env.config.vagrant.log_output = output
35
+ env = vagrant_env
41
36
 
42
- Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result)
37
+ Vagrant::Util::PlainLogger.expects(:new).with(anything).returns(@result)
43
38
  assert_equal @result, @klass.singleton_logger(env)
44
39
  assert_equal @result, @klass.singleton_logger(env)
45
40
  assert_equal @result, @klass.singleton_logger(env)
@@ -48,7 +43,7 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase
48
43
 
49
44
  context "initialization" do
50
45
  should "setup the logger and attributes" do
51
- env = mock_environment
46
+ env = vagrant_env
52
47
  resource = mock("resource")
53
48
  result = mock("result")
54
49
 
@@ -63,7 +58,7 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase
63
58
  context "with an instance" do
64
59
  setup do
65
60
  @resource = "foo"
66
- @env = mock_environment
61
+ @env = vagrant_env
67
62
  @logger = mock("logger")
68
63
 
69
64
  @klass.stubs(:singleton_logger).returns(@logger)
@@ -71,11 +66,6 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase
71
66
  end
72
67
 
73
68
  context "logging methods" do
74
- setup do
75
- @instance.stubs(:flush_progress)
76
- @instance.stubs(:cl_reset).returns("")
77
- end
78
-
79
69
  [:debug, :info, :error, :fatal].each do |method|
80
70
  should "log with the proper format on #{method}" do
81
71
  message = "bar"
@@ -84,62 +74,5 @@ class ResourceLoggerUtilTest < Test::Unit::TestCase
84
74
  end
85
75
  end
86
76
  end
87
-
88
- context "reporting progress" do
89
- setup do
90
- @instance.stubs(:flush_progress)
91
- end
92
-
93
- should "flush progress" do
94
- @instance.expects(:flush_progress).once
95
- @instance.report_progress(72, 100)
96
- end
97
-
98
- should "add the reporter to the progress reporters" do
99
- @instance.report_progress(72, 100)
100
- assert @klass.progress_reporters.has_key?(@instance.resource)
101
- end
102
- end
103
-
104
- context "clearing progress" do
105
- setup do
106
- @instance.stubs(:flush_progress)
107
-
108
- @klass.progress_reporters.clear
109
- @instance.report_progress(72, 100)
110
- end
111
-
112
- should "remove the key from the reporters" do
113
- assert @klass.progress_reporters.has_key?(@instance.resource)
114
- @instance.clear_progress
115
- assert !@klass.progress_reporters.has_key?(@instance.resource)
116
- end
117
- end
118
-
119
- context "command line reset" do
120
- setup do
121
- Mario::Platform.logger(nil)
122
- end
123
-
124
- context "on windows" do
125
- setup do
126
- Mario::Platform.forced = Mario::Platform::Windows7
127
- end
128
-
129
- should "just return \\r for the clear screen" do
130
- assert_equal "\r", @instance.cl_reset
131
- end
132
- end
133
-
134
- context "on other platforms" do
135
- setup do
136
- Mario::Platform.forced = Mario::Platform::Linux
137
- end
138
-
139
- should "return the full clear screen" do
140
- assert_equal "\r\e[0K", @instance.cl_reset
141
- end
142
- end
143
- end
144
77
  end
145
78
  end
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+
3
+ class RetryableUtilTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Class.new do
6
+ extend Vagrant::Util::Retryable
7
+ end
8
+ end
9
+
10
+ should "retry specified number of times if exception is raised" do
11
+ proc = mock("proc")
12
+ proc.expects(:call).twice
13
+
14
+ assert_raises(RuntimeError) {
15
+ @klass.retryable(:tries => 2, :on => RuntimeError) do
16
+ proc.call
17
+ raise "An error"
18
+ end
19
+ }
20
+ end
21
+
22
+ should "only retry on specified exception" do
23
+ proc = mock("proc")
24
+ proc.expects(:call).once
25
+
26
+ assert_raises(StandardError) {
27
+ @klass.retryable(:tries => 5, :on => RuntimeError) do
28
+ proc.call
29
+ raise StandardError.new
30
+ end
31
+ }
32
+ end
33
+
34
+ should "return the value of the block" do
35
+ result = @klass.retryable { 7 }
36
+ assert_equal 7, result
37
+ end
38
+ end
@@ -73,14 +73,14 @@ class TemplateRendererUtilTest < Test::Unit::TestCase
73
73
  end
74
74
 
75
75
  should "be the ERB file in the templates directory" do
76
- result = File.join(PROJECT_ROOT, "templates", "#{@template}.erb")
77
- assert_equal result, @r.full_template_path
76
+ result = Vagrant.source_root.join("templates", "#{@template}.erb")
77
+ assert_equal result.to_s, @r.full_template_path
78
78
  end
79
79
 
80
80
  should "remove duplicate path separators" do
81
81
  @r.template = "foo///bar"
82
- result = File.join(PROJECT_ROOT, "templates", "foo", "bar.erb")
83
- assert_equal result, @r.full_template_path
82
+ result = Vagrant.source_root.join("templates", "foo", "bar.erb")
83
+ assert_equal result.to_s, @r.full_template_path
84
84
  end
85
85
  end
86
86
 
@@ -2,12 +2,7 @@ require "test_helper"
2
2
 
3
3
  class VMTest < Test::Unit::TestCase
4
4
  setup do
5
- @mock_vm = mock("vm")
6
-
7
- @persisted_vm = mock("persisted_vm")
8
-
9
- @env = mock_environment
10
- @env.stubs(:vm).returns(@persisted_vm)
5
+ @env = vagrant_env
11
6
 
12
7
  Net::SSH.stubs(:start)
13
8
  end
@@ -22,7 +17,7 @@ class VMTest < Test::Unit::TestCase
22
17
 
23
18
  should "return a Vagrant::VM object for that VM if found" do
24
19
  VirtualBox::VM.expects(:find).with("foo").returns("bar")
25
- result = Vagrant::VM.find("foo", mock_environment)
20
+ result = Vagrant::VM.find("foo", @env)
26
21
  assert result.is_a?(Vagrant::VM)
27
22
  assert_equal "bar", result.vm
28
23
  end
@@ -31,7 +26,8 @@ class VMTest < Test::Unit::TestCase
31
26
  context "vagrant VM instance" do
32
27
  setup do
33
28
  @vm_name = "foo"
34
- @vm = Vagrant::VM.new(:env => @env, :vm => @mock_vm, :vm_name => @vm_name)
29
+ @mock_vm = mock("vm")
30
+ @vm = Vagrant::VM.new(:env => @env, :vm => @mock_vm, :name => @vm_name)
35
31
  @mock_vm.stubs(:uuid).returns("foo")
36
32
  end
37
33
 
@@ -47,6 +43,35 @@ class VMTest < Test::Unit::TestCase
47
43
  end
48
44
  end
49
45
 
46
+ context "setting the VM" do
47
+ setup do
48
+ @raw_vm = mock("vm")
49
+ @raw_vm.stubs(:uuid).returns("foobar")
50
+ end
51
+
52
+ should "set the VM" do
53
+ @vm.vm = @raw_vm
54
+ assert_equal @raw_vm, @vm.vm
55
+ end
56
+
57
+ should "add the VM to the active list" do
58
+ assert @env.local_data.empty?
59
+ @vm.vm = @raw_vm
60
+ assert_equal @raw_vm.uuid, @env.local_data[:active][@vm.name.to_s]
61
+ end
62
+
63
+ should "remove the VM from the active list if nil is given" do
64
+ @env.local_data[:active] = { @vm.name.to_s => "foo" }
65
+
66
+ assert @env.local_data[:active].has_key?(@vm.name.to_s) # sanity
67
+ @vm.vm = nil
68
+
69
+ # This becomes empty because vm= will commit the local data which
70
+ # actually prunes out the empty values.
71
+ assert @env.local_data.empty?
72
+ end
73
+ end
74
+
50
75
  context "accessing the SSH object" do
51
76
  setup do
52
77
  # Reset this to nil to force the reload
@@ -56,25 +81,21 @@ class VMTest < Test::Unit::TestCase
56
81
  Vagrant::SSH.stubs(:new).returns(@ssh)
57
82
  end
58
83
 
59
- should "load it the first time" do
84
+ should "load it the first time, and only load it once" do
60
85
  Vagrant::SSH.expects(:new).with(@vm.env).once.returns(@ssh)
61
86
  @vm.ssh
62
87
  @vm.ssh
63
88
  @vm.ssh
64
89
  end
65
-
66
- should "use the same value once its loaded" do
67
- result = @vm.ssh
68
- assert_equal result, @vm.ssh
69
- end
70
90
  end
71
91
 
72
92
  context "loading associated system" do
73
93
  should "error and exit if system is not specified" do
74
94
  @vm.env.config.vm.system = nil
75
95
 
76
- @vm.expects(:error_and_exit).with(:system_unspecified).once
77
- @vm.load_system!
96
+ assert_raises(Vagrant::Errors::VMSystemError) {
97
+ @vm.load_system!
98
+ }
78
99
  end
79
100
 
80
101
  context "with a class" do
@@ -85,16 +106,15 @@ class VMTest < Test::Unit::TestCase
85
106
  should "initialize class if given" do
86
107
  @vm.env.config.vm.system = Vagrant::Systems::Linux
87
108
 
88
- @vm.expects(:error_and_exit).never
89
- @vm.load_system!
90
-
109
+ assert_nothing_raised { @vm.load_system!}
91
110
  assert @vm.system.is_a?(Vagrant::Systems::Linux)
92
111
  end
93
112
 
94
- should "error and exit if class has invalid parent" do
113
+ should "raise error if class has invalid parent" do
95
114
  @vm.env.config.vm.system = FakeSystemClass
96
- @vm.expects(:error_and_exit).with(:system_invalid_class, :system => @vm.env.config.vm.system.to_s).once
97
- @vm.load_system!
115
+ assert_raises(Vagrant::Errors::VMSystemError) {
116
+ @vm.load_system!
117
+ }
98
118
  end
99
119
  end
100
120
 
@@ -106,9 +126,8 @@ class VMTest < Test::Unit::TestCase
106
126
 
107
127
  valid.each do |symbol, klass|
108
128
  @vm.env.config.vm.system = symbol
109
- @vm.expects(:error_and_exit).never
110
- @vm.load_system!
111
129
 
130
+ assert_nothing_raised { @vm.load_system! }
112
131
  assert @vm.system.is_a?(klass)
113
132
  assert_equal @vm, @vm.system.vm
114
133
  end
@@ -116,8 +135,10 @@ class VMTest < Test::Unit::TestCase
116
135
 
117
136
  should "error and exit with invalid symbol" do
118
137
  @vm.env.config.vm.system = :shall_never_exist
119
- @vm.expects(:error_and_exit).with(:system_unknown_type, :system => @vm.env.config.vm.system.to_s).once
120
- @vm.load_system!
138
+
139
+ assert_raises(Vagrant::Errors::VMSystemError) {
140
+ @vm.load_system!
141
+ }
121
142
  end
122
143
  end
123
144
  end