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,25 @@
1
+ require "test_helper"
2
+
3
+ class PackageBoxActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Box::Package
6
+ @app, @env = mock_action_data
7
+ @env["box"] = Vagrant::Box.new(mock_environment, "foo")
8
+
9
+ @instance = @klass.new(@app, @env)
10
+ end
11
+
12
+ should "be a subclass of general packaging middleware" do
13
+ assert @instance.is_a?(Vagrant::Action::General::Package)
14
+ end
15
+
16
+ should "set the package directory then call parent" do
17
+ @instance.expects(:general_call).once.with() do |env|
18
+ assert env["package.directory"]
19
+ assert_equal env["package.directory"], @env["box"].directory
20
+ true
21
+ end
22
+
23
+ @instance.call(@env)
24
+ end
25
+ end
@@ -0,0 +1,103 @@
1
+ require "test_helper"
2
+
3
+ class UnpackageBoxActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Box::Unpackage
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+ @env["box"] = Vagrant::Box.new(mock_environment, "foo")
11
+
12
+ @internal_vm = mock("internal")
13
+ @vm.stubs(:vm).returns(@internal_vm)
14
+
15
+ @instance = @klass.new(@app, @env)
16
+ end
17
+
18
+ context "calling" do
19
+ should "call the proper chain" do
20
+ seq = sequence("sequence")
21
+ @instance.expects(:setup_box_directory).in_sequence(seq).returns(true)
22
+ @instance.expects(:decompress).in_sequence(seq)
23
+ @app.expects(:call).with(@env)
24
+ @instance.expects(:cleanup).never
25
+ @instance.call(@env)
26
+ end
27
+
28
+ should "halt the chain if setting up the box directory fails" do
29
+ @instance.expects(:setup_box_directory).returns(false)
30
+ @instance.expects(:decompress).never
31
+ @app.expects(:call).never
32
+ @instance.expects(:cleanup).never
33
+ @instance.call(@env)
34
+ end
35
+
36
+ should "cleanup if there was an error" do
37
+ @env.error!(:foo)
38
+
39
+ seq = sequence("sequence")
40
+ @instance.expects(:setup_box_directory).in_sequence(seq).returns(true)
41
+ @instance.expects(:decompress).in_sequence(seq)
42
+ @app.expects(:call).with(@env)
43
+ @instance.expects(:cleanup).once
44
+ @instance.call(@env)
45
+ end
46
+ end
47
+
48
+ context "cleaning up" do
49
+ setup do
50
+ @instance.stubs(:box_directory).returns("foo")
51
+ File.stubs(:directory?).returns(false)
52
+ FileUtils.stubs(:rm_rf)
53
+ end
54
+
55
+ should "do nothing if not a directory" do
56
+ FileUtils.expects(:rm_rf).never
57
+ @instance.cleanup
58
+ end
59
+
60
+ should "remove the directory if exists" do
61
+ File.expects(:directory?).with(@instance.box_directory).once.returns(true)
62
+ FileUtils.expects(:rm_rf).with(@instance.box_directory).once
63
+ @instance.cleanup
64
+ end
65
+ end
66
+
67
+ context "setting up the box directory" do
68
+ setup do
69
+ File.stubs(:directory?).returns(false)
70
+ FileUtils.stubs(:mkdir_p)
71
+ end
72
+
73
+ should "error the environment if the box already exists" do
74
+ File.expects(:directory?).returns(true)
75
+ assert !@instance.setup_box_directory
76
+ assert @env.error?
77
+ assert_equal :box_already_exists, @env.error.first
78
+ end
79
+
80
+ should "create the directory" do
81
+ FileUtils.expects(:mkdir_p).with(@env["box"].directory).once
82
+ @instance.setup_box_directory
83
+ end
84
+ end
85
+
86
+ context "decompressing" do
87
+ setup do
88
+ @env["download.temp_path"] = "bar"
89
+
90
+ Dir.stubs(:chdir).yields
91
+ end
92
+
93
+ should "change to the box directory" do
94
+ Dir.expects(:chdir).with(@env["box"].directory)
95
+ @instance.decompress
96
+ end
97
+
98
+ should "open the tar file within the new directory, and extract it all" do
99
+ Archive::Tar::Minitar.expects(:unpack).with(@env["download.temp_path"], @env["box"].directory).once
100
+ @instance.decompress
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ class VerifyBoxActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Box::Verify
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+ @env["box"] = Vagrant::Box.new(mock_environment, "foo")
11
+
12
+ @internal_vm = mock("internal")
13
+ @vm.stubs(:vm).returns(@internal_vm)
14
+
15
+ @instance = @klass.new(@app, @env)
16
+ end
17
+
18
+ context "calling" do
19
+ setup do
20
+ @env.logger.stubs(:info)
21
+ end
22
+
23
+ should "continue fine if verification succeeds" do
24
+ seq = sequence("seq")
25
+ VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file).in_sequence(seq)
26
+ @app.expects(:call).with(@env).once.in_sequence(seq)
27
+ @instance.call(@env)
28
+ assert !@env.error?
29
+ end
30
+
31
+ should "halt chain if verification fails" do
32
+ VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file).raises(Exception)
33
+ @app.expects(:call).with(@env).never
34
+ @instance.call(@env)
35
+ assert @env.error?
36
+ assert_equal :box_verification_failed, @env.error.first
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,218 @@
1
+ require "test_helper"
2
+
3
+ class ActionBuilderTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Builder
6
+ end
7
+
8
+ context "initializing" do
9
+ should "setup empty middleware stack" do
10
+ builder = @klass.new
11
+ assert builder.stack.empty?
12
+ end
13
+
14
+ should "take block to setup stack" do
15
+ builder = @klass.new do
16
+ use Hash
17
+ use lambda { |i| i }
18
+ end
19
+
20
+ assert !builder.stack.empty?
21
+ assert_equal 2, builder.stack.length
22
+ end
23
+ end
24
+
25
+ context "with an instance" do
26
+ setup do
27
+ @instance = @klass.new
28
+ end
29
+
30
+ context "adding to the stack" do
31
+ should "return self" do
32
+ assert @instance.equal?(@instance.use(1))
33
+ end
34
+
35
+ should "add to the end" do
36
+ @instance.use 1
37
+ @instance.use 2
38
+ assert_equal [2, [], nil], @instance.stack.last
39
+ end
40
+
41
+ should "merge in other builder's stack" do
42
+ other = @klass.new do
43
+ use 2
44
+ use 3
45
+ end
46
+
47
+ @instance.use 1
48
+ @instance.use other
49
+ assert_equal 3, @instance.stack.length
50
+ end
51
+
52
+ should "prepend a set environment task for merging middlewares if given" do
53
+ other = @klass.new do
54
+ use 1
55
+ end
56
+
57
+ @instance.use 0
58
+ @instance.use(other, :foo => :bar)
59
+ assert_equal 3, @instance.stack.length
60
+ assert_equal Vagrant::Action::Env::Set, @instance.stack[1].first
61
+ end
62
+ end
63
+
64
+ context "flatten" do
65
+ should "return the flattened format of the builder" do
66
+ env = Vagrant::Action::Environment.new(nil)
67
+ env.expects(:foo).once
68
+
69
+ func = lambda { |x| x.foo }
70
+ @instance.use func
71
+ proc = @instance.flatten
72
+ assert proc.respond_to?(:call)
73
+ proc.call(env)
74
+ end
75
+ end
76
+
77
+ context "inserting" do
78
+ setup do
79
+ @instance.use "1"
80
+ @instance.use "2"
81
+ end
82
+
83
+ should "insert at the proper numeric index" do
84
+ @instance.insert(1, "3")
85
+ assert_equal "3", @instance.stack[1].first
86
+ end
87
+
88
+ should "insert next to the proper object if given" do
89
+ @instance.insert("2", "3")
90
+ assert_equal "3", @instance.stack[1].first
91
+ end
92
+
93
+ should "be able to call insert_before as well" do
94
+ @instance.insert_before("1", "0")
95
+ assert_equal "0", @instance.stack.first.first
96
+ end
97
+
98
+ should "be able to insert_after" do
99
+ @instance.insert_after("1", "0")
100
+ assert_equal "0", @instance.stack[1].first
101
+ end
102
+
103
+ should "be able to insert_after using numeric index" do
104
+ @instance.insert_after(1, "0")
105
+ assert_equal "0", @instance.stack[2].first
106
+ end
107
+
108
+ should "raise an exception if invalid index" do
109
+ assert_raises(RuntimeError) {
110
+ @instance.insert_after("15", "0")
111
+ }
112
+ end
113
+ end
114
+
115
+ context "swapping" do
116
+ setup do
117
+ @instance.use "1"
118
+ @instance.use "2"
119
+ end
120
+
121
+ should "be able to swap using the object" do
122
+ @instance.swap "1", "3"
123
+ assert_equal "3", @instance.stack.first.first
124
+ end
125
+
126
+ should "be able to swap using the index" do
127
+ @instance.swap 0, "3"
128
+ assert_equal "3", @instance.stack.first.first
129
+ end
130
+ end
131
+
132
+ context "deleting" do
133
+ setup do
134
+ @instance.use "1"
135
+ end
136
+
137
+ should "delete the proper object" do
138
+ @instance.delete("1")
139
+ assert @instance.stack.empty?
140
+ end
141
+
142
+ should "delete by index if given" do
143
+ @instance.delete(0)
144
+ assert @instance.stack.empty?
145
+ end
146
+ end
147
+
148
+ context "getting an index of an object" do
149
+ should "return the proper index if it exists" do
150
+ @instance.use 1
151
+ @instance.use 2
152
+ @instance.use 3
153
+ assert_equal 1, @instance.index(2)
154
+ end
155
+ end
156
+
157
+ context "converting to an app" do
158
+ teardown do
159
+ Vagrant::Action.actions.clear
160
+ end
161
+
162
+ should "preprend error halt to the chain" do
163
+ result = mock("result")
164
+ env = {:a => :b}
165
+ middleware = mock("middleware")
166
+ middleware.stubs(:is_a?).with(Class).returns(true)
167
+ middleware.expects(:new).with(anything, env).returns(result)
168
+ @instance.use middleware
169
+ result = @instance.to_app(env)
170
+ assert result.kind_of?(Vagrant::Action::Env::ErrorHalt)
171
+ end
172
+
173
+ should "make non-classes lambdas" do
174
+ env = Vagrant::Action::Environment.new(nil)
175
+ env.expects(:foo).once
176
+
177
+ func = lambda { |x| x.foo }
178
+ @instance.use func
179
+ @instance.to_app(env).call(env)
180
+ end
181
+
182
+ should "raise exception if given invalid middleware" do
183
+ @instance.use 7
184
+ assert_raises(RuntimeError) {
185
+ @instance.to_app(nil)
186
+ }
187
+ end
188
+ end
189
+
190
+ context "calling" do
191
+ def mock_middleware
192
+ middleware = Class.new do
193
+ def initialize(app, env)
194
+ @app = app
195
+ end
196
+
197
+ def call(env)
198
+ @app.call(env)
199
+ end
200
+ end
201
+ end
202
+
203
+ should "convert to an app then call with the env" do
204
+ mw = mock_middleware
205
+ mw.any_instance.expects(:call).with() do |env|
206
+ assert env.has_key?(:key)
207
+ true
208
+ end
209
+
210
+ env = Vagrant::Action::Environment.new(nil)
211
+ env[:key] = :value
212
+
213
+ @instance.use(mw)
214
+ @instance.call(env)
215
+ end
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ class ErrorHaltEnvActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Env::ErrorHalt
6
+ @app, @env = mock_action_data
7
+ @instance = @klass.new(@app, @env)
8
+ end
9
+
10
+ should "continue the chain if no error" do
11
+ assert !@env.error?
12
+ @app.expects(:call).with(@env).once
13
+ @instance.call(@env)
14
+ end
15
+
16
+ should "halt the chain if an error occured" do
17
+ @env.error!(:foo)
18
+ @app.expects(:call).never
19
+ @instance.call(@env)
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ class SetEnvActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Env::Set
6
+ @app, @env = mock_action_data
7
+ @env.clear
8
+ end
9
+
10
+ should "merge in the given options" do
11
+ @klass.new(@app, @env, :foo => :bar)
12
+ assert_equal :bar, @env[:foo]
13
+ end
14
+
15
+ should "not merge in anything if not given" do
16
+ @klass.new(@app, @env)
17
+ assert @env.empty?
18
+ end
19
+
20
+ should "just continue the chain" do
21
+ @app.expects(:call).with(@env)
22
+ @klass.new(@app, @env).call(@env)
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ require "test_helper"
2
+
3
+ class ActionEnvironmentTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::Environment
6
+ @instance = @klass.new(mock_environment)
7
+ end
8
+
9
+ should "default values to those on the env" do
10
+ @instance.env.stubs(:key).returns("value")
11
+ assert_equal "value", @instance["key"]
12
+ end
13
+
14
+ should "setup the logger" do
15
+ assert_equal @instance.env.logger, @instance.logger
16
+ end
17
+
18
+ should "not be erroneous initially" do
19
+ assert !@instance.error?
20
+ end
21
+
22
+ should "mark as erroneous" do
23
+ @instance.error!(:key)
24
+ assert_equal [:key, {}], @instance.error
25
+ end
26
+
27
+ should "properly report erroneous" do
28
+ @instance.error!(:key)
29
+ assert @instance.error?
30
+ end
31
+
32
+ should "report interrupted if interrupt error" do
33
+ assert !@instance.interrupted?
34
+ @instance.error!(:interrupt)
35
+ assert @instance.interrupted?
36
+ end
37
+
38
+ should "have indifferent access" do
39
+ @instance[:foo] = :bar
40
+ @instance["bar"] = :baz
41
+
42
+ assert_equal :bar, @instance["foo"]
43
+ assert_equal :baz, @instance[:bar]
44
+ end
45
+ end