vagrant 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG.md +48 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +49 -0
  5. data/README.md +2 -2
  6. data/Rakefile +22 -0
  7. data/bin/.gitignore +0 -0
  8. data/lib/vagrant/provisioners/chef_solo.rb +1 -1
  9. data/lib/vagrant/util/template_renderer.rb +2 -2
  10. data/lib/vagrant/version.rb +1 -1
  11. data/templates/Vagrantfile.erb +1 -1
  12. data/templates/nfs/exports.erb +4 -2
  13. data/test/test_helper.rb +128 -0
  14. data/test/vagrant/action/box/destroy_test.rb +30 -0
  15. data/test/vagrant/action/box/download_test.rb +141 -0
  16. data/test/vagrant/action/box/package_test.rb +25 -0
  17. data/test/vagrant/action/box/unpackage_test.rb +103 -0
  18. data/test/vagrant/action/box/verify_test.rb +39 -0
  19. data/test/vagrant/action/builder_test.rb +218 -0
  20. data/test/vagrant/action/env/error_halt_test.rb +21 -0
  21. data/test/vagrant/action/env/set_test.rb +24 -0
  22. data/test/vagrant/action/environment_test.rb +45 -0
  23. data/test/vagrant/action/exception_catcher_test.rb +30 -0
  24. data/test/vagrant/action/general/package_test.rb +254 -0
  25. data/test/vagrant/action/vm/boot_test.rb +83 -0
  26. data/test/vagrant/action/vm/check_box_test.rb +48 -0
  27. data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
  28. data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
  29. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
  30. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
  31. data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
  32. data/test/vagrant/action/vm/customize_test.rb +29 -0
  33. data/test/vagrant/action/vm/destroy_test.rb +26 -0
  34. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
  35. data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
  36. data/test/vagrant/action/vm/discard_state_test.rb +36 -0
  37. data/test/vagrant/action/vm/export_test.rb +135 -0
  38. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
  39. data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
  40. data/test/vagrant/action/vm/halt_test.rb +69 -0
  41. data/test/vagrant/action/vm/import_test.rb +50 -0
  42. data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
  43. data/test/vagrant/action/vm/network_test.rb +246 -0
  44. data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
  45. data/test/vagrant/action/vm/nfs_test.rb +269 -0
  46. data/test/vagrant/action/vm/package_test.rb +25 -0
  47. data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
  48. data/test/vagrant/action/vm/persist_test.rb +50 -0
  49. data/test/vagrant/action/vm/provision_test.rb +134 -0
  50. data/test/vagrant/action/vm/resume_test.rb +35 -0
  51. data/test/vagrant/action/vm/share_folders_test.rb +215 -0
  52. data/test/vagrant/action/vm/suspend_test.rb +35 -0
  53. data/test/vagrant/action_test.rb +111 -0
  54. data/test/vagrant/active_list_test.rb +173 -0
  55. data/test/vagrant/box_test.rb +166 -0
  56. data/test/vagrant/command_test.rb +53 -0
  57. data/test/vagrant/commands/base_test.rb +139 -0
  58. data/test/vagrant/commands/box/add_test.rb +34 -0
  59. data/test/vagrant/commands/box/list_test.rb +32 -0
  60. data/test/vagrant/commands/box/remove_test.rb +41 -0
  61. data/test/vagrant/commands/box/repackage_test.rb +52 -0
  62. data/test/vagrant/commands/destroy_test.rb +44 -0
  63. data/test/vagrant/commands/halt_test.rb +50 -0
  64. data/test/vagrant/commands/init_test.rb +71 -0
  65. data/test/vagrant/commands/package_test.rb +97 -0
  66. data/test/vagrant/commands/provision_test.rb +60 -0
  67. data/test/vagrant/commands/reload_test.rb +47 -0
  68. data/test/vagrant/commands/resume_test.rb +44 -0
  69. data/test/vagrant/commands/ssh_config_test.rb +77 -0
  70. data/test/vagrant/commands/ssh_test.rb +129 -0
  71. data/test/vagrant/commands/status_test.rb +40 -0
  72. data/test/vagrant/commands/suspend_test.rb +44 -0
  73. data/test/vagrant/commands/up_test.rb +49 -0
  74. data/test/vagrant/config_test.rb +307 -0
  75. data/test/vagrant/downloaders/base_test.rb +28 -0
  76. data/test/vagrant/downloaders/file_test.rb +33 -0
  77. data/test/vagrant/downloaders/http_test.rb +70 -0
  78. data/test/vagrant/environment_test.rb +770 -0
  79. data/test/vagrant/hosts/base_test.rb +46 -0
  80. data/test/vagrant/hosts/bsd_test.rb +56 -0
  81. data/test/vagrant/hosts/linux_test.rb +56 -0
  82. data/test/vagrant/provisioners/base_test.rb +36 -0
  83. data/test/vagrant/provisioners/chef_server_test.rb +182 -0
  84. data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
  85. data/test/vagrant/provisioners/chef_test.rb +178 -0
  86. data/test/vagrant/ssh_session_test.rb +46 -0
  87. data/test/vagrant/ssh_test.rb +317 -0
  88. data/test/vagrant/systems/linux_test.rb +179 -0
  89. data/test/vagrant/util/busy_test.rb +106 -0
  90. data/test/vagrant/util/plain_logger_test.rb +17 -0
  91. data/test/vagrant/util/platform_test.rb +18 -0
  92. data/test/vagrant/util/resource_logger_test.rb +145 -0
  93. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  94. data/test/vagrant/util/template_renderer_test.rb +145 -0
  95. data/test/vagrant/util/translator_test.rb +61 -0
  96. data/test/vagrant/util_test.rb +27 -0
  97. data/test/vagrant/vm_test.rb +228 -0
  98. data/vagrant.gemspec +34 -0
  99. metadata +158 -43
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+
3
+ class StackedProcRunnerUtilTest < Test::Unit::TestCase
4
+ class TestClass
5
+ include Vagrant::Util::StackedProcRunner
6
+ end
7
+
8
+ setup do
9
+ @instance = TestClass.new
10
+ @instance.proc_stack.clear
11
+ end
12
+
13
+ should "not run the procs right away" do
14
+ obj = mock("obj")
15
+ obj.expects(:foo).never
16
+ @instance.push_proc { |config| obj.foo }
17
+ @instance.push_proc { |config| obj.foo }
18
+ @instance.push_proc { |config| obj.foo }
19
+ end
20
+
21
+ should "run the blocks when run_procs! is ran" do
22
+ obj = mock("obj")
23
+ obj.expects(:foo).times(2)
24
+ @instance.push_proc { obj.foo }
25
+ @instance.push_proc { obj.foo }
26
+ @instance.run_procs!
27
+ end
28
+
29
+ should "run the blocks with the same arguments" do
30
+ passed_config = mock("config")
31
+ @instance.push_proc { |config| assert passed_config.equal?(config) }
32
+ @instance.push_proc { |config| assert passed_config.equal?(config) }
33
+ @instance.run_procs!(passed_config)
34
+ end
35
+
36
+ should "not clear the blocks after running" do
37
+ obj = mock("obj")
38
+ obj.expects(:foo).times(2)
39
+ @instance.push_proc { obj.foo }
40
+ @instance.run_procs!
41
+ @instance.run_procs!
42
+ end
43
+ end
@@ -0,0 +1,145 @@
1
+ require "test_helper"
2
+
3
+ class TemplateRendererUtilTest < Test::Unit::TestCase
4
+ context "initializing" do
5
+ should "set the template to the given argument" do
6
+ r = Vagrant::Util::TemplateRenderer.new("foo")
7
+ assert_equal "foo", r.template
8
+ end
9
+
10
+ should "set any additional variables" do
11
+ r = Vagrant::Util::TemplateRenderer.new("foo", {:bar => :baz})
12
+ assert_equal :baz, r.bar
13
+ end
14
+ end
15
+
16
+ context "rendering" do
17
+ setup do
18
+ @template = "foo"
19
+ @r = Vagrant::Util::TemplateRenderer.new(@template)
20
+ @r.stubs(:full_template_path).returns(@template + "!")
21
+
22
+ @contents = "bar"
23
+
24
+ @file = mock("file")
25
+ @file.stubs(:read).returns(@contents)
26
+ File.stubs(:open).yields(@file)
27
+ end
28
+
29
+ should "open the template file for reading" do
30
+ File.expects(:open).with(@r.full_template_path, 'r').once
31
+ @r.render
32
+ end
33
+
34
+ should "set the template to the file contents, render, then set it back" do
35
+ result = "bar"
36
+
37
+ template_seq = sequence("template_seq")
38
+ @r.expects(:template=).with(@file.read).in_sequence(template_seq)
39
+ @r.expects(:render_string).returns(result).in_sequence(template_seq)
40
+ @r.expects(:template=).with(@template).in_sequence(template_seq)
41
+ assert_equal result, @r.render
42
+ end
43
+
44
+ should "render the ERB file in the context of the renderer" do
45
+ result = "bar"
46
+ template = "<%= foo %>"
47
+ @r.foo = result
48
+ @file.expects(:read).returns(template)
49
+ assert_equal result, @r.render
50
+ end
51
+ end
52
+
53
+ context "rendering as string" do
54
+ setup do
55
+ @result = "foo"
56
+ @erb = mock("erb")
57
+ @erb.stubs(:result).returns(@result)
58
+
59
+ @r = Vagrant::Util::TemplateRenderer.new("foo")
60
+ end
61
+
62
+ should "simply render the template as a string" do
63
+ Erubis::Eruby.expects(:new).with(@r.template, :trim => true).returns(@erb)
64
+ @erb.expects(:result).returns(@result)
65
+ assert_equal @result, @r.render_string
66
+ end
67
+ end
68
+
69
+ context "the full template path" do
70
+ setup do
71
+ @template = "foo"
72
+ @r = Vagrant::Util::TemplateRenderer.new(@template)
73
+ end
74
+
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
78
+ end
79
+
80
+ should "remove duplicate path separators" do
81
+ @r.template = "foo///bar"
82
+ result = File.join(PROJECT_ROOT, "templates", "foo", "bar.erb")
83
+ assert_equal result, @r.full_template_path
84
+ end
85
+ end
86
+
87
+ context "class methods" do
88
+ context "render_with method" do
89
+ setup do
90
+ @template = "foo"
91
+ @r = Vagrant::Util::TemplateRenderer.new(@template)
92
+ @r.stubs(:render)
93
+
94
+ @method = :rawr
95
+
96
+ Vagrant::Util::TemplateRenderer.stubs(:new).with(@template, {}).returns(@r)
97
+ end
98
+
99
+ should "use the second argument as the template" do
100
+ Vagrant::Util::TemplateRenderer.expects(:new).with(@template, {}).returns(@r)
101
+ Vagrant::Util::TemplateRenderer.render_with(@method, @template)
102
+ end
103
+
104
+ should "send in additional argument to the renderer" do
105
+ data = {:hey => :foo}
106
+ Vagrant::Util::TemplateRenderer.expects(:new).with(@template, data).returns(@r)
107
+ Vagrant::Util::TemplateRenderer.render_with(@method, @template, data)
108
+ end
109
+
110
+ should "yield a block if given with the renderer as the argument" do
111
+ @r.expects(:yielded=).with(true).once
112
+ Vagrant::Util::TemplateRenderer.render_with(@method, @template) do |r|
113
+ r.yielded = true
114
+ end
115
+ end
116
+
117
+ should "render the result using the given method" do
118
+ result = mock('result')
119
+ @r.expects(@method).returns(result)
120
+ assert_equal result, Vagrant::Util::TemplateRenderer.render_with(@method, @template)
121
+ end
122
+
123
+ should "convert the given method to a sym prior to calling" do
124
+ @r.expects(@method.to_sym).returns(nil)
125
+ Vagrant::Util::TemplateRenderer.render_with(@method.to_s, @template)
126
+ end
127
+ end
128
+
129
+ context "render method" do
130
+ should "call render_with the render! method" do
131
+ args = ["foo", "bar", "baz"]
132
+ Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render, *args)
133
+ Vagrant::Util::TemplateRenderer.render(*args)
134
+ end
135
+ end
136
+
137
+ context "render_string method" do
138
+ should "call render_with the render! method" do
139
+ args = ["foo", "bar", "baz"]
140
+ Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render_string, *args)
141
+ Vagrant::Util::TemplateRenderer.render_string(*args)
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,61 @@
1
+ require "test_helper"
2
+
3
+ class TranslatorUtilTest < Test::Unit::TestCase
4
+ include Vagrant::Util
5
+
6
+ setup do
7
+ @klass = Translator
8
+ end
9
+
10
+ context "loading the errors from the YML" do
11
+ setup do
12
+ YAML.stubs(:load_file)
13
+ @klass.reset!
14
+ end
15
+
16
+ should "load the file initially, then never again unless reset" do
17
+ YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "strings.yml")).once
18
+ @klass.strings
19
+ @klass.strings
20
+ @klass.strings
21
+ @klass.strings
22
+ end
23
+
24
+ should "reload if reset! is called" do
25
+ YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "strings.yml")).twice
26
+ @klass.strings
27
+ @klass.reset!
28
+ @klass.strings
29
+ end
30
+ end
31
+
32
+ context "getting the string translated" do
33
+ setup do
34
+ @strings = {}
35
+ @strings[:foo] = "foo bar baz"
36
+ @klass.stubs(:strings).returns(@strings)
37
+ end
38
+
39
+ should "render the error string" do
40
+ TemplateRenderer.expects(:render_string).with(@strings[:foo], anything).once
41
+ @klass.t(:foo)
42
+ end
43
+
44
+ should "pass in any data entries" do
45
+ data = mock("data")
46
+ TemplateRenderer.expects(:render_string).with(@strings[:foo], data).once
47
+ @klass.t(:foo, data)
48
+ end
49
+
50
+ should "return the result of the render" do
51
+ result = mock("result")
52
+ TemplateRenderer.expects(:render_string).returns(result)
53
+ assert_equal result, @klass.t(:foo)
54
+ end
55
+
56
+ should "return an unknown if the key doesn't exist" do
57
+ result = @klass.t(:unknown)
58
+ assert result =~ /Unknown/i
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,27 @@
1
+ require "test_helper"
2
+
3
+ class UtilTest < Test::Unit::TestCase
4
+ class UtilIncludeTest
5
+ include Vagrant::Util
6
+ end
7
+
8
+ setup do
9
+ @klass = UtilIncludeTest
10
+ end
11
+
12
+ context "with a class" do
13
+ should "have the util methods" do
14
+ assert @klass.respond_to?(:error_and_exit)
15
+ end
16
+ end
17
+
18
+ context "with an instance" do
19
+ setup do
20
+ @instance = @klass.new
21
+ end
22
+
23
+ should "have the util methods" do
24
+ assert @instance.respond_to?(:error_and_exit)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,228 @@
1
+ require "test_helper"
2
+
3
+ class VMTest < Test::Unit::TestCase
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)
11
+
12
+ Net::SSH.stubs(:start)
13
+ end
14
+
15
+ context "finding a VM" do
16
+ should "return return an uncreated VM object if the VM is not found" do
17
+ VirtualBox::VM.expects(:find).returns(nil)
18
+ result = Vagrant::VM.find("foo")
19
+ assert result.is_a?(Vagrant::VM)
20
+ assert !result.created?
21
+ end
22
+
23
+ should "return a Vagrant::VM object for that VM if found" do
24
+ VirtualBox::VM.expects(:find).with("foo").returns("bar")
25
+ result = Vagrant::VM.find("foo", mock_environment)
26
+ assert result.is_a?(Vagrant::VM)
27
+ assert_equal "bar", result.vm
28
+ end
29
+ end
30
+
31
+ context "vagrant VM instance" do
32
+ setup do
33
+ @vm_name = "foo"
34
+ @vm = Vagrant::VM.new(:env => @env, :vm => @mock_vm, :vm_name => @vm_name)
35
+ @mock_vm.stubs(:uuid).returns("foo")
36
+ end
37
+
38
+ context "checking if created" do
39
+ should "return true if the VM object is not nil" do
40
+ @vm.stubs(:vm).returns(:foo)
41
+ assert @vm.created?
42
+ end
43
+
44
+ should "return false if the VM object is nil" do
45
+ @vm.stubs(:vm).returns(nil)
46
+ assert !@vm.created?
47
+ end
48
+ end
49
+
50
+ context "accessing the SSH object" do
51
+ setup do
52
+ # Reset this to nil to force the reload
53
+ @vm.instance_variable_set(:@ssh, nil)
54
+
55
+ @ssh = mock("ssh")
56
+ Vagrant::SSH.stubs(:new).returns(@ssh)
57
+ end
58
+
59
+ should "load it the first time" do
60
+ Vagrant::SSH.expects(:new).with(@vm.env).once.returns(@ssh)
61
+ @vm.ssh
62
+ @vm.ssh
63
+ @vm.ssh
64
+ 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
+ end
71
+
72
+ context "loading associated system" do
73
+ should "error and exit if system is not specified" do
74
+ @vm.env.config.vm.system = nil
75
+
76
+ @vm.expects(:error_and_exit).with(:system_unspecified).once
77
+ @vm.load_system!
78
+ end
79
+
80
+ context "with a class" do
81
+ class FakeSystemClass
82
+ def initialize(vm); end
83
+ end
84
+
85
+ should "initialize class if given" do
86
+ @vm.env.config.vm.system = Vagrant::Systems::Linux
87
+
88
+ @vm.expects(:error_and_exit).never
89
+ @vm.load_system!
90
+
91
+ assert @vm.system.is_a?(Vagrant::Systems::Linux)
92
+ end
93
+
94
+ should "error and exit if class has invalid parent" do
95
+ @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!
98
+ end
99
+ end
100
+
101
+ context "with a symbol" do
102
+ should "initialize proper symbols" do
103
+ valid = {
104
+ :linux => Vagrant::Systems::Linux
105
+ }
106
+
107
+ valid.each do |symbol, klass|
108
+ @vm.env.config.vm.system = symbol
109
+ @vm.expects(:error_and_exit).never
110
+ @vm.load_system!
111
+
112
+ assert @vm.system.is_a?(klass)
113
+ assert_equal @vm, @vm.system.vm
114
+ end
115
+ end
116
+
117
+ should "error and exit with invalid symbol" do
118
+ @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!
121
+ end
122
+ end
123
+ end
124
+
125
+ context "uuid" do
126
+ should "call UUID on VM object" do
127
+ uuid = mock("uuid")
128
+ @mock_vm.expects(:uuid).once.returns(uuid)
129
+ assert_equal uuid, @vm.uuid
130
+ end
131
+
132
+ should "return nil if vm is nil" do
133
+ @vm.expects(:vm).returns(nil)
134
+ assert @vm.uuid.nil?
135
+ end
136
+ end
137
+
138
+ context "reloading" do
139
+ should "load the same VM and set it" do
140
+ new_vm = mock("vm")
141
+ VirtualBox::VM.expects(:find).with(@mock_vm.uuid).returns(new_vm)
142
+ @vm.reload!
143
+ assert_equal new_vm, @vm.vm
144
+ end
145
+ end
146
+
147
+ context "packaging" do
148
+ should "execute the package action" do
149
+ @vm.env.actions.expects(:run).with(:package, :foo => :bar).once
150
+ @vm.package(:foo => :bar)
151
+ end
152
+ end
153
+
154
+ context "upping" do
155
+ should "execute the up action" do
156
+ @vm.env.actions.expects(:run).with(:up, nil).once
157
+ @vm.up
158
+ end
159
+ end
160
+
161
+ context "halting" do
162
+ should "execute the halt action" do
163
+ @vm.env.actions.expects(:run).with(:halt, :foo => :bar).once
164
+ @vm.halt({:foo => :bar})
165
+ end
166
+ end
167
+
168
+ context "reloading action" do
169
+ should "execute the reload action" do
170
+ @vm.env.actions.expects(:run).with(:reload).once
171
+ @vm.reload
172
+ end
173
+ end
174
+
175
+ context "provisioning" do
176
+ should "execute the provision action" do
177
+ @vm.env.actions.expects(:run).with(:provision).once
178
+ @vm.provision
179
+ end
180
+ end
181
+
182
+ context "destroying" do
183
+ should "execute the destroy action" do
184
+ @vm.env.actions.expects(:run).with(:destroy).once
185
+ @vm.destroy
186
+ end
187
+ end
188
+
189
+ context "suspending" do
190
+ should "execute the suspend action" do
191
+ @vm.env.actions.expects(:run).with(:suspend).once
192
+ @vm.suspend
193
+ end
194
+ end
195
+
196
+ context "resuming" do
197
+ should "execute the resume action" do
198
+ @vm.env.actions.expects(:run).with(:resume).once
199
+ @vm.resume
200
+ end
201
+ end
202
+
203
+ context "starting" do
204
+ setup do
205
+ @mock_vm.stubs(:running?).returns(false)
206
+ @mock_vm.stubs(:saved?).returns(false)
207
+ end
208
+
209
+ should "not do anything if the VM is already running" do
210
+ @mock_vm.stubs(:running?).returns(true)
211
+ @vm.expects(:execute!).never
212
+ @vm.start
213
+ end
214
+
215
+ should "execute the resume action if saved" do
216
+ @mock_vm.expects(:saved?).returns(true)
217
+ @vm.expects(:resume).once
218
+ @vm.env.actions.expects(:run).with(:start).never
219
+ @vm.start
220
+ end
221
+
222
+ should "execute the start action" do
223
+ @vm.env.actions.expects(:run).with(:start).once
224
+ @vm.start
225
+ end
226
+ end
227
+ end
228
+ end